CREATE TABLE entity_aliases (
entity_id TEXT NOT NULL,
alias_type TEXT NOT NULL,
-- name|email|phone|slack_user|calendar_id|ticker|external_id
alias_value TEXT NOT NULL,
source_id TEXT,
-- which integration asserted it
confidence REAL DEFAULT 0.0,
created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now')),
updated_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now')),
PRIMARY KEY (alias_type, alias_value),
FOREIGN KEY (entity_id) REFERENCES entities(id) ON DELETE RESTRICT DEFERRABLE INITIALLY DEFERRED,
FOREIGN KEY (source_id) REFERENCES sources(id) ON DELETE SET NULL DEFERRABLE INITIALLY DEFERRED
)