db: add foreign key contraint to AdministrateursProcedure

In production there are around 20 000 AdministrateursProcedure
records that reference a deleted Procedure.
This commit is contained in:
Pierre de La Morinerie 2022-03-08 08:21:22 +00:00
parent a4108c7787
commit 27edc6676d
2 changed files with 14 additions and 1 deletions

View file

@ -0,0 +1,12 @@
class AddProcedureForeignKeyToAdministrateursProcedure < ActiveRecord::Migration[6.1]
include Database::MigrationHelpers
def up
delete_orphans :administrateurs_procedures, :procedures
add_foreign_key :administrateurs_procedures, :procedures
end
def down
remove_foreign_key :administrateurs_procedures, :procedures
end
end

View file

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2022_03_02_101337) do ActiveRecord::Schema.define(version: 2022_03_08_110720) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -855,6 +855,7 @@ ActiveRecord::Schema.define(version: 2022_03_02_101337) do
add_foreign_key "administrateurs_instructeurs", "administrateurs" add_foreign_key "administrateurs_instructeurs", "administrateurs"
add_foreign_key "administrateurs_instructeurs", "instructeurs" add_foreign_key "administrateurs_instructeurs", "instructeurs"
add_foreign_key "administrateurs_procedures", "administrateurs" add_foreign_key "administrateurs_procedures", "administrateurs"
add_foreign_key "administrateurs_procedures", "procedures"
add_foreign_key "archives_groupe_instructeurs", "archives" add_foreign_key "archives_groupe_instructeurs", "archives"
add_foreign_key "archives_groupe_instructeurs", "groupe_instructeurs" add_foreign_key "archives_groupe_instructeurs", "groupe_instructeurs"
add_foreign_key "assign_tos", "groupe_instructeurs" add_foreign_key "assign_tos", "groupe_instructeurs"