fix: Cleanup S3 Attachments (#1217)
* fix: Server error if attempting to load an unknown attachment * fix: Migration should cascade delete to document attachments * fix: Delete S3 attachments along with documents
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
// @flow
|
||||
import path from 'path';
|
||||
import { DataTypes, sequelize } from '../sequelize';
|
||||
import { deleteFromS3 } from '../utils/s3';
|
||||
|
||||
const Attachment = sequelize.define(
|
||||
'attachment',
|
||||
@@ -50,6 +51,10 @@ const Attachment = sequelize.define(
|
||||
}
|
||||
);
|
||||
|
||||
Attachment.beforeDestroy(async model => {
|
||||
await deleteFromS3(model.key);
|
||||
});
|
||||
|
||||
Attachment.associate = models => {
|
||||
Attachment.belongsTo(models.Team);
|
||||
Attachment.belongsTo(models.Document);
|
||||
|
||||
Reference in New Issue
Block a user