DROP INDEX IF EXISTS idx_file_index_path_cwd;
DROP TABLE IF EXISTS file_index_path;

CREATE TABLE IF NOT EXISTS file_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 file_index_child_path (
  parent_id INTEGER NOT NULL,
  path TEXT NOT NULL,
  PRIMARY KEY (parent_id, path),
  FOREIGN KEY (parent_id) REFERENCES file_index_parent_path(id) ON DELETE CASCADE
);
CREATE INDEX IF NOT EXISTS idx_file_index_child_path_parent ON file_index_child_path(parent_id);
