Skip to content

g1t/services/deployments/migrations/0010_repo_deployments.sql

64 lines2,370 bytesCodeBlame
1-- A repository's deployments wherever they run: reported through the API
2-- by any CI, or made by a g1t Actions job with an `environment:`. g1t.page
3-- builds stay in `deployments` and are read into the same model, never
4-- copied (src/repo-deployments.ts). Every timestamp is RFC 3339 UTC.
5
6-- The environments deployments went to, each named once per repository
7-- whatever its case: the first deployment's spelling is kept.
8CREATE TABLE environments (
9 repo_id TEXT NOT NULL,
10 name TEXT NOT NULL COLLATE NOCASE,
11 created_at TEXT NOT NULL,
12 PRIMARY KEY (repo_id, name)
13);
14
15-- Each reported deployment, with its latest status's state and addresses.
16CREATE TABLE reported_deployments (
17 -- dep_…
18 id TEXT PRIMARY KEY,
19 repo_id TEXT NOT NULL,
20 environment TEXT NOT NULL COLLATE NOCASE,
21 ref TEXT NOT NULL,
22 sha TEXT NOT NULL,
23 task TEXT NOT NULL DEFAULT 'deploy',
24 description TEXT,
25 -- A JSON object, as given.
26 payload TEXT NOT NULL DEFAULT '{}',
27 transient_environment INTEGER NOT NULL DEFAULT 0,
28 production_environment INTEGER NOT NULL DEFAULT 0,
29 -- queued, in_progress, success, failure, error or inactive.
30 state TEXT NOT NULL,
31 environment_url TEXT,
32 log_url TEXT,
33 -- A username, or g1t.
34 creator TEXT NOT NULL,
35 -- api or actions.
36 source TEXT NOT NULL,
37 -- For actions: the run and its attempt. One deployment per run, attempt
38 -- and environment, however many of its jobs name the environment.
39 run_id TEXT,
40 run_attempt INTEGER,
41 run_url TEXT,
42 created_at TEXT NOT NULL,
43 updated_at TEXT NOT NULL
44);
45CREATE INDEX reported_by_repo ON reported_deployments (repo_id, created_at);
46CREATE INDEX reported_by_environment ON reported_deployments (repo_id, environment, created_at);
47CREATE UNIQUE INDEX reported_by_run ON reported_deployments (run_id, run_attempt, environment) WHERE run_id IS NOT NULL;
48
49-- Every status a reported deployment was given, in order.
50CREATE TABLE deployment_statuses (
51 -- dst_…
52 id TEXT PRIMARY KEY,
53 deployment_id TEXT NOT NULL,
54 state TEXT NOT NULL,
55 description TEXT,
56 environment_url TEXT,
57 log_url TEXT,
58 creator TEXT NOT NULL,
59 created_at TEXT NOT NULL
60);
61CREATE INDEX statuses_by_deployment ON deployment_statuses (deployment_id, created_at);
62
63-- g1t.page builds, read by repository alongside the reported ones.
64CREATE INDEX deployments_by_repo ON deployments (repo_id, created_at);