OXYGENHUB
◆ v0.9.6 oxygenhub / crates / hub / migrations / 0060_backups.sql
1.4 KiB · SQL · last changed feat: backups for users and organisations, to a directory, with restore (refs #169) 22 days ago source blame history raw
d7d18246 Andy McCall ↶ 1
-- Backups (docs/backups.md, oxygenhub#169): what each user and organisation
2
-- backs up, where and how often, and how each run went.
3
CREATE TABLE backup_settings (
4
    owner       TEXT PRIMARY KEY,
5
    -- 'user' or 'org'
6
    kind        TEXT NOT NULL,
7
    -- 'off', 'hourly' or 'daily'
8
    every       TEXT NOT NULL DEFAULT 'off',
9
    -- 'dir' (a directory hub.toml allows) or 'gcs'
10
    destination TEXT NOT NULL DEFAULT 'dir',
11
    -- the directory, or the bucket
12
    target      TEXT NOT NULL DEFAULT '',
13
    prefix      TEXT NOT NULL DEFAULT '',
14
    -- for 'gcs': the workload identity provider's resource name
15
    provider    TEXT NOT NULL DEFAULT '',
16
    keep_days   INTEGER NOT NULL DEFAULT 30,
17
    updated_ms  INTEGER NOT NULL
18
);
19
20
CREATE TABLE backup_runs (
21
    id          INTEGER PRIMARY KEY,
22
    owner       TEXT NOT NULL,
23
    started_ms  INTEGER NOT NULL,
24
    finished_ms INTEGER,
25
    -- 'running', 'ok', 'partial' or 'failed'
26
    status      TEXT NOT NULL,
27
    -- the run's name at its destination (runs/<at>/)
28
    at          TEXT NOT NULL DEFAULT '',
29
    repos       INTEGER NOT NULL DEFAULT 0,
30
    files       INTEGER NOT NULL DEFAULT 0,
31
    sent        INTEGER NOT NULL DEFAULT 0,
32
    bytes       INTEGER NOT NULL DEFAULT 0,
33
    detail      TEXT NOT NULL DEFAULT '',
34
    -- 'schedule' or 'now'
35
    trigger     TEXT NOT NULL DEFAULT 'schedule'
36
);
37
CREATE INDEX backup_runs_by_owner ON backup_runs (owner, id DESC);