For MySQL, foreign keys are dependent on index.
This commit is contained in:
parent
43b74afd86
commit
8a7cd25d08
2 changed files with 6 additions and 3 deletions
|
@ -10,9 +10,6 @@ class CreateUserInteractedProjectsTable < ActiveRecord::Migration
|
|||
t.references :user, null: false
|
||||
t.references :project, null: false
|
||||
end
|
||||
|
||||
add_concurrent_foreign_key :user_interacted_projects, :users, column: :user_id, on_delete: :cascade
|
||||
add_concurrent_foreign_key :user_interacted_projects, :projects, column: :project_id, on_delete: :cascade
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -14,11 +14,17 @@ class BuildUserInteractedProjectsTable < ActiveRecord::Migration
|
|||
end.up
|
||||
|
||||
add_concurrent_index :user_interacted_projects, [:project_id, :user_id], unique: true
|
||||
|
||||
add_concurrent_foreign_key :user_interacted_projects, :users, column: :user_id, on_delete: :cascade
|
||||
add_concurrent_foreign_key :user_interacted_projects, :projects, column: :project_id, on_delete: :cascade
|
||||
end
|
||||
|
||||
def down
|
||||
execute "TRUNCATE user_interacted_projects"
|
||||
|
||||
remove_foreign_key :user_interacted_projects, :users
|
||||
remove_foreign_key :user_interacted_projects, :projects
|
||||
|
||||
remove_concurrent_index_by_name :user_interacted_projects, 'index_user_interacted_projects_on_project_id_and_user_id'
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue