Skip to content

Commit f6094aa

Browse files
ClearlyClairekadoshita
authored andcommitted
Fix missing on_delete: :cascade for canonical_email_blocks foreign key (mastodon#16448)
1 parent d0b590e commit f6094aa

3 files changed

Lines changed: 16 additions & 3 deletions

File tree

db/migrate/20210416200740_create_canonical_email_blocks.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ class CreateCanonicalEmailBlocks < ActiveRecord::Migration[6.1]
22
def change
33
create_table :canonical_email_blocks do |t|
44
t.string :canonical_email_hash, null: false, default: '', index: { unique: true }
5-
t.belongs_to :reference_account, null: false, foreign_key: { on_cascade: :delete, to_table: 'accounts' }
5+
t.belongs_to :reference_account, null: false, foreign_key: { to_table: 'accounts' }
66

77
t.timestamps
88
end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class FixCanonicalEmailBlocksForeignKey < ActiveRecord::Migration[6.1]
2+
def up
3+
safety_assured do
4+
execute 'ALTER TABLE canonical_email_blocks DROP CONSTRAINT fk_rails_1ecb262096, ADD CONSTRAINT fk_rails_1ecb262096 FOREIGN KEY (reference_account_id) REFERENCES accounts(id) ON DELETE CASCADE;'
5+
end
6+
end
7+
8+
def down
9+
safety_assured do
10+
execute 'ALTER TABLE canonical_email_blocks DROP CONSTRAINT fk_rails_1ecb262096, ADD CONSTRAINT fk_rails_1ecb262096 FOREIGN KEY (reference_account_id) REFERENCES accounts(id);'
11+
end
12+
end
13+
end

db/schema.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema.define(version: 2021_05_26_193025) do
13+
ActiveRecord::Schema.define(version: 2021_06_30_000137) do
1414

1515
# These are extensions that must be enabled in order to support this database
1616
enable_extension "plpgsql"
@@ -985,7 +985,7 @@
985985
add_foreign_key "blocks", "accounts", name: "fk_4269e03e65", on_delete: :cascade
986986
add_foreign_key "bookmarks", "accounts", on_delete: :cascade
987987
add_foreign_key "bookmarks", "statuses", on_delete: :cascade
988-
add_foreign_key "canonical_email_blocks", "accounts", column: "reference_account_id"
988+
add_foreign_key "canonical_email_blocks", "accounts", column: "reference_account_id", on_delete: :cascade
989989
add_foreign_key "conversation_mutes", "accounts", name: "fk_225b4212bb", on_delete: :cascade
990990
add_foreign_key "conversation_mutes", "conversations", on_delete: :cascade
991991
add_foreign_key "custom_filters", "accounts", on_delete: :cascade

0 commit comments

Comments
 (0)