SQL

CREATE TABLE links  (
  id TEXT PRIMARY KEY,
  type TEXT NOT NULL,
  from_id TEXT NOT NULL,
  to_id TEXT NOT NULL,
  valid_from TEXT,
  valid_to TEXT,
  strength REAL,
  rationale_event_id TEXT,
  FOREIGN KEY (from_id) REFERENCES entities(id) ON DELETE RESTRICT DEFERRABLE INITIALLY DEFERRED,
  FOREIGN KEY (to_id) REFERENCES entities(id) ON DELETE RESTRICT DEFERRABLE INITIALLY DEFERRED,
  FOREIGN KEY (rationale_event_id) REFERENCES events(id) ON DELETE SET NULL DEFERRABLE INITIALLY DEFERRED
)

+ Add column

Columns

Column Data type Allow null Primary key Actions
id TEXT Rename | Drop
type TEXT Rename | Drop
from_id TEXT Rename | Drop
to_id TEXT Rename | Drop
valid_from TEXT Rename | Drop
valid_to TEXT Rename | Drop
strength REAL Rename | Drop
rationale_event_id TEXT Rename | Drop

Foreign Keys

Column Destination
rationale_event_id events.id
to_id entities.id
from_id entities.id

+ Add index

Indexes

Name Columns Unique SQL Drop?
idx_links_from
  • from_id
  • type
SQL
CREATE INDEX idx_links_from
ON links (from_id, type)
Drop
idx_links_rationale rationale_event_id SQL
CREATE INDEX idx_links_rationale
ON links (rationale_event_id)
Drop
idx_links_to
  • to_id
  • type
SQL
CREATE INDEX idx_links_to
ON links (to_id, type)
Drop
idx_links_unique_edge
  • type
  • from_id
  • to_id
  • None
SQL
CREATE UNIQUE INDEX idx_links_unique_edge
ON links (type, from_id, to_id, IFNULL(valid_from,''))
Drop
sqlite_autoindex_links_1 id SQL
-- no sql found --
Drop