pr_01m47d15m3e54sn21z27rpy5n9/services/automations/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.
| Automations: rules in .g1t/automations that act when something happens | 1 | -- Automations, read from repositories' .g1t/automations, and their runs. |
| 2 | -- Every timestamp is RFC 3339 UTC. | |
| 3 | ||
| 4 | CREATE TABLE automations ( | |
| 5 | id TEXT PRIMARY KEY, | |
| 6 | repo_id TEXT NOT NULL, | |
| 7 | -- owner/name. | |
| 8 | repo TEXT NOT NULL, | |
| 9 | -- The file it comes from. | |
| 10 | path TEXT NOT NULL, | |
| 11 | name TEXT NOT NULL, | |
| 12 | -- The file as it is on the default branch. | |
| 13 | source TEXT NOT NULL, | |
| 14 | -- events, schedule, manual, or invalid. | |
| 15 | trigger_kind TEXT NOT NULL, | |
| 16 | -- For events: the types that start it, as a JSON array. | |
| 17 | events TEXT NOT NULL, | |
| 18 | -- Why the file cannot be used, if it cannot. | |
| 19 | error TEXT, | |
| 20 | -- Kept across reloads of the file: a member can turn one off. | |
| 21 | enabled INTEGER NOT NULL DEFAULT 1, | |
| 22 | updated_at TEXT NOT NULL, | |
| 23 | UNIQUE (repo_id, path) | |
| 24 | ); | |
| 25 | CREATE INDEX automations_by_trigger ON automations (repo_id, enabled, trigger_kind); | |
| 26 | CREATE INDEX automations_scheduled ON automations (trigger_kind, enabled); | |
| 27 | ||
| 28 | CREATE TABLE runs ( | |
| 29 | id TEXT PRIMARY KEY, | |
| 30 | automation_id TEXT NOT NULL, | |
| 31 | repo_id TEXT NOT NULL, | |
| 32 | -- What started it, unique per automation: an event's id, the minute of a | |
| 33 | -- schedule, or a manual run's own key. An event runs an automation once. | |
| 34 | event_key TEXT NOT NULL, | |
| 35 | name TEXT NOT NULL, | |
| 36 | event TEXT NOT NULL, | |
| 37 | number INTEGER, | |
| 38 | -- running, succeeded, failed or skipped. | |
| 39 | status TEXT NOT NULL, | |
| 40 | reason TEXT, | |
| 41 | -- Each step's result, as JSON. | |
| 42 | steps TEXT NOT NULL, | |
| 43 | actor TEXT, | |
| 44 | started_at TEXT NOT NULL, | |
| 45 | UNIQUE (automation_id, event_key) | |
| 46 | ); | |
| 47 | CREATE INDEX runs_by_repo ON runs (repo_id, id); | |
| 48 | CREATE INDEX runs_by_automation ON runs (automation_id, id); | |
| 49 | ||
| 50 | -- What an automation just touched, so it does not answer its own doing. | |
| 51 | CREATE TABLE effects ( | |
| 52 | automation_id TEXT NOT NULL, | |
| 53 | repo_id TEXT NOT NULL, | |
| 54 | number INTEGER NOT NULL, | |
| 55 | at TEXT NOT NULL | |
| 56 | ); | |
| 57 | CREATE INDEX effects_recent ON effects (automation_id, repo_id, number, at); | |
| 58 | ||
| 59 | -- Repositories whose files have been read at least once. | |
| 60 | CREATE TABLE synced ( | |
| 61 | repo_id TEXT PRIMARY KEY, | |
| 62 | at TEXT NOT NULL | |
| 63 | ); |