DEV: Replace old field_type text column with field_type_enum integer column (#27448)

Follow up to: #27444. In that PR we added a new integer column for UserField#field_type and populated the data based on the old text field.

In this PR we drop the old text column and swap in the new integer (enum) column.
This commit is contained in:
Ted Johansson 2024-06-12 16:41:02 +08:00 committed by GitHub
parent 7e31a8104d
commit 6be4ef59fa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 6 deletions

View File

@ -19,10 +19,7 @@ class UserField < ActiveRecord::Base
scope :public_fields, -> { where(show_on_profile: true).or(where(show_on_user_card: true)) }
enum :requirement, { optional: 0, for_all_users: 1, on_signup: 2 }.freeze
# TODO: Drop old field_type and rename this column into field_type and remove alias.
enum :field_type_enum, { text: 0, confirm: 1, dropdown: 2, multiselect: 3 }.freeze
alias_attribute :field_type, :field_type_enum
enum :field_type, { text: 0, confirm: 1, dropdown: 2, multiselect: 3 }.freeze
def self.max_length
2048
@ -51,7 +48,6 @@ end
#
# id :integer not null, primary key
# name :string not null
# field_type :string
# created_at :datetime not null
# updated_at :datetime not null
# editable :boolean default(FALSE), not null
@ -64,5 +60,5 @@ end
# external_type :string
# searchable :boolean default(FALSE), not null
# requirement :integer default("optional"), not null
# field_type_enum :integer not null
# field_type :integer not null
#

View File

@ -0,0 +1,14 @@
# frozen_string_literal: true
class SwapFieldTypeWithFieldTypeEnumOnUserFields < ActiveRecord::Migration[7.0]
DROPPED_COLUMNS ||= { user_fields: %i[field_type] }
def up
DROPPED_COLUMNS.each { |table, columns| Migration::ColumnDropper.execute_drop(table, columns) }
rename_column :user_fields, :field_type_enum, :field_type
end
def down
raise ActiveRecord::IrreversibleMigration
end
end