mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 08:43:25 +08:00
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:
parent
7e31a8104d
commit
6be4ef59fa
|
@ -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
|
||||
#
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue
Block a user