diff options
author | Claire <claire.github-309c@sitedethib.com> | 2021-08-08 15:29:57 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-08 15:29:57 +0200 |
commit | 763ab0c7eb5430235ca8a354d11e00de1d8ba6dd (patch) | |
tree | 424b1ab20882facd51ef8e1140381b6cf56e850f /db | |
parent | 818e0b314fc81005dc9a73b53331f75ad52daa0d (diff) |
Fix owned account notes not being deleted when an account is deleted (#16579)
* Add account_notes relationship * Add tests * Fix owned account notes not being deleted when an account is deleted * Add post-migration to clean up orphaned account notes
Diffstat (limited to 'db')
-rw-r--r-- | db/post_migrate/20210808071221_clear_orphaned_account_notes.rb | 21 | ||||
-rw-r--r-- | db/schema.rb | 2 |
2 files changed, 22 insertions, 1 deletions
diff --git a/db/post_migrate/20210808071221_clear_orphaned_account_notes.rb b/db/post_migrate/20210808071221_clear_orphaned_account_notes.rb new file mode 100644 index 000000000..71171658a --- /dev/null +++ b/db/post_migrate/20210808071221_clear_orphaned_account_notes.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +class ClearOrphanedAccountNotes < ActiveRecord::Migration[5.2] + class Account < ApplicationRecord + # Dummy class, to make migration possible across version changes + end + + class AccountNote < ApplicationRecord + # Dummy class, to make migration possible across version changes + belongs_to :account + belongs_to :target_account, class_name: 'Account' + end + + def up + AccountNote.where('NOT EXISTS (SELECT * FROM users u WHERE u.account_id = account_notes.account_id)').in_batches.delete_all + end + + def down + # nothing to do + end +end diff --git a/db/schema.rb b/db/schema.rb index b2929f693..a0a98eb03 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_06_30_000137) do +ActiveRecord::Schema.define(version: 2021_08_08_071221) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" |