-- deploy_server initial schema. Tracks deploy targets (per app+host) and execution history.

CREATE TABLE IF NOT EXISTS deploy_targets (
    app           TEXT NOT NULL,
    host          TEXT NOT NULL,
    remote_dir    TEXT NOT NULL DEFAULT '',
    binary_name   TEXT NOT NULL DEFAULT '',
    build_cmd     TEXT NOT NULL DEFAULT '',
    service_user  TEXT NOT NULL DEFAULT '',
    port          INTEGER NOT NULL DEFAULT 0,
    health_path   TEXT NOT NULL DEFAULT '',
    env           TEXT NOT NULL DEFAULT '{}',
    created_at    TEXT NOT NULL,
    PRIMARY KEY (app, host)
);

CREATE TABLE IF NOT EXISTS deploy_logs (
    id          INTEGER PRIMARY KEY AUTOINCREMENT,
    app         TEXT NOT NULL,
    host        TEXT NOT NULL,
    status      TEXT NOT NULL,
    trigger     TEXT NOT NULL DEFAULT 'manual',
    error       TEXT NOT NULL DEFAULT '',
    duration_ms INTEGER NOT NULL DEFAULT 0,
    started_at  TEXT NOT NULL
);
