20170112154826_migrate_settings.rb 886 B

123456789101112131415161718192021
  1. # frozen_string_literal: true
  2. class MigrateSettings < ActiveRecord::Migration[4.2]
  3. def up
  4. remove_index :settings, [:target_type, :target_id, :var]
  5. rename_column :settings, :target_id, :thing_id
  6. rename_column :settings, :target_type, :thing_type
  7. change_column :settings, :thing_id, :integer, null: true, default: nil
  8. change_column :settings, :thing_type, :string, null: true, default: nil
  9. add_index :settings, [:thing_type, :thing_id, :var], unique: true
  10. end
  11. def down
  12. remove_index :settings, [:thing_type, :thing_id, :var]
  13. rename_column :settings, :thing_id, :target_id
  14. rename_column :settings, :thing_type, :target_type
  15. change_column :settings, :target_id, :integer, null: false
  16. change_column :settings, :target_type, :string, null: false, default: ''
  17. add_index :settings, [:target_type, :target_id, :var], unique: true
  18. end
  19. end