about summary refs log tree commit diff
path: root/db/migrate/20161006213403_rails_settings_migration.rb
blob: 9d565cb5c6f1155a33637d8b3fd0c50926893815 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
MIGRATION_BASE_CLASS = if ActiveRecord::VERSION::MAJOR >= 5
  ActiveRecord::Migration[5.0]
else
  ActiveRecord::Migration[4.2]
end

class RailsSettingsMigration < MIGRATION_BASE_CLASS
  def self.up
    create_table :settings do |t|
      t.string     :var, null: false
      t.text       :value
      t.references :target, null: false, polymorphic: true, index: { name: 'index_settings_on_target_type_and_target_id' }
      t.timestamps null: true
    end
    add_index :settings, [ :target_type, :target_id, :var ], unique: true
  end

  def self.down
    drop_table :settings
  end
end