'Will TypeORM @AfterRemove or @BeforeRemove entity listeners still run when the db is dropped?
Some entities in my database have a property which is their associated key on AWS S3, for example:
// my.entity.ts
@Column()
s3Key: string;
I would like one of TypeOrm's entity listeners, @AfterRemove
or @BeforeRemove
to execute their functions when the table is dropped using the TypeOrm cli? This kind of action would be really helpful when developing locally so I don't have to delete S3 objects one by one when dropping the db
// my.entity.ts
@AfterRemove()
async deleteFromS3AfterRemove() {
await deleteFromS3("BUCKET_NAME", this.s3Key);
}
So, will these entity listeners still be executed when the table is dropped or does anyone know if typeorm schema:drop
emits the remove subscription events?
I had a look around at the source and docs but couldn't find anything https://github.com/typeorm/typeorm/blob/master/src/commands/SchemaDropCommand.ts
Solution 1:[1]
This does not work - entity listeners are not executed when dropping a database.
I span up a test database with some fake entities to test this out and I added the method
@AfterRemove()
async logIfWorking() {
console.log('????????');
}
No console logs were seen when executing the schema drop command from the TypeORM cli
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | IB3N |