Module: Woods::Db::Migrations::CreateEdges
- Defined in:
- lib/woods/db/migrations/002_create_edges.rb
Overview
Creates the woods_edges table for storing unit relationships.
Constant Summary collapse
- VERSION =
2
Class Method Summary collapse
Class Method Details
.up(connection) ⇒ void
This method returns an undefined value.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/woods/db/migrations/002_create_edges.rb', line 12 def self.up(connection) connection.execute(<<~SQL) CREATE TABLE IF NOT EXISTS woods_edges ( id INTEGER PRIMARY KEY AUTOINCREMENT, source_id INTEGER NOT NULL, target_id INTEGER NOT NULL, relationship TEXT NOT NULL, via TEXT, created_at TEXT NOT NULL DEFAULT (datetime('now')), FOREIGN KEY (source_id) REFERENCES woods_units(id), FOREIGN KEY (target_id) REFERENCES woods_units(id) ) SQL connection.execute(<<~SQL) CREATE INDEX IF NOT EXISTS idx_woods_edges_source ON woods_edges(source_id) SQL connection.execute(<<~SQL) CREATE INDEX IF NOT EXISTS idx_woods_edges_target ON woods_edges(target_id) SQL end |