-
Notifications
You must be signed in to change notification settings - Fork 9
Foreign keys constraint clearing history records #779
Comments
Hi @predragffwd, For now, you need to create a migration file and call the Of course, you can also delete it manually. Please refer to this line.
|
Hi @anchan828, This is fine, I do have migration that is doing exactly what you explained, but problem is that for development I have sync turned on, and when ever I do some changes it rebuilds the constraints and all indexes... Also I had issues with unique values because history table is copying exactly the same entity table schema. Even if I drop all unique indexes with migration, sync would return them on change, and because I have duplicate records with the same values, it breaks on sync with duplicate entry error. So migration works fine in case sync is turned off, for production it's perfect, but for development where I don't write entity migration on the start it's quite problematic as you see. That is why it would be nice to define a configuration that will override the entity field configuration. |
Hi @predragffwd, @Entity()
class TestEntity extends BaseEntity {
@PrimaryGeneratedColumn()
public id!: number;
@Column()
public test!: string;
}
@Entity()
class TestHistoryEntity extends TestEntity implements HistoryEntityInterface {
@HistoryOriginalIdColumn()
public originalID!: number;
@HistoryActionColumn()
public action!: HistoryActionType;
} ↓ @Entity()
class TestEntity extends BaseEntity {
@PrimaryGeneratedColumn()
public id!: number;
@Column()
public test!: string;
}
@Entity()
class TestHistoryEntity extends BaseEntity implements HistoryEntityInterface {
@PrimaryGeneratedColumn()
public id!: number;
@Column()
public test!: string;
@HistoryOriginalIdColumn()
public originalID!: number;
@HistoryActionColumn()
public action!: HistoryActionType;
} Currently, the History class always had to inherit from the original entity, but that restriction is meaningless. So we will try to remove this restriction. |
I published Creating a History class without class inheritance might work. @Entity()
class TestEntity {
@ManyToOne(() => UserData, { onDelete: 'CASCADE', nullable: false, })
@JoinColumn()
data: UserData;
}
@Entity()
class TestHistoryEntity implements HistoryEntityInterface {
@ManyToOne(() => UserData, { createForeignKeyConstraints: false, nullable: false, })
@JoinColumn()
data: UserData;
@HistoryOriginalIdColumn()
public originalID!: number;
@HistoryActionColumn()
public action!: HistoryActionType;
} |
If you have any questions, please create new issue. |
Hi, I have issue with cascade delete on ManyToOne (same as on OneToOne) relation. In my case I have entity with
@ManyToOne(() => UserData, { onDelete: 'CASCADE', nullable: false, }) @JoinColumn() data: UserData;
When making a history entity and extending my entity, same field is created in history, with cascade delete. Of course, when I delete UserData related record, mysql also removes all my records with related dataId, so I end up without my history records.
Can we have an option where I can disable all foreign keys in the history table?
The text was updated successfully, but these errors were encountered: