oguimbal / pg-mem

An in memory postgres DB instance for your unit tests
MIT License
1.95k stars 94 forks source link

Table inheritance failing with TypeORM due to duplicated column registration #329

Open leogcba opened 1 year ago

leogcba commented 1 year ago

Describe the bug

When i try to register the second child entity, i get an error saying that there are duplicated columns. If I only register one child entity, i don't get this error.

QueryFailedError: Column "entityId" already exists

To Reproduce

@Entity('agreements')
@TableInheritance({ column: { name: 'entityType', type: 'text' } })
export default abstract class AbstractAgreement extends BaseEntity {
    @PrimaryColumn({ type: 'uuid' })
    public id: string;

    @Column()
    public agreementType: string;
}

@ChildEntity('Account')
export default class AccountAgreement extends AbstractAgreement {
    @Column({ name: 'entityId', type: 'uuid' })
    public accountId: string;
}

@ChildEntity('Customer')
export default class CustomerAgreement extends AbstractAgreement {
    @Column({ name: 'entityId', type: 'uuid' })
    public customerId: string;
}

this.db.adapters.createTypeormDataSource({
    entities: [
        'src/**/abstractAgreement.entity.ts',
        'src/**/accountAgreement.entity.ts',
        'src/**/customerAgreement.entity.ts',
    ],
    subscribers: ['src/**/*.subscriber.ts'],
    synchronize: true,
    type: 'postgres',
}),
Failed SQL statement: CREATE TABLE "agreements" ("id" uuid NOT NULL, "agreementType" character varying NOT NULL, "entityId" uuid, "entityId" uuid, "entityType" text NOT NULL, CONSTRAINT "PK_01532f6c999d44c776e3d1fa4c8" PRIMARY KEY ("id"));

pg-mem version

2.6.12