CREATE TABLE IF NOT EXISTS app_store_installs (
    id TEXT PRIMARY KEY,
    agent_id TEXT NOT NULL,
    slug TEXT NOT NULL,
    name TEXT NOT NULL,
    project TEXT NOT NULL,
    status TEXT NOT NULL,
    params_json TEXT NOT NULL DEFAULT '{}',
    result_json TEXT,
    error TEXT,
    created_at TEXT NOT NULL DEFAULT (datetime('now')),
    updated_at TEXT NOT NULL DEFAULT (datetime('now')),
    FOREIGN KEY(agent_id) REFERENCES agents(id) ON DELETE CASCADE
);

CREATE INDEX IF NOT EXISTS idx_app_store_installs_agent ON app_store_installs(agent_id, updated_at DESC);
CREATE INDEX IF NOT EXISTS idx_app_store_installs_slug ON app_store_installs(slug, updated_at DESC);
