demarches-normaliennes/db/migrate/20220302101337_add_foreign_keys_to_administrateurs_instructeurs.rb
Pierre de La Morinerie a4108c7787 db: backport delete_orphans in recent migrations
Recent migrations used ActiveRecord when removing invalid data. This may
break if the ActiveRecord model later changes.

To ensure these migrations will run correctly, even when the code will
have changed, let's use an SQL-based helper instead of ActiveRecord.
2022-03-08 14:48:17 +01:00

16 lines
560 B
Ruby

class AddForeignKeysToAdministrateursInstructeurs < ActiveRecord::Migration[6.1]
include Database::MigrationHelpers
def up
delete_orphans :administrateurs_instructeurs, :administrateurs
add_foreign_key :administrateurs_instructeurs, :administrateurs
delete_orphans :administrateurs_instructeurs, :instructeurs
add_foreign_key :administrateurs_instructeurs, :instructeurs
end
def down
remove_foreign_key :administrateurs_instructeurs, :administrateurs
remove_foreign_key :administrateurs_instructeurs, :instructeurs
end
end