pr_01m47d15m3e54sn21z27rpy5n9/services/deployments/migrations/0002_projects.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.
| Projects: what a workspace builds and runs, first on every page | 1 | -- Deployments belong to projects, and previews to branches. The tables |
| 2 | -- from before held only the first test deployments; they are replaced, and | |
| 3 | -- the sweep takes their apps out of the namespace. | |
| 4 | ||
| 5 | DROP TABLE settings; | |
| 6 | DROP TABLE apps; | |
| 7 | DROP TABLE deployments; | |
| 8 | ||
| 9 | -- Each project's choices. A project not listed does not deploy. | |
| 10 | CREATE TABLE settings ( | |
| 11 | project_id TEXT PRIMARY KEY, | |
| 12 | workspace TEXT NOT NULL, | |
| 13 | slug TEXT NOT NULL, | |
| 14 | repo_id TEXT NOT NULL, | |
| 15 | enabled INTEGER NOT NULL DEFAULT 0, | |
| 16 | previews INTEGER NOT NULL DEFAULT 1, | |
| 17 | production INTEGER NOT NULL DEFAULT 1, | |
| 18 | build_command TEXT, | |
| 19 | output_dir TEXT, | |
| 20 | idle_days INTEGER NOT NULL DEFAULT 7, | |
| 21 | updated_by TEXT, | |
| 22 | updated_at TEXT NOT NULL | |
| 23 | ); | |
| 24 | CREATE INDEX settings_by_repo ON settings (repo_id); | |
| 25 | ||
| 26 | -- Apps that are up, one per script in the dispatch namespace. The script's | |
| 27 | -- name is the hostname's first label on g1t.page. | |
| 28 | CREATE TABLE apps ( | |
| 29 | script TEXT PRIMARY KEY, | |
| 30 | project_id TEXT NOT NULL, | |
| 31 | workspace TEXT NOT NULL, | |
| 32 | slug TEXT NOT NULL, | |
| 33 | -- preview or production. | |
| 34 | kind TEXT NOT NULL, | |
| 35 | -- For a preview: the branch (or pr-<n> for a fork) and its pull request. | |
| 36 | branch TEXT, | |
| 37 | number INTEGER, | |
| 38 | commit_sha TEXT NOT NULL, | |
| 39 | deployed_at TEXT NOT NULL, | |
| 40 | created_at TEXT NOT NULL, | |
| 41 | last_request_at TEXT | |
| 42 | ); | |
| 43 | CREATE INDEX apps_by_project ON apps (project_id, kind, branch); | |
| 44 | CREATE INDEX apps_by_workspace ON apps (workspace); | |
| 45 | ||
| 46 | -- Every build, and where it went. | |
| 47 | CREATE TABLE deployments ( | |
| 48 | id TEXT PRIMARY KEY, | |
| 49 | project_id TEXT NOT NULL, | |
| 50 | workspace TEXT NOT NULL, | |
| 51 | slug TEXT NOT NULL, | |
| 52 | repo_id TEXT NOT NULL, | |
| 53 | -- The repository, as namespace/name, for links and charges. | |
| 54 | repo TEXT NOT NULL, | |
| 55 | kind TEXT NOT NULL, | |
| 56 | branch TEXT, | |
| 57 | number INTEGER, | |
| 58 | commit_sha TEXT NOT NULL, | |
| 59 | script TEXT NOT NULL, | |
| 60 | -- queued, building, ready, failed or skipped. | |
| 61 | status TEXT NOT NULL, | |
| 62 | error TEXT, | |
| 63 | warnings TEXT NOT NULL DEFAULT '[]', | |
| 64 | log TEXT, | |
| 65 | token_hash TEXT, | |
| 66 | trusted INTEGER NOT NULL DEFAULT 0, | |
| 67 | build_seconds INTEGER, | |
| 68 | created_by TEXT NOT NULL, | |
| 69 | created_at TEXT NOT NULL, | |
| 70 | started_at TEXT, | |
| 71 | finished_at TEXT | |
| 72 | ); | |
| 73 | CREATE INDEX deployments_by_project ON deployments (project_id, id); | |
| 74 | CREATE INDEX deployments_by_status ON deployments (status, created_at); |