Class: SemanticallyTaggableMigration

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

Class Method Summary collapse

Class Method Details

.downObject



65
66
67
68
69
70
71
72
# File 'lib/generators/semantically_taggable/migration/templates/active_record/migration.rb', line 65

def self.down
  drop_table :schemes
  drop_table :taggings
  drop_table :tags
  drop_table :tag_parentages
  drop_table :related_tags
  drop_table :synonyms
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/generators/semantically_taggable/migration/templates/active_record/migration.rb', line 2

def self.up
  create_table :schemes do |t|
    t.string :name
    t.string :meta_name
    t.string :meta_scheme
    t.string :description
    t.string :delimiter, :limit => 10, :default => ','
    t.boolean :polyhierarchical, :default => false
    t.boolean :restrict_to_known_tags, :default => false
  end

  add_index :schemes, :name, :unique => true

  create_table :tags do |t|
    t.string :name
    t.integer :scheme_id
    t.string :original_id
  end

  add_index :tags, :name
  add_index :tags, :scheme_id

  create_table :taggings do |t|
    t.references :tag

    # You should make sure that the column created is
    # long enough to store the required class names.
    t.references :taggable, :polymorphic => true

    t.datetime :created_at
  end

  add_index :taggings, :tag_id
  add_index :taggings, [:taggable_id, :taggable_type]

  # Transitive closure table for multiple parent tags
  # Works bidirectionally to support model.narrower_tags and model.broader_tags
  create_table :tag_parentages, :id => false, :force => true do |t|
    t.integer :parent_tag_id
    t.integer :child_tag_id
    t.integer :distance, :default => 1
  end

  add_index :tag_parentages, :parent_tag_id
  add_index :tag_parentages, :child_tag_id
  add_index :tag_parentages, [:parent_tag_id, :child_tag_id, :distance], :unique => true,
            :name => 'index_tag_parentages_on_parent_child_distance'

  create_table :related_tags, :id => false, :force => true do |t|
    t.integer :tag_id
    t.integer :related_tag_id
  end

  add_index :related_tags, [:tag_id, :related_tag_id], :unique => true

  create_table :synonyms, :force => true do |t|
    t.string :name
    t.integer :tag_id
  end

  add_index :synonyms, :tag_id
end