class CreateBanyanTables < ActiveRecord::Migration def self.up create_table :banyan_categories do |t| t.string :tag t.integer :parent_id t.integer :lft t.integer :rgt end add_index :banyan_categories, :tag add_index :banyan_categories, :parent_id add_index :banyan_categories, :lft add_index :banyan_categories, :rgt create_table :banyan_categories_category_groups, :id => false do |t| t.integer :category_id t.integer :category_group_id end execute "ALTER TABLE banyan_categories_category_groups ADD PRIMARY KEY (category_id, category_group_id);" add_index :banyan_categories_category_groups, :category_group_id create_table :banyan_categorizations do |t| t.integer :category_id t.references :categorizable, :polymorphic => true end add_index :banyan_categorizations, :category_id add_index :banyan_categorizations, [:categorizable_id, :categorizable_type], :name => 'index_banyan_categorizations_on_categorizable' create_table :banyan_category_groups do |t| t.string :tag t.references :group_categorizable, :polymorphic => true t.integer :parent_id t.integer :lft t.integer :rgt end add_index :banyan_category_groups, :tag add_index :banyan_category_groups, [:group_categorizable_id, :group_categorizable_type], :name => 'index_banyan_category_groups_on_group_categorizable' add_index :banyan_category_groups, :parent_id add_index :banyan_category_groups, :lft add_index :banyan_category_groups, :rgt Banyan::Category.create_translation_table! :name => :string Banyan::CategoryGroup.create_translation_table! :name => :string end def self.down drop_table :banyan_category_groups drop_table :banyan_categorizations drop_table :banyan_categories_category_groups drop_table :banyan_categories Banyan::Category.drop_translation_table! Banyan::CategoryGroup.drop_translation_table! end end