Class: CustomAttributesMigration

Inherits:
ActiveRecord::Migration
  • Object
show all
Defined in:
lib/generators/custom_attributes/migration/templates/active_record/migration.rb

Class Method Summary collapse

Class Method Details

.downObject



29
30
31
# File 'lib/generators/custom_attributes/migration/templates/active_record/migration.rb', line 29

def self.down
  drop_table :custom_attributes
end

.upObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/generators/custom_attributes/migration/templates/active_record/migration.rb', line 2

def self.up
  create_table :custom_attributes do |t|
	# label
    t.string :field_name
    t.string :field_label

    # value type
    t.string :value_type
	
	# fields for value storage
    t.string :text_value
    t.datetime :date_time_value
    t.integer :number_value
    t.float :float_value

	# sorting
    t.integer :position
	# link to object
    t.references :item, :polymorphic => true

    t.timestamps
  end

  add_index :custom_attributes, :value_type
  add_index :custom_attributes, [:item_id, :item_type]
end