20161006213403_rails_settings_migration.rb 709 B

1234567891011121314151617181920212223
  1. # frozen_string_literal: true
  2. MIGRATION_BASE_CLASS = if ActiveRecord::VERSION::MAJOR >= 5
  3. ActiveRecord::Migration[5.0]
  4. else
  5. ActiveRecord::Migration[4.2]
  6. end
  7. class RailsSettingsMigration < MIGRATION_BASE_CLASS
  8. def self.up
  9. create_table :settings do |t|
  10. t.string :var, null: false
  11. t.text :value
  12. t.references :target, null: false, polymorphic: true, index: { name: 'index_settings_on_target_type_and_target_id' }
  13. t.timestamps null: true
  14. end
  15. add_index :settings, [:target_type, :target_id, :var], unique: true
  16. end
  17. def self.down
  18. drop_table :settings
  19. end
  20. end