-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enum with enumName in two tables fails on second synchronize #7501
Comments
Exactly same issue here. Version 0.2.31 implemented support for this kind of synchronisation of enums but seemingly is not working. |
Awesome news, thanks, really appreciate it! |
fix now available in version |
The bug still happen with embedded entity The entities: import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm';
enum TestEnum {
test = 'test',
}
class TestAEmbedded {
@Column({
type: 'enum',
enum: TestEnum,
enumName: 'test_enum',
})
testEnumA: TestEnum;
}
@Entity()
export class TestA {
@PrimaryGeneratedColumn('uuid')
id: string;
@Column(() => TestAEmbedded, { prefix: true })
embedded: TestAEmbedded;
}
@Entity()
export class TestB {
@PrimaryGeneratedColumn('uuid')
id: string;
@Column({
type: 'enum',
enum: TestEnum,
enumName: 'test_enum',
})
testEnumB: TestEnum;
} The generated migration: import { MigrationInterface, QueryRunner } from "typeorm";
export class MyMigrationName1674574030711 implements MigrationInterface {
name = 'MyMigrationName1674574030711'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
CREATE TYPE "public"."test_enum" AS ENUM('test')
`);
await queryRunner.query(`
CREATE TABLE "test_a" (
"id" uuid NOT NULL DEFAULT uuid_generate_v4(),
"embedded_test_enum_a" "public"."test_enum" NOT NULL,
CONSTRAINT "PK_16eb42d7d3d65ae555af54a3cd9" PRIMARY KEY ("id")
)
`);
await queryRunner.query(`
CREATE TYPE "public"."test_enum" AS ENUM('test')
`);
await queryRunner.query(`
CREATE TABLE "test_b" (
"id" uuid NOT NULL DEFAULT uuid_generate_v4(),
"test_enum_b" "public"."test_enum" NOT NULL,
CONSTRAINT "PK_25d8d88d8a1ae98ad35e8ebada8" PRIMARY KEY ("id")
)
`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
DROP TABLE "test_b"
`);
await queryRunner.query(`
DROP TYPE "public"."test_enum"
`);
await queryRunner.query(`
DROP TABLE "test_a"
`);
await queryRunner.query(`
DROP TYPE "public"."test_enum"
`);
}
} Tested with typeorm version |
Our current workaround is to have a script that parse the migration with regex and wrap CREATE/ALTER/DROP statement on enum with Here is the gist of the full script @AlexMesser, would you be willing to re-open this issue ? |
I see this being raised again and again (and now I encountered it too)… Can it be addressed? |
Issue Description
When using the same
enum
with the sameenumName
in two different tables, the second time syncing the code to the database breaks.Expected Behavior
Using an enum twice in different tables should not break when syncing the database for a second time.
Actual Behavior
Using an enum twice in different tables breaks when creating a connection with
synchronize: true
more than once (or calling synchronize).I get the following error:
Steps to Reproduce
Basic code example:
Code example with full context of what I want to do:
I did two
connection.synchronize()
at the end, but it could be running twice a script doing only once.My Environment
Additional Context
The reason for bumping into this problem and the code example is because I needed a composite foreign key between two tables, an one of the columns is an enum.
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?
I don't know how much time it would take ¯\(ツ)/¯
The text was updated successfully, but these errors were encountered: