chore(schema): safer migration for add_etablissment_infos_to_services

This commit is contained in:
Colin Darie 2022-09-05 14:29:45 +02:00
parent 3cb25e8393
commit 81149cc809
2 changed files with 19 additions and 2 deletions

View file

@ -1,7 +1,14 @@
class AddEtablissementInfosToServices < ActiveRecord::Migration[6.1] class AddEtablissementInfosToServices < ActiveRecord::Migration[6.1]
def change def up
add_column :services, :etablissement_infos, :jsonb, default: {} add_column :services, :etablissement_infos, :jsonb
add_column :services, :etablissement_lat, :decimal, precision: 10, scale: 6 add_column :services, :etablissement_lat, :decimal, precision: 10, scale: 6
add_column :services, :etablissement_lng, :decimal, precision: 10, scale: 6 add_column :services, :etablissement_lng, :decimal, precision: 10, scale: 6
change_column_default :services, :etablissement_infos, {}
end
def down
remove_column :services, :etablissement_infos
remove_column :services, :etablissement_lat
remove_column :services, :etablissement_lng
end end
end end

View file

@ -0,0 +1,10 @@
class BackfillAddEtablissementInfosToServices < ActiveRecord::Migration[6.1]
disable_ddl_transaction!
def up
Service.unscoped.in_batches do |relation| # rubocop:disable DS/Unscoped
relation.update_all etablissement_infos: {}
sleep(0.01)
end
end
end