fix(schema): dossier_corrections foreign keys in separate migration

This commit is contained in:
Colin Darie 2023-06-05 12:42:06 +02:00
parent 66dc8f251f
commit a03f8b2ea4
2 changed files with 15 additions and 2 deletions

View file

@ -3,8 +3,10 @@ class CreateDossierCorrections < ActiveRecord::Migration[6.1]
def change
create_table :dossier_corrections do |t|
t.references :dossier, null: false, foreign_key: true
t.references :commentaire, foreign_key: true
# foreign keys are added in a later migration
# see https://github.com/fatkodima/online_migrations#adding-multiple-foreign-keys
t.references :dossier, null: false, foreign_key: false
t.references :commentaire, foreign_key: false
t.datetime :resolved_at, precision: 6
t.timestamps

View file

@ -0,0 +1,11 @@
class AddForeignKeysToDossierCorrections < ActiveRecord::Migration[7.0]
disable_ddl_transaction!
def change
add_foreign_key :dossier_corrections, :dossiers, column: :dossier_id, validate: false
validate_foreign_key :dossier_corrections, :dossiers
add_foreign_key :dossier_corrections, :commentaires, column: :commentaire_id, validate: false
validate_foreign_key :dossier_corrections, :commentaires
end
end