fix(schema): add missing index exports#instructeur_id

This commit is contained in:
Colin Darie 2023-11-08 13:06:25 +01:00
parent f972d36f2f
commit bb4a2b84b9
3 changed files with 23 additions and 1 deletions

View file

@ -1,11 +1,17 @@
class AddInstructeurForeignKeyToExports < ActiveRecord::Migration[7.0]
disable_ddl_transaction!
def change
def up
# 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
def down
if foreign_key_exists?(:exports, :instructeurs)
remove_foreign_key :exports, :instructeurs
end
end
end

View file

@ -0,0 +1,15 @@
class AddMissingExportsInstructeurIndex < ActiveRecord::Migration[7.0]
disable_ddl_transaction!
def up
if !index_exists?(:exports, :instructeur_id) # index may have already been added on other environments by a previous migration
add_index :exports, :instructeur_id, algorithm: :concurrently
end
end
def down
if index_exists?(:exports, :instructeur_id)
remove_index :exports, :instructeur_id
end
end
end

View file

@ -556,6 +556,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_11_14_113317) do
t.string "statut", default: "tous"
t.string "time_span_type", default: "everything", null: false
t.datetime "updated_at", precision: nil, null: false
t.index ["instructeur_id"], name: "index_exports_on_instructeur_id"
t.index ["key"], name: "index_exports_on_key"
t.index ["procedure_presentation_id"], name: "index_exports_on_procedure_presentation_id"
end