1
0

20170112154826_migrate_settings.rb 855 B

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