From 33c3bb261a72aebe4b9088a3c4e54469bd77e514 Mon Sep 17 00:00:00 2001 From: Mark VanLandingham Date: Thu, 17 Jun 2021 15:56:48 -0500 Subject: [PATCH] FIX: Drop and recreate column properly for directory_columns (#13429) --- ..._automatic_on_directory_columns_to_bool.rb | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 db/migrate/20210617202227_change_automatic_on_directory_columns_to_bool.rb diff --git a/db/migrate/20210617202227_change_automatic_on_directory_columns_to_bool.rb b/db/migrate/20210617202227_change_automatic_on_directory_columns_to_bool.rb new file mode 100644 index 00000000000..534d2217b3c --- /dev/null +++ b/db/migrate/20210617202227_change_automatic_on_directory_columns_to_bool.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +class ChangeAutomaticOnDirectoryColumnsToBool < ActiveRecord::Migration[6.1] + def up + begin + Migration::SafeMigrate.disable! + + # Because of a weird state we are in where some sites have a boolean type column for `automatic` and some + # have an `integer`type, we remove the column. Then we re-create it and using `user_field_id` to determine + # if the value should be true or false. + remove_column :directory_columns, :automatic + add_column :directory_columns, :automatic, :boolean, default: true, null: false + + execute <<~SQL + UPDATE directory_columns SET automatic = (user_field_id IS NULL); + SQL + ensure + Migration::SafeMigrate.enable! + end + end + + def down + raise ActiveRecord::IrreversibleMigration + end +end