summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSheogorath2020-03-21 16:07:14 +0100
committerSheogorath2020-03-21 16:14:43 +0100
commita9d98d4b529e6dd4a4f978dd8facd4bf5a20861e (patch)
tree47abe564a0c2623a9e37fbb6466532c1eec179c0 /lib
parent8ce7b285636c02b4215c838640bb748947c8317f (diff)
Add fix for missing deletion of notes on user-deletion request
Depending on how the system was setup, this bug lead to keep user's data around even after a successful deletion of user'S account. This patch will make sure the missing database constraints are implemented and missed out deletions are executed. This bug was introduced to insufficent testing after implementing the feature initially. It was well tested, using the app process itself, but the migrations where missed out. I'm currently not sure, if there was also a change in how sequelize handles cassaded deletion, since I'm unter the impression that before switching to sequelize 5, this feature has worked. But I haven't verified this. No matter what, the cleanup process is rather straight forward and will be invoked on migration, but can also be done manually using the new `bin/cleanup` script. This change will result in a release 1.6.1. Signed-off-by: Sheogorath <sheogorath@shivering-isles.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/migrations/20200321153000-fix-account-deletion.js61
1 files changed, 61 insertions, 0 deletions
diff --git a/lib/migrations/20200321153000-fix-account-deletion.js b/lib/migrations/20200321153000-fix-account-deletion.js
new file mode 100644
index 00000000..e794e993
--- /dev/null
+++ b/lib/migrations/20200321153000-fix-account-deletion.js
@@ -0,0 +1,61 @@
+'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')
+ })
+ }
+}