Class: AddHasMagicFieldsTables

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

Instance Method Summary collapse

Instance Method Details

#changeObject



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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/generators/has_magic_fields/install/templates/migration.rb', line 2

def change
  create_table :magic_fields do |t|
    t.column :name,           :string
    t.column :pretty_name,    :string
    t.column :pretty_name_cn,    :string
    t.column :datatype,       :string, :default => "string"
    t.column :default,        :string
    t.column :is_required,    :boolean, :default => false
    t.column :include_blank,  :boolean, :default => false
    t.column :allow_other,    :boolean, :default => true
    t.column :type_scoped,    :string
    t.column :created_at,     :datetime
    t.column :updated_at,     :datetime
  end
  
  create_table :magic_attributes do |t|
    t.column :magic_field_id, :integer
    t.column :value, :string
    t.column :created_at, :datetime
    t.column :updated_at, :datetime
  end
  
  
  create_table :magic_field_relationships do |t|
    t.column :magic_field_id, :integer
    t.column :owner_id, :integer
    t.column :owner_type, :string
    t.column :name, :string
    t.column :type_scoped,   :string
    t.column :created_at, :datetime
    t.column :updated_at, :datetime
  end
  
  create_table :magic_attribute_relationships do |t|
    t.column :magic_attribute_id, :integer
    t.column :owner_id, :integer
    t.column :owner_type, :string
    t.column :created_at, :datetime
    t.column :updated_at, :datetime
  end  

  add_index :magic_attribute_relationships, [:magic_attribute_id, :owner_id, :owner_type], name:"magic_attribute_id_owner", :unique => true
  add_index :magic_field_relationships, [:magic_field_id, :owner_id, :owner_type], name:"magic_field_id_owner", :unique => true
  add_index :magic_field_relationships, [:name, :type_scoped, :owner_id, :owner_type], name:"magic_field_name_owner", :unique => true
end