/**
 * SQLite database schema for the PocketCoder daemon.
 * Matches PRD.md Section 5 exactly.
 */
export const SCHEMA_SQL = `
-- Registered projects
CREATE TABLE IF NOT EXISTS projects (
  project_id TEXT PRIMARY KEY,
  name TEXT NOT NULL,
  path TEXT NOT NULL UNIQUE,
  created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
  last_opened_at DATETIME
);

-- Filesystem watcher state (only seq for sync)
CREATE TABLE IF NOT EXISTS fs_state (
  project_id TEXT PRIMARY KEY REFERENCES projects(project_id) ON DELETE CASCADE,
  last_seq INTEGER NOT NULL DEFAULT 0
);

-- Command execution history
CREATE TABLE IF NOT EXISTS command_runs (
  request_id TEXT PRIMARY KEY,
  project_id TEXT NOT NULL REFERENCES projects(project_id) ON DELETE CASCADE,
  command TEXT NOT NULL,
  started_at DATETIME DEFAULT CURRENT_TIMESTAMP,
  ended_at DATETIME,
  exit_code INTEGER,
  truncated BOOLEAN DEFAULT FALSE,
  output_preview TEXT
);

-- Terminal session tracking
CREATE TABLE IF NOT EXISTS terminal_sessions (
  terminal_id TEXT PRIMARY KEY,
  project_id TEXT NOT NULL REFERENCES projects(project_id) ON DELETE CASCADE,
  pid INTEGER,
  created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
  closed_at DATETIME
);

-- Indexes for frequently queried columns
CREATE INDEX IF NOT EXISTS idx_projects_path ON projects(path);
CREATE INDEX IF NOT EXISTS idx_command_runs_project ON command_runs(project_id);
CREATE INDEX IF NOT EXISTS idx_command_runs_started ON command_runs(started_at);
CREATE INDEX IF NOT EXISTS idx_terminal_sessions_project ON terminal_sessions(project_id);
CREATE INDEX IF NOT EXISTS idx_terminal_sessions_created ON terminal_sessions(created_at);
`;
//# sourceMappingURL=schema.js.map