From 3b98117dfa9c078b2035b4ab3da37815f6274a2e Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Sat, 16 Jul 2022 15:55:09 +0200 Subject: [PATCH] Update foreign keys instead of redefining them --- ...0220714211614_set_on_delete_for_anonymous_blocks.rb | 7 ++----- .../20220714212414_set_on_delete_for_mute_rules.rb | 3 +-- db/schema.rb | 10 +++++----- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/db/migrate/20220714211614_set_on_delete_for_anonymous_blocks.rb b/db/migrate/20220714211614_set_on_delete_for_anonymous_blocks.rb index ef1668d8..52aaf299 100644 --- a/db/migrate/20220714211614_set_on_delete_for_anonymous_blocks.rb +++ b/db/migrate/20220714211614_set_on_delete_for_anonymous_blocks.rb @@ -3,11 +3,8 @@ class SetOnDeleteForAnonymousBlocks < ActiveRecord::Migration[6.1] def change change_table :anonymous_blocks do |t| - t.remove_references :user - t.references :user, null: false, foreign_key: true, on_delete: :cascade - - t.remove_references :question - t.references :question, null: true, foreign_key: true, on_delete: :null + t.foreign_key :users, on_delete: :cascade + t.foreign_key :questions, on_delete: :cascade end end end diff --git a/db/migrate/20220714212414_set_on_delete_for_mute_rules.rb b/db/migrate/20220714212414_set_on_delete_for_mute_rules.rb index 84bb698f..d4c01c6b 100644 --- a/db/migrate/20220714212414_set_on_delete_for_mute_rules.rb +++ b/db/migrate/20220714212414_set_on_delete_for_mute_rules.rb @@ -3,8 +3,7 @@ class SetOnDeleteForMuteRules < ActiveRecord::Migration[6.1] def change change_table :mute_rules do |t| - t.remove_references :user - t.references :user, null: false, foreign_key: true, on_delete: :cascade + t.foreign_key :users, on_delete: :cascade end end end diff --git a/db/schema.rb b/db/schema.rb index 852fa608..1873247f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -31,8 +31,8 @@ ActiveRecord::Schema.define(version: 2022_07_14_212414) do t.string "identifier" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false - t.bigint "user_id", null: false t.bigint "question_id" + t.bigint "user_id" t.index ["identifier"], name: "index_anonymous_blocks_on_identifier" t.index ["question_id"], name: "index_anonymous_blocks_on_question_id" t.index ["user_id"], name: "index_anonymous_blocks_on_user_id" @@ -125,7 +125,7 @@ ActiveRecord::Schema.define(version: 2022_07_14_212414) do t.string "muted_phrase" t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.bigint "user_id", null: false + t.bigint "user_id" t.index ["user_id"], name: "index_mute_rules_on_user_id" end @@ -324,8 +324,8 @@ ActiveRecord::Schema.define(version: 2022_07_14_212414) do t.index ["user_id"], name: "index_users_roles_on_user_id" end - add_foreign_key "anonymous_blocks", "questions" - add_foreign_key "anonymous_blocks", "users" - add_foreign_key "mute_rules", "users" + add_foreign_key "anonymous_blocks", "questions", on_delete: :cascade + add_foreign_key "anonymous_blocks", "users", on_delete: :cascade + add_foreign_key "mute_rules", "users", on_delete: :cascade add_foreign_key "profiles", "users" end