Sha256: 5509fd47286dad9881a41dd20431d8da66b456c935114561260813b065751ff0

Contents?: true

Size: 783 Bytes

Versions: 4

Compression:

Stored size: 783 Bytes

Contents

class CreateTags < ActiveRecord::Migration
  def change

    create_table :tags do |t|
      t.string :name
      t.string :title
      t.integer :parent_id
      t.timestamps
    end

    create_table :tags_hierarchies, :id => false do |t|
      t.integer :ancestor_id, :null => false # ID of the parent/grandparent/great-grandparent/... tag
      t.integer :descendant_id, :null => false # ID of the target tag
      t.integer :generations, :null => false # Number of generations between the ancestor and the descendant. Parent/child = 1, for example.
    end

    # For "all progeny of..." selects:
    add_index :tags_hierarchies, [:ancestor_id, :descendant_id], :unique => true

    # For "all ancestors of..." selects
    add_index :tags_hierarchies, :descendant_id

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
closure_tree-1.0.0 test/dummy/db/migrate/20110522004834_create_tags.rb
closure_tree-1.0.0.beta6 test/dummy/db/migrate/20110522004834_create_tags.rb
closure_tree-1.0.0.beta5 test/dummy/db/migrate/20110522004834_create_tags.rb
closure_tree-1.0.0.beta3 test/dummy/db/migrate/20110522004834_create_tags.rb