From cbecf29070cb79a365b3ea5bf61f33a610925961 Mon Sep 17 00:00:00 2001 From: fumimowdan Date: Wed, 18 Oct 2023 14:27:40 +0100 Subject: [PATCH] Fix migrations --- ...0630083744_add_default_values_to_boolean_fields.rb | 11 +++++++---- db/migrate/20231009110217_add_application_indexes.rb | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/db/migrate/20230630083744_add_default_values_to_boolean_fields.rb b/db/migrate/20230630083744_add_default_values_to_boolean_fields.rb index d3db612c..4f987604 100644 --- a/db/migrate/20230630083744_add_default_values_to_boolean_fields.rb +++ b/db/migrate/20230630083744_add_default_values_to_boolean_fields.rb @@ -1,11 +1,14 @@ class AddDefaultValuesToBooleanFields < ActiveRecord::Migration[7.0] def up - ApplicationProgress.where.not(visa_investigation_required: true) - .update(visa_investigation_required: false) + execute('UPDATE application_progresses + SET visa_investigation_required = false + WHERE visa_investigation_required != true') + change_column :application_progresses, :visa_investigation_required, :boolean, default: false, null: false + execute('UPDATE application_progresses + SET school_investigation_required = false + WHERE school_investigation_required != true') - ApplicationProgress.where.not(school_investigation_required: true) - .update(school_investigation_required: false) change_column :application_progresses, :school_investigation_required, :boolean, default: false, null: false end end diff --git a/db/migrate/20231009110217_add_application_indexes.rb b/db/migrate/20231009110217_add_application_indexes.rb index cbaa98bd..f3a16e1d 100644 --- a/db/migrate/20231009110217_add_application_indexes.rb +++ b/db/migrate/20231009110217_add_application_indexes.rb @@ -1,6 +1,6 @@ class AddApplicationIndexes < ActiveRecord::Migration[7.0] def change - drop_table :urns # rubocop:disable Rails/ReversibleMigration + execute("DROP TABLE IF EXISTS urns") # rubocop:disable Rails/ReversibleMigration add_index :applications, :urn, unique: true add_index :applications, :application_route end