-- 005_backups.sql — instance backups (tar.gz of volumes).
--
-- The agent writes the archive to disk under its --backup-dir and
-- reports back path + size. Controller persists the row so operators
-- can list / restore / delete later.

CREATE TABLE backups (
    id            TEXT PRIMARY KEY,                              -- bkp_<hex16>
    instance_id   TEXT NOT NULL,
    agent_id      TEXT NOT NULL,
    path          TEXT NOT NULL,                                 -- absolute path on the agent
    size_bytes    BIGINT NOT NULL DEFAULT 0,
    description   TEXT NOT NULL DEFAULT '',
    created_at    TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

CREATE INDEX idx_backups_instance ON backups(instance_id);
CREATE INDEX idx_backups_created  ON backups(created_at DESC);
