CREATE TABLE asm3_import_runs (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  source_name TEXT NOT NULL,
  source_sha256 TEXT NOT NULL,
  status TEXT NOT NULL CHECK(status IN ('completed','failed')),
  summary_json TEXT NOT NULL,
  backup_name TEXT,
  created_at TEXT NOT NULL DEFAULT (datetime('now'))
);
CREATE TABLE asm3_import_links (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  source_sha256 TEXT NOT NULL,
  entity_type TEXT NOT NULL,
  source_id INTEGER NOT NULL,
  target_id INTEGER NOT NULL,
  import_run_id INTEGER NOT NULL,
  created_at TEXT NOT NULL DEFAULT (datetime('now')),
  UNIQUE(source_sha256,entity_type,source_id),
  FOREIGN KEY(import_run_id) REFERENCES asm3_import_runs(id) ON DELETE CASCADE
);
CREATE INDEX idx_asm3_import_links_target ON asm3_import_links(entity_type,target_id);
