OXYGENHUB
# 76fdeedccf44 oxygenhub / crates / hub / migrations-pg / 0079_terraform_states.sql
1.1 KiB · SQL · last changed The hub keeps Terraform and OpenTofu state (closes #252) 18 days ago source blame history raw
1
-- Terraform and OpenTofu state kept by the hub (oxygenhub#252): one row
2
-- per repository and state name, its body sealed with the hub's secrets
3
-- key, its lock, and the last versions for rolling back.
4
CREATE TABLE terraform_states (
5
    repo_id    BIGINT NOT NULL REFERENCES repositories(id) ON DELETE CASCADE,
6
    name       TEXT NOT NULL,
7
    body       BYTEA NOT NULL,
8
    serial     BIGINT NOT NULL DEFAULT 0,
9
    lock_id    TEXT NOT NULL DEFAULT '',
10
    lock_info  TEXT NOT NULL DEFAULT '',
11
    locked_by  TEXT NOT NULL DEFAULT '',
12
    locked_ms  BIGINT,
13
    updated_by TEXT NOT NULL DEFAULT '',
14
    updated_ms BIGINT NOT NULL,
15
    PRIMARY KEY (repo_id, name)
16
);
17
CREATE TABLE terraform_state_versions (
18
    id         BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
19
    repo_id    BIGINT NOT NULL REFERENCES repositories(id) ON DELETE CASCADE,
20
    name       TEXT NOT NULL,
21
    body       BYTEA NOT NULL,
22
    serial     BIGINT NOT NULL,
23
    created_by TEXT NOT NULL,
24
    created_ms BIGINT NOT NULL
25
);
26
CREATE INDEX terraform_state_versions_state ON terraform_state_versions(repo_id, name, id);