discourse/db/migrate/20170501191912_add_upload_id_to_theme_fields.rb
Sam Saffron 30990006a9 DEV: enable frozen string literal on all files
This reduces chances of errors where consumers of strings mutate inputs
and reduces memory usage of the app.

Test suite passes now, but there may be some stuff left, so we will run
a few sites on a branch prior to merging
2019-05-13 09:31:32 +08:00

30 lines
1.1 KiB
Ruby

# frozen_string_literal: true
class AddUploadIdToThemeFields < ActiveRecord::Migration[4.2]
def up
remove_index :theme_fields, [:theme_id, :target, :name]
rename_column :theme_fields, :target, :target_id
# we need a throwaway column here to keep running
add_column :theme_fields, :target, :integer
execute "UPDATE theme_fields SET target = target_id"
change_column :theme_fields, :name, :string, null: false, limit: 30
add_column :theme_fields, :upload_id, :integer
add_column :theme_fields, :type_id, :integer, null: false, default: 0
add_index :theme_fields, [:theme_id, :target_id, :type_id, :name], unique: true, name: 'theme_field_unique_index'
execute "UPDATE theme_fields SET type_id = 1 WHERE name IN ('scss', 'embedded_scss')"
end
def down
remove_column :theme_fields, :target
execute 'drop index theme_field_unique_index'
rename_column :theme_fields, :target_id, :target
remove_column :theme_fields, :upload_id
remove_column :theme_fields, :type_id
add_index :theme_fields, [:theme_id, :target, :name], unique: true
end
end