hedgedoc/lib/migrations/20200321153000-fix-account-deletion.js

62 lines
1.8 KiB
JavaScript
Raw Normal View History

'use strict'
const { spawnSync } = require('child_process')
const path = require('path')
module.exports = {
up: function (queryInterface, Sequelize) {
const cleanup = spawnSync('./bin/cleanup', { cwd: path.resolve(__dirname, '../../') })
if (cleanup.status !== 0) {
throw new Error('Unable to cleanup')
}
return queryInterface.addConstraint('Notes', ['ownerId'], {
type: 'foreign key',
name: 'Notes_owner_fkey',
references: {
table: 'Users',
field: 'id'
},
onDelete: 'cascade'
}).then(function () {
return queryInterface.addConstraint('Revisions', ['noteId'], {
type: 'foreign key',
name: 'Revisions_note_fkey',
references: {
table: 'Notes',
field: 'id'
},
onDelete: 'cascade'
})
}).then(function () {
return queryInterface.addConstraint('Authors', ['noteId'], {
type: 'foreign key',
name: 'Author_note_fkey',
references: {
table: 'Notes',
field: 'id'
},
onDelete: 'cascade'
})
}).then(function () {
return queryInterface.addConstraint('Authors', ['userId'], {
type: 'foreign key',
name: 'Author_user_fkey',
references: {
table: 'Users',
field: 'id'
},
onDelete: 'cascade'
})
})
},
down: function (queryInterface, Sequelize) {
return queryInterface.removeConstraint('Notes', 'Notes_owner_fkey')
.then(function () {
return queryInterface.removeConstraint('Revisions', 'Revisions_note_fkey')
}).then(function () {
return queryInterface.removeConstraint('Authors', 'Author_note_fkey')
}).then(function () {
return queryInterface.removeConstraint('Authors', 'Author_user_fkey')
})
}
}