chore(schema): fixup failed migrations, ensure exports->instructeurs foreign key exists

This commit is contained in:
Colin Darie 2023-10-10 11:00:05 +02:00
parent dd3805b7cd
commit b11495a7a6
No known key found for this signature in database
GPG key ID: 8C76CADD40253590
5 changed files with 18 additions and 8 deletions

View file

@ -2,6 +2,7 @@ class AddGroupeGestionnaireToAdministrateurs < ActiveRecord::Migration[7.0]
disable_ddl_transaction!
def change
add_reference :administrateurs, :groupe_gestionnaire, index: { algorithm: :concurrently }, null: true
# Foreign key is added in a later migration
add_reference :administrateurs, :groupe_gestionnaire, index: { algorithm: :concurrently }, null: true, foreign_key: false
end
end

View file

@ -1,6 +1,4 @@
class AddContextToExports < ActiveRecord::Migration[7.0]
disable_ddl_transaction!
class AddDossiersCountToExports < ActiveRecord::Migration[7.0]
def change
add_column :exports, :dossiers_count, :integer, null: true, default: nil
end

View file

@ -1,8 +1,8 @@
class AddReferenceToExportsInstructeur < ActiveRecord::Migration[7.0]
disable_ddl_transaction!
def change
safety_assured do
add_reference :exports, :instructeur, foreign_key: true, null: true, default: nil, index: { algorithm: :concurrently }
end
# Foreign key is added in a later migration
add_reference :exports, :instructeur, null: true, default: nil, index: { algorithm: :concurrently }, foreign_key: false
end
end

View file

@ -0,0 +1,11 @@
class AddInstructeurForeignKeyToExports < ActiveRecord::Migration[7.0]
disable_ddl_transaction!
def change
# Foreign keys were already added on developer machines, but timeouted in production.
if !foreign_key_exists?(:exports, :instructeurs)
add_foreign_key :exports, :instructeurs, validate: false
validate_foreign_key :exports, :instructeurs
end
end
end

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2023_10_09_143331) do
ActiveRecord::Schema[7.0].define(version: 2023_10_10_083144) do
# These are extensions that must be enabled in order to support this database
enable_extension "pgcrypto"
enable_extension "plpgsql"