CREATE TABLE IF NOT EXISTS symbol_index_parent_path (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  path TEXT NOT NULL UNIQUE,
  path_hash TEXT NOT NULL,
  updated_at TEXT NOT NULL
);

CREATE TABLE IF NOT EXISTS symbol_index_tag (
  parent_id INTEGER NOT NULL,
  file_path TEXT NOT NULL,
  name TEXT NOT NULL,
  role TEXT NOT NULL,
  kind TEXT NOT NULL,
  start_line INTEGER NOT NULL,
  start_column INTEGER NOT NULL,
  end_line INTEGER NOT NULL,
  end_column INTEGER NOT NULL,
  PRIMARY KEY (parent_id, file_path, start_line, start_column, role, kind, name),
  FOREIGN KEY (parent_id) REFERENCES symbol_index_parent_path(id) ON DELETE CASCADE
);

CREATE INDEX IF NOT EXISTS idx_symbol_index_tag_parent_name ON symbol_index_tag(parent_id, name);
CREATE INDEX IF NOT EXISTS idx_symbol_index_tag_parent_file ON symbol_index_tag(parent_id, file_path);
