pr_01m47d24b0e6n91zwymwxg0vpx/services/deployments/migrations/0001_init.sql
| 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 | -- A JSON object of variables the build runs with. |
| 16 | build_env TEXT NOT NULL DEFAULT '{}', |
| 17 | idle_days INTEGER NOT NULL DEFAULT 7, |
| 18 | updated_by TEXT, |
| 19 | updated_at TEXT NOT NULL |
| 20 | ); |
| 21 | |
| 22 | -- Apps that are up, one per script in the dispatch namespace. The script's |
| 23 | -- name is the hostname's first label on g1t.page. |
| 24 | CREATE TABLE apps ( |
| 25 | script TEXT PRIMARY KEY, |
| 26 | repo_id TEXT NOT NULL, |
| 27 | namespace TEXT NOT NULL, |
| 28 | name TEXT NOT NULL, |
| 29 | -- preview or production. |
| 30 | kind TEXT NOT NULL, |
| 31 | -- For a preview: the pull request. |
| 32 | number INTEGER, |
| 33 | commit_sha TEXT NOT NULL, |
| 34 | deployed_at TEXT NOT NULL, |
| 35 | created_at TEXT NOT NULL, |
| 36 | -- When it last answered a request, as of the last count. |
| 37 | last_request_at TEXT |
| 38 | ); |
| 39 | CREATE INDEX apps_by_repo ON apps (repo_id, kind, number); |
| 40 | CREATE INDEX apps_by_workspace ON apps (namespace); |
| 41 | |
| 42 | -- Every build, and where it went. |
| 43 | CREATE TABLE deployments ( |
| 44 | id TEXT PRIMARY KEY, |
| 45 | repo_id TEXT NOT NULL, |
| 46 | namespace TEXT NOT NULL, |
| 47 | name TEXT NOT NULL, |
| 48 | kind TEXT NOT NULL, |
| 49 | number INTEGER, |
| 50 | commit_sha TEXT NOT NULL, |
| 51 | script TEXT NOT NULL, |
| 52 | -- queued, building, ready, failed or skipped. |
| 53 | status TEXT NOT NULL, |
| 54 | error TEXT, |
| 55 | -- A JSON array. |
| 56 | warnings TEXT NOT NULL DEFAULT '[]', |
| 57 | log TEXT, |
| 58 | -- SHA-256 of the token the sandbox reports with. |
| 59 | token_hash TEXT, |
| 60 | build_seconds INTEGER, |
| 61 | created_by TEXT NOT NULL, |
| 62 | created_at TEXT NOT NULL, |
| 63 | started_at TEXT, |
| 64 | finished_at TEXT |
| 65 | ); |
| 66 | CREATE INDEX deployments_by_repo ON deployments (repo_id, id); |
| 67 | CREATE INDEX deployments_by_status ON deployments (status, created_at); |
| 68 | |
| 69 | -- What each workspace's apps used, per month: counted from Cloudflare's |
| 70 | -- analytics, and charged past the plan's allowance once the month is over. |
| 71 | CREATE TABLE meters ( |
| 72 | namespace TEXT NOT NULL, |
| 73 | -- YYYY-MM. |
| 74 | month TEXT NOT NULL, |
| 75 | requests INTEGER NOT NULL DEFAULT 0, |
| 76 | cpu_ms INTEGER NOT NULL DEFAULT 0, |
| 77 | peak_apps INTEGER NOT NULL DEFAULT 0, |
| 78 | build_seconds INTEGER NOT NULL DEFAULT 0, |
| 79 | build_micros INTEGER NOT NULL DEFAULT 0, |
| 80 | counted_at TEXT, |
| 81 | -- When the month's usage past the allowance was charged. |
| 82 | charged_at TEXT, |
| 83 | PRIMARY KEY (namespace, month) |
| 84 | ); |