Module: Dagable::MigrationHelpers

Defined in:
lib/dagable/migration_helpers.rb

Overview

Schema helpers for creating the two supporting tables that every dagable model requires. Include this module in your migration class.

Usage

class CreateCategoryDag < ActiveRecord::Migration[8.1]
  include Dagable::MigrationHelpers

  def change
    create_dagable_tables(:categories)
  end
end

This creates:

  • categories_edges with parent_id and child_id columns, a unique composite index, and foreign keys back to the source table

  • categories_ancestries with predecessor_id, successor_id, and depth columns, a unique composite index, individual indexes on each foreign key, and foreign keys back to the source table

Instance Method Summary collapse

Instance Method Details

#create_dagable_tables(source_table_name) ⇒ Object

Creates the edge and ancestry tables for the given source_table_name.

Parameters:

  • source_table_name (Symbol, String)

    the table name of the dagable model (e.g. :categories)



28
29
30
31
# File 'lib/dagable/migration_helpers.rb', line 28

def create_dagable_tables(source_table_name)
  create_dagable_edges_table(source_table_name)
  create_dagable_ancestries_table(source_table_name)
end