From 83a98cb81a2f40017c589b66b9cd48ab0fd4f171 Mon Sep 17 00:00:00 2001 From: Claire Date: Mon, 7 Oct 2024 09:46:03 +0200 Subject: [PATCH] Add missing `on_delete: :cascade` on `notification_permissions` (#32281) --- ...ix_notification_permission_foreign_keys.rb | 39 +++++++++++++++++++ db/schema.rb | 6 +-- 2 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20241007071624_fix_notification_permission_foreign_keys.rb diff --git a/db/migrate/20241007071624_fix_notification_permission_foreign_keys.rb b/db/migrate/20241007071624_fix_notification_permission_foreign_keys.rb new file mode 100644 index 0000000000..11b82de8a6 --- /dev/null +++ b/db/migrate/20241007071624_fix_notification_permission_foreign_keys.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +class FixNotificationPermissionForeignKeys < ActiveRecord::Migration[7.1] + def up + safety_assured do + execute <<~SQL.squish + ALTER TABLE notification_permissions + DROP CONSTRAINT fk_rails_7c0bed08df, + ADD CONSTRAINT fk_rails_7c0bed08df + FOREIGN KEY (account_id) + REFERENCES accounts(id) + ON DELETE CASCADE, + + DROP CONSTRAINT fk_rails_e3e0aaad70, + ADD CONSTRAINT fk_rails_e3e0aaad70 + FOREIGN KEY (from_account_id) + REFERENCES accounts(id) + ON DELETE CASCADE + SQL + end + end + + def down + safety_assured do + execute <<~SQL.squish + ALTER TABLE notification_permissions + DROP CONSTRAINT fk_rails_7c0bed08df, + ADD CONSTRAINT fk_rails_7c0bed08df + FOREIGN KEY (account_id) + REFERENCES accounts(id), + + DROP CONSTRAINT fk_rails_e3e0aaad70, + ADD CONSTRAINT fk_rails_e3e0aaad70 + FOREIGN KEY (from_account_id) + REFERENCES accounts(id) + SQL + end + end +end diff --git a/db/schema.rb b/db/schema.rb index f9f2d97395..68067841e0 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[7.1].define(version: 2024_09_16_190140) do +ActiveRecord::Schema[7.1].define(version: 2024_10_07_071624) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -1291,8 +1291,8 @@ ActiveRecord::Schema[7.1].define(version: 2024_09_16_190140) do add_foreign_key "mentions", "statuses", on_delete: :cascade add_foreign_key "mutes", "accounts", column: "target_account_id", name: "fk_eecff219ea", on_delete: :cascade add_foreign_key "mutes", "accounts", name: "fk_b8d8daf315", on_delete: :cascade - add_foreign_key "notification_permissions", "accounts" - add_foreign_key "notification_permissions", "accounts", column: "from_account_id" + add_foreign_key "notification_permissions", "accounts", column: "from_account_id", on_delete: :cascade + add_foreign_key "notification_permissions", "accounts", on_delete: :cascade add_foreign_key "notification_policies", "accounts", on_delete: :cascade add_foreign_key "notification_requests", "accounts", column: "from_account_id", on_delete: :cascade add_foreign_key "notification_requests", "accounts", on_delete: :cascade