Provides a Revision History Subscriber for TypeORM Entities
Tested: MySQL 8, MariaDB and Postgres
$ npm i --save typeorm @ifjkt/typeorm-revisions
@Entity()
class MyModel extends BaseEntity {
@PrimaryGeneratedColumn()
public id!: number;
@Column()
public name!: string;
@Column()
public email!: string;
}
@Entity()
class MyModelHistory extends MyModel implements HistoryEntityInterface {
@Column({
name: 'record_id',
type: 'int',
})
recordId: number;
@Column({
name: 'revision_timestamp',
})
revisionTime: Date;
@Column({
name: 'revision_type',
})
revisionType: RevisionActionType;
}
@Entity()
@AuditTable({
recordIdProperty: 'recordId',
revisionTypeProperty: 'revisionType',
revisionTimestampProperty: 'revisionTime',
})
class MyModelHistory extends MyModel implements HistoryEntityInterface {
@Column({
name: 'record_id',
type: 'int',
})
recordId: number;
@Column({
name: 'revision_timestamp',
})
revisionTime: Date;
@Column({
name: 'revision_type',
})
revisionType: RevisionActionType;
}
@EventSubscriber()
class MyModelHistorySubscriber extends HistorySubscriber<MyModel, MyModelHistory> {
public entity = MyModel;
public historyEntity = MyModelHistory;
}
Forked from https://github.com/ephillipe/typeorm-revisions