Class: CategoryDb::CreateDb

Inherits:
Object
  • Object
show all
Defined in:
lib/tagutils/categories/schema.rb

Instance Method Summary collapse

Instance Method Details

#upObject



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
# File 'lib/tagutils/categories/schema.rb', line 7

def up
ActiveRecord::Schema.define do

create_table :categories do |t|
t.string     :key,   null: false
t.string     :slug,  null: false
t.string     :name,  null: false
t.references :parent
# todo: use only t.datetime :created_at (do we get ar magic? is updated used/needed??)
t.timestamps
end

add_index :categories, :key, unique: true

create_table :categorizations do |t|
t.references :category,      null: false, index: false                     ## Note: do NOT auto-add index
t.references :categorizable, null: false, index: false, polymorphic: true  ## Note: do NOT auto-add index

# todo: use only t.datetime :created_at (do we get ar magic? is updated used/needed??)
t.timestamps
end

###
# note: use name prop
#  too avoid error index name too long (e.g. sqlite requires <64 chars)

add_index :categorizations, :category_id, name: 'categorizations_cats_idx'
add_index :categorizations, [:categorizable_id, :categorizable_type], name: 'categorizations_idx'
add_index :categorizations, [:categorizable_id, :categorizable_type, :category_id], unique: true, name: 'categorizations_unique_idx'

end # Schema.define
end