-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Closed
Labels
Description
Issue Description
TypeORM drops and recreates every enum field with a custom enum name with sync enabled or when generating migration.
Expected Behavior
To not drop and recreate fields.
Actual Behavior
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "external_user" DROP CONSTRAINT "PK_5e027bcbb18ddb47082d7db9434"`); // provider - id
await queryRunner.query(`ALTER TABLE "external_user" ADD CONSTRAINT "PK_ca5f437dd8b664627e45ec63369" PRIMARY KEY ("id")`);
await queryRunner.query(`DROP INDEX "IDX_207e7af2ba870f0fea673e6c02"`); // provider
await queryRunner.query(`ALTER TABLE "external_user" DROP COLUMN "provider"`);
await queryRunner.query(`ALTER TABLE "external_user" ADD "provider" "external_user_provider" NOT NULL`);
await queryRunner.query(`ALTER TABLE "external_user" DROP CONSTRAINT "PK_ca5f437dd8b664627e45ec63369"`);
await queryRunner.query(`ALTER TABLE "external_user" ADD CONSTRAINT "PK_5e027bcbb18ddb47082d7db9434" PRIMARY KEY ("id", "provider")`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "external_user" DROP CONSTRAINT "PK_5e027bcbb18ddb47082d7db9434"`);
await queryRunner.query(`ALTER TABLE "external_user" ADD CONSTRAINT "PK_ca5f437dd8b664627e45ec63369" PRIMARY KEY ("id")`);
await queryRunner.query(`ALTER TABLE "external_user" DROP COLUMN "provider"`);
await queryRunner.query(`ALTER TABLE "external_user" ADD "provider" external_user_provider NOT NULL`);
await queryRunner.query(`CREATE INDEX "IDX_207e7af2ba870f0fea673e6c02" ON "external_user" ("provider") `);
await queryRunner.query(`ALTER TABLE "external_user" DROP CONSTRAINT "PK_ca5f437dd8b664627e45ec63369"`);
await queryRunner.query(`ALTER TABLE "external_user" ADD CONSTRAINT "PK_5e027bcbb18ddb47082d7db9434" PRIMARY KEY ("provider", "id")`);
}Steps to Reproduce
just define a new enum field with custom name:
@PrimaryColumn({ name: "provider", type: "enum", enumName: "external_user_provider", enum: ExternalUserProvider })
@Index()
public provider!: ExternalUserProvider;My Environment
| Dependency | Version |
|---|---|
| Operating System | Win10 / Postgres on Docker |
| Node.js version | v16.0.0 |
| Typescript version | v4.2.3 |
| TypeORM version | v0.2.32 |
Additional Context
Please note that this happened due to the fact that when reading from the database, TypeORM gets the name of the enum without "s around it, but when creating it, it adds the additional " around the name of the enum. So apparently this is the reason behind this behavior.
Relevant Database Driver(s)
-
aurora-data-api -
aurora-data-api-pg -
better-sqlite3 -
cockroachdb -
cordova -
expo -
mongodb -
mysql -
nativescript -
oracle -
postgres -
react-native -
sap -
sqlite -
sqlite-abstract -
sqljs -
sqlserver
Are you willing to resolve this issue by submitting a Pull Request?
- Yes, I have the time, and I know how to start.
- Yes, I have the time, but I don't know how to start. I would need guidance.
- No, I don't have the time, although I believe I could do it if I had the time...
- No, I don't have the time and I wouldn't even know how to start.
Thank you guys
Reactions are currently unavailable