I am extending a class Entity to create a history table. The history table, must not inherit the unique constraints from the base class because we need to duplicate most of the data in there. Of course, I can just copy the properties without extending the base class but will result in maintaining two classes for each history table.
There is any way, to prevent TypeORM from generating constraints for a class entity?
I am thinking about something similar to avoiding foreign key constraint creation. Maybe a class decorator (something like @IgnoreConstraints
) would be nice to have for this type of situations.
//Base class with required constraint
@Entity()
@Unique(['email', 'shopId'])
export class Customer {}
// Will inherit the unique constraint
@Entity()
export class CustomerHistory extends Customer {}
More, I am using anchan828's very useful TypeORM History library which is adding a dropUniqueIndices
method to be used in a later migration but unfortunately will later result in auto-generated migrations including those constraints and schema:sync
will no longer work.
Thanks!