From f84c7ac5e4fb56084328e39e31b84894234d3da0 Mon Sep 17 00:00:00 2001 From: Martin Date: Thu, 7 Apr 2022 10:18:12 +0200 Subject: [PATCH] fix(migration): apply what strong migration recommends --- ..._add_procedure_presentation_and_state_to_exports.rb | 5 ++--- db/migrate/20220407081538_backfill_export_status.rb | 10 ++++++++++ db/schema.rb | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 db/migrate/20220407081538_backfill_export_status.rb diff --git a/db/migrate/20220323143325_add_procedure_presentation_and_state_to_exports.rb b/db/migrate/20220323143325_add_procedure_presentation_and_state_to_exports.rb index 61f166723..3b2ac9406 100644 --- a/db/migrate/20220323143325_add_procedure_presentation_and_state_to_exports.rb +++ b/db/migrate/20220323143325_add_procedure_presentation_and_state_to_exports.rb @@ -3,9 +3,8 @@ class AddProcedurePresentationAndStateToExports < ActiveRecord::Migration[6.1] def change add_reference :exports, :procedure_presentation, null: true, index: { algorithm: :concurrently } - StrongMigrations.disable_check(:add_column) - add_column :exports, :statut, :string, default: 'tous' - StrongMigrations.enable_check(:add_column) + add_column :exports, :statut, :string + change_column_default :exports, :statut, "tous" remove_index :exports, [:format, :time_span_type, :key] add_index :exports, [:format, :time_span_type, :statut, :key], unique: true, algorithm: :concurrently end diff --git a/db/migrate/20220407081538_backfill_export_status.rb b/db/migrate/20220407081538_backfill_export_status.rb new file mode 100644 index 000000000..721789437 --- /dev/null +++ b/db/migrate/20220407081538_backfill_export_status.rb @@ -0,0 +1,10 @@ +class BackfillExportStatus < ActiveRecord::Migration[6.1] + disable_ddl_transaction! + + def change + Export.in_batches do |relation| + relation.update_all statut: "tous" + sleep(0.01) + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 4cff9290a..d59c95dd9 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2022_04_05_163206) do +ActiveRecord::Schema.define(version: 2022_04_07_081538) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql"