g1t/services/deployments/migrations/0001_init.sql
Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.
| Deployments: a preview for every pull request, production on g1t.page | 1 | -- Deployments: previews per pull request and production, on g1t.page. |
| 2 | -- Every timestamp is RFC 3339 UTC. | |
| 3 | ||
| 4 | -- Each repository's choices. A repository not listed does not deploy. | |
| 5 | CREATE TABLE settings ( | |
| 6 | repo_id TEXT PRIMARY KEY, | |
| 7 | -- The workspace's slug and the repository's name. | |
| 8 | namespace TEXT NOT NULL, | |
| 9 | name TEXT NOT NULL, | |
| 10 | enabled INTEGER NOT NULL DEFAULT 0, | |
| 11 | previews INTEGER NOT NULL DEFAULT 1, | |
| 12 | production INTEGER NOT NULL DEFAULT 1, | |
| 13 | build_command TEXT, | |
| 14 | output_dir TEXT, | |
| 15 | idle_days INTEGER NOT NULL DEFAULT 7, | |
| 16 | updated_by TEXT, | |
| 17 | updated_at TEXT NOT NULL | |
| 18 | ); | |
| 19 | ||
| 20 | -- Apps that are up, one per script in the dispatch namespace. The script's | |
| 21 | -- name is the hostname's first label on g1t.page. | |
| 22 | CREATE TABLE apps ( | |
| 23 | script TEXT PRIMARY KEY, | |
| 24 | repo_id TEXT NOT NULL, | |
| 25 | namespace TEXT NOT NULL, | |
| 26 | name TEXT NOT NULL, | |
| 27 | -- preview or production. | |
| 28 | kind TEXT NOT NULL, | |
| 29 | -- For a preview: the pull request. | |
| 30 | number INTEGER, | |
| 31 | commit_sha TEXT NOT NULL, | |
| 32 | deployed_at TEXT NOT NULL, | |
| 33 | created_at TEXT NOT NULL, | |
| 34 | -- When it last answered a request, as of the last count. | |
| 35 | last_request_at TEXT | |
| 36 | ); | |
| 37 | CREATE INDEX apps_by_repo ON apps (repo_id, kind, number); | |
| 38 | CREATE INDEX apps_by_workspace ON apps (namespace); | |
| 39 | ||
| 40 | -- Every build, and where it went. | |
| 41 | CREATE TABLE deployments ( | |
| 42 | id TEXT PRIMARY KEY, | |
| 43 | repo_id TEXT NOT NULL, | |
| 44 | namespace TEXT NOT NULL, | |
| 45 | name TEXT NOT NULL, | |
| 46 | kind TEXT NOT NULL, | |
| 47 | number INTEGER, | |
| 48 | commit_sha TEXT NOT NULL, | |
| 49 | script TEXT NOT NULL, | |
| 50 | -- queued, building, ready, failed or skipped. | |
| 51 | status TEXT NOT NULL, | |
| 52 | error TEXT, | |
| 53 | -- A JSON array. | |
| 54 | warnings TEXT NOT NULL DEFAULT '[]', | |
| 55 | log TEXT, | |
| 56 | -- SHA-256 of the token the sandbox reports with. | |
| 57 | token_hash TEXT, | |
| Secrets and variables: one list, rows per environment, for workflows and deployments | 58 | -- Whether it was built for someone trusted: a member, an agent, or a |
| 59 | -- push. Protected secrets and variables, and every secret, reach only | |
| 60 | -- trusted builds and their apps. | |
| 61 | trusted INTEGER NOT NULL DEFAULT 0, | |
| Deployments: a preview for every pull request, production on g1t.page | 62 | build_seconds INTEGER, |
| 63 | created_by TEXT NOT NULL, | |
| 64 | created_at TEXT NOT NULL, | |
| 65 | started_at TEXT, | |
| 66 | finished_at TEXT | |
| 67 | ); | |
| 68 | CREATE INDEX deployments_by_repo ON deployments (repo_id, id); | |
| 69 | CREATE INDEX deployments_by_status ON deployments (status, created_at); | |
| 70 | ||
| 71 | -- What each workspace's apps used, per month: counted from Cloudflare's | |
| 72 | -- analytics, and charged past the plan's allowance once the month is over. | |
| 73 | CREATE TABLE meters ( | |
| 74 | namespace TEXT NOT NULL, | |
| 75 | -- YYYY-MM. | |
| 76 | month TEXT NOT NULL, | |
| 77 | requests INTEGER NOT NULL DEFAULT 0, | |
| 78 | cpu_ms INTEGER NOT NULL DEFAULT 0, | |
| 79 | peak_apps INTEGER NOT NULL DEFAULT 0, | |
| 80 | build_seconds INTEGER NOT NULL DEFAULT 0, | |
| 81 | build_micros INTEGER NOT NULL DEFAULT 0, | |
| 82 | counted_at TEXT, | |
| 83 | -- When the month's usage past the allowance was charged. | |
| 84 | charged_at TEXT, | |
| 85 | PRIMARY KEY (namespace, month) | |
| 86 | ); |