1
0

20170112154826_migrate_settings.rb 848 B

12345678910111213141516171819202122232425
  1. # frozen_string_literal: true
  2. class MigrateSettings < ActiveRecord::Migration[4.2]
  3. def up
  4. change_table(:settings, bulk: true) do |t|
  5. t.remove_index [:target_type, :target_id, :var]
  6. t.rename :target_id, :thing_id
  7. t.rename :target_type, :thing_type
  8. t.change :thing_id, :integer, null: true, default: nil
  9. t.change :thing_type, :string, null: true, default: nil
  10. t.index [:thing_type, :thing_id, :var], unique: true
  11. end
  12. end
  13. def down
  14. change_table(:settings, bulk: true) do |t|
  15. t.remove_index [:thing_type, :thing_id, :var]
  16. t.rename :thing_id, :target_id
  17. t.rename :thing_type, :target_type
  18. t.column :target_id, :integer, null: false
  19. t.column :target_type, :string, null: false, default: ''
  20. t.index [:target_type, :target_id, :var], unique: true
  21. end
  22. end
  23. end