1
0

20161006213403_rails_settings_migration.rb 588 B

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