Cotton code
1931 lines · 50.3 KB · JSONRaw
{  "format_version": 1,  "id": "repository",  "setup": true,  "name": "Repository",  "plural": "Repositories",  "picture": null,  "builtin": true,  "engine": "repos",  "screen_family": "core",  "record_route": "/repos/[id]",  "columns": [    {      "key": "name",      "type": "text",      "required": true,      "readonly": true    },    {      "key": "owner",      "type": "text",      "required": true,      "readonly": true    },    {      "key": "host",      "type": "text",      "required": true,      "readonly": true    },    {      "key": "description",      "type": "longtext",      "readonly": true    },    {      "key": "default_branch",      "name": "Default branch",      "type": "text",      "readonly": true    },    {      "key": "kind",      "name": "Hosted on",      "type": "choice",      "choices": [        "github",        "forgejo",        "cotton"      ],      "readonly": true    },    {      "key": "origin",      "type": "choice",      "choices": [        "forgejo",        "github",        "cotton"      ],      "readonly": true    },    {      "key": "web_url",      "name": "Web address",      "type": "text",      "readonly": true    },    {      "key": "open_pulls",      "name": "Open pull requests",      "type": "number",      "readonly": true    },    {      "key": "open_issues",      "name": "Open issues",      "type": "number",      "readonly": true    },    {      "key": "held",      "name": "Held on a Mac",      "type": "bool",      "readonly": true    },    {      "key": "label",      "name": "Repository",      "type": "text",      "readonly": true    },    {      "key": "sync_state",      "name": "Sync state",      "type": "choice",      "choices": [        "ok",        "pending",        "no_token",        "unsupported",        "error"      ],      "readonly": true    },    {      "key": "sync_line",      "name": "Synced",      "type": "text",      "readonly": true    },    {      "key": "last_error",      "name": "What went wrong",      "type": "text",      "shown_when": {        "column": "sync_state",        "values": [          "pending",          "no_token",          "unsupported",          "error"        ]      },      "readonly": true    },    {      "key": "state",      "name": "State",      "type": "choice",      "choices": [        "Synced",        "Syncing",        "Not synced",        "Holding",        "Hold failed",        "Not held"      ],      "tones": {        "Synced": "green",        "Syncing": "amber",        "Not synced": "red",        "Holding": "amber",        "Hold failed": "red"      },      "readonly": true    },    {      "key": "serving_problem",      "name": "Not servable",      "type": "longtext",      "readonly": true    },    {      "key": "held_line",      "name": "Held in Cotton",      "type": "text",      "readonly": true    },    {      "key": "clone_forks",      "name": "Forked on a Mac",      "type": "longtext",      "readonly": true    },    {      "key": "latest_release",      "name": "Latest release",      "type": "text",      "readonly": true    },    {      "key": "runs_line",      "name": "CI",      "type": "text",      "readonly": true    }  ],  "title": "label",  "date": null,  "project": null,  "order": null,  "slip": {    "title": "label",    "subtitle": "description",    "trailing": null,    "photo": null,    "toggle": null  },  "tile": {    "face": "slip-list"  },  "page": [    {      "heading": null,      "columns": [        "label",        "description",        "clone_forks",        "serving_problem"      ]    },    {      "heading": "Pull requests",      "list": {        "table": "pull",        "link": "open_in"      }    },    {      "heading": "Issues",      "list": {        "table": "issue",        "link": "open_in"      }    },    {      "heading": "CI runs",      "list": {        "table": "run",        "link": "repo_id",        "limit": 5      }    },    {      "heading": "Branch protection",      "list": {        "table": "repo_rule",        "link": "repo_id"      }    },    {      "heading": "Labels",      "list": {        "table": "repo_label",        "link": "repo_id"      }    },    {      "heading": "Variables",      "list": {        "table": "repo_var",        "link": "repo_id"      }    },    {      "heading": "Details",      "columns": [        "default_branch",        "host",        "latest_release",        "runs_line",        "web_url"      ]    }  ],  "instructions": "A repository is a code repository on a host, with its pull requests, issues, releases and CI runs indexed as their own records. A held repository keeps a full copy of its history on the owner's Macs. The counts of open pull requests and issues come from the host.",  "add": false,  "empty": {    "title": "No repositories.",    "message": "A repository appears here once a project names it and the Mac that serves you has read it."  },  "sort": {    "column": "label"  },  "commands": [    {      "id": "build",      "label": "Build",      "object": "agent",      "kind": "update",      "method": "repo.dispatchRun",      "data": {        "workflow": "build-main.yml"      },      "bindings": {        "id": "$id",        "ref": "default_branch"      },      "when": {        "origin": "cotton"      },      "receipt": "Asked the Mac to build {name}"    },    {      "id": "push",      "label": "Push",      "kind": "update",      "method": "repo.setOrigin",      "data": {        "origin": "cotton"      },      "bindings": {        "id": "$id"      },      "when": {        "held": true,        "origin": {          "not": "cotton"        }      },      "receipt": "Asked the Mac to take {name}'s pushes",      "does": "moves"    },    {      "id": "hold",      "label": "Hold",      "object": "pushpin",      "kind": "update",      "method": "repo.hold",      "bindings": {        "id": "$id"      },      "when": {        "held": false      },      "receipt": "Asked the Mac to hold {name}"    },    {      "id": "move_home",      "label": "Move to serving Mac",      "kind": "update",      "method": "repo.moveHome",      "bindings": {        "id": "$id"      },      "when": {        "held": true      },      "receipt": "Moved {name} to the serving Mac",      "does": "moves"    }  ],  "parts": {    "shape": "sheet",    "cards": [      { "column": "serving_problem" }    ],    "head": {      "facts": [        "host",        "default_branch"      ],      "state": "state"    },    "links": [],    "body": "description",    "lists": [      {        "read": {          "name": "repoCommits",          "bindings": {            "id": "$id"          },          "rows": "commits",          "id": "sha",          "title": "message",          "trailing": "sha",          "trailing_format": "short_hash",          "line": [            {              "field": "authorName"            },            {              "field": "authoredAt",              "format": "date"            }          ]        },        "heading": "Commits"      },      {        "table": "pull",        "relation": "open_in",        "heading": "Pull requests"      },      {        "table": "issue",        "relation": "open_in",        "heading": "Issues"      },      {        "table": "run",        "relation": "repo_id",        "heading": "CI runs"      }    ],    "acts": {      "main": "build",      "more": [        "push",        "hold"      ]    }  },  "tables": [    {      "name": "cotton_repos",      "columns": [        {          "name": "id",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": true,          "declaration": "\n    id TEXT PRIMARY KEY",          "position": 0        },        {          "name": "workspace_id",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    workspace_id TEXT NOT NULL",          "position": 1        },        {          "name": "key",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    key TEXT NOT NULL",          "position": 2        },        {          "name": "host",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    host TEXT NOT NULL",          "position": 3        },        {          "name": "owner",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    owner TEXT NOT NULL",          "position": 4        },        {          "name": "name",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    name TEXT NOT NULL",          "position": 5        },        {          "name": "kind",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    kind TEXT NOT NULL",          "position": 6        },        {          "name": "default_branch",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    default_branch TEXT",          "position": 7        },        {          "name": "description",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    description TEXT",          "position": 8        },        {          "name": "web_url",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    web_url TEXT NOT NULL",          "position": 9        },        {          "name": "open_pulls",          "type": "INTEGER",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    open_pulls INTEGER",          "position": 10        },        {          "name": "open_issues",          "type": "INTEGER",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    open_issues INTEGER",          "position": 11        },        {          "name": "sync_state",          "type": "TEXT",          "default": "'pending'",          "nullable": false,          "primary_key": false,          "declaration": "\n    sync_state TEXT NOT NULL DEFAULT 'pending'",          "position": 12        },        {          "name": "last_error",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    last_error TEXT",          "position": 13        },        {          "name": "synced_at",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    synced_at TEXT",          "position": 14        },        {          "name": "pulls_cursor",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    pulls_cursor TEXT",          "position": 15        },        {          "name": "issues_cursor",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    issues_cursor TEXT",          "position": 16        },        {          "name": "held",          "type": "INTEGER",          "default": "0",          "nullable": false,          "primary_key": false,          "declaration": "\n    held INTEGER NOT NULL DEFAULT 0",          "position": 17        },        {          "name": "origin",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    origin TEXT",          "position": 18        },        {          "name": "head_sha",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    head_sha TEXT",          "position": 19        },        {          "name": "held_at",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    held_at TEXT",          "position": 20        },        {          "name": "bundle_state",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    bundle_state TEXT",          "position": 21        },        {          "name": "last_bundle_error",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    last_bundle_error TEXT",          "position": 22        },        {          "name": "created_at",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    created_at TEXT NOT NULL",          "position": 23        },        {          "name": "updated_at",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    updated_at TEXT NOT NULL",          "position": 24        },        {          "name": "_hlc",          "type": "TEXT",          "default": "''",          "nullable": false,          "primary_key": false,          "declaration": "\n    _hlc TEXT NOT NULL DEFAULT ''",          "position": 25        },        {          "name": "_born",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    _born TEXT",          "position": 26        }      ],      "constraints": [        {          "declaration": "\n    UNIQUE (workspace_id, key)",          "position": 27        },        {          "declaration": "\n    CHECK (kind IN ('github', 'forgejo', 'cotton'))",          "position": 28        },        {          "declaration": "\n    CHECK (sync_state IN ('pending', 'ok', 'no_token', 'error', 'unsupported', 'held'))",          "position": 29        },        {          "declaration": "\n    CHECK (held IN (0, 1))",          "position": 30        },        {          "declaration": "\n    CHECK (origin IS NULL OR origin IN ('forgejo', 'github', 'cotton'))",          "position": 31        },        {          "declaration": "\n    CHECK (bundle_state IS NULL OR bundle_state IN ('none', 'bundling', 'ok', 'error'))",          "position": 32        },        {          "declaration": "\n    CHECK (length(trim(key)) > 0)",          "position": 33        },        {          "declaration": "\n    FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n  ",          "position": 34        }      ],      "prefix": "CREATE TABLE IF NOT EXISTS cotton_repos (",      "suffix": ")",      "indexes": [        "CREATE INDEX IF NOT EXISTS idx_cotton_repos_author ON cotton_repos (substr(_hlc, 20), _hlc)"      ],      "full_text": [],      "triggers": []    },    {      "name": "cotton_repo_commits",      "columns": [        {          "name": "id",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": true,          "declaration": "\n    id TEXT PRIMARY KEY",          "position": 0        },        {          "name": "workspace_id",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    workspace_id TEXT NOT NULL",          "position": 1        },        {          "name": "repo_id",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    repo_id TEXT NOT NULL",          "position": 2        },        {          "name": "sha",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    sha TEXT NOT NULL",          "position": 3        },        {          "name": "message",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    message TEXT NOT NULL",          "position": 4        },        {          "name": "author_name",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    author_name TEXT",          "position": 5        },        {          "name": "author_login",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    author_login TEXT",          "position": 6        },        {          "name": "authored_at",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    authored_at TEXT",          "position": 7        },        {          "name": "parents",          "type": "TEXT",          "default": "'[]'",          "nullable": false,          "primary_key": false,          "declaration": "\n    parents TEXT NOT NULL DEFAULT '[]'",          "position": 8        },        {          "name": "html_url",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    html_url TEXT",          "position": 9        },        {          "name": "created_at",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    created_at TEXT NOT NULL",          "position": 10        },        {          "name": "updated_at",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    updated_at TEXT NOT NULL",          "position": 11        },        {          "name": "_hlc",          "type": "TEXT",          "default": "''",          "nullable": false,          "primary_key": false,          "declaration": "\n    _hlc TEXT NOT NULL DEFAULT ''",          "position": 12        },        {          "name": "_born",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    _born TEXT",          "position": 13        }      ],      "constraints": [        {          "declaration": "\n    UNIQUE (workspace_id, repo_id, sha)",          "position": 14        },        {          "declaration": "\n    CHECK (json_type(parents) = 'array')",          "position": 15        },        {          "declaration": "\n    FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE",          "position": 16        },        {          "declaration": "\n    FOREIGN KEY (repo_id) REFERENCES cotton_repos(id)\n  ",          "position": 17        }      ],      "prefix": "CREATE TABLE IF NOT EXISTS cotton_repo_commits (",      "suffix": ")",      "indexes": [        "CREATE INDEX IF NOT EXISTS idx_cotton_repo_commits_repo ON cotton_repo_commits (workspace_id, repo_id, authored_at DESC)",        "CREATE INDEX IF NOT EXISTS idx_cotton_repo_commits_author ON cotton_repo_commits (substr(_hlc, 20), _hlc)"      ],      "full_text": [],      "triggers": []    },    {      "name": "cotton_repo_bundles",      "columns": [        {          "name": "id",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": true,          "declaration": "\n    id TEXT PRIMARY KEY",          "position": 0        },        {          "name": "workspace_id",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    workspace_id TEXT NOT NULL",          "position": 1        },        {          "name": "repo_id",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    repo_id TEXT NOT NULL",          "position": 2        },        {          "name": "object_key",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    object_key TEXT NOT NULL",          "position": 3        },        {          "name": "kind",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    kind TEXT NOT NULL",          "position": 4        },        {          "name": "basis_sha",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    basis_sha TEXT",          "position": 5        },        {          "name": "head_sha",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    head_sha TEXT NOT NULL",          "position": 6        },        {          "name": "refs_json",          "type": "TEXT",          "default": "'{}'",          "nullable": false,          "primary_key": false,          "declaration": "\n    refs_json TEXT NOT NULL DEFAULT '{}'",          "position": 7        },        {          "name": "bytes",          "type": "INTEGER",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    bytes INTEGER NOT NULL",          "position": 8        },        {          "name": "sha256",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    sha256 TEXT NOT NULL",          "position": 9        },        {          "name": "superseded_at",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    superseded_at TEXT",          "position": 10        },        {          "name": "created_at",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    created_at TEXT NOT NULL",          "position": 11        },        {          "name": "updated_at",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    updated_at TEXT NOT NULL",          "position": 12        },        {          "name": "_hlc",          "type": "TEXT",          "default": "''",          "nullable": false,          "primary_key": false,          "declaration": "\n    _hlc TEXT NOT NULL DEFAULT ''",          "position": 13        },        {          "name": "_born",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    _born TEXT",          "position": 14        }      ],      "constraints": [        {          "declaration": "\n    UNIQUE (workspace_id, repo_id, sha256)",          "position": 15        },        {          "declaration": "\n    CHECK (kind IN ('full', 'incremental'))",          "position": 16        },        {          "declaration": "\n    CHECK ((kind = 'full') = (basis_sha IS NULL))",          "position": 17        },        {          "declaration": "\n    CHECK (bytes >= 0)",          "position": 18        },        {          "declaration": "\n    CHECK (length(sha256) = 64)",          "position": 19        },        {          "declaration": "\n    CHECK (length(trim(object_key)) > 0)",          "position": 20        },        {          "declaration": "\n    CHECK (json_type(refs_json) = 'object')",          "position": 21        },        {          "declaration": "\n    FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE",          "position": 22        },        {          "declaration": "\n    FOREIGN KEY (repo_id) REFERENCES cotton_repos(id)\n  ",          "position": 23        }      ],      "prefix": "CREATE TABLE IF NOT EXISTS cotton_repo_bundles (",      "suffix": ")",      "indexes": [        "CREATE INDEX IF NOT EXISTS idx_cotton_repo_bundles_repo ON cotton_repo_bundles (workspace_id, repo_id, created_at)",        "CREATE INDEX IF NOT EXISTS idx_cotton_repo_bundles_author ON cotton_repo_bundles (substr(_hlc, 20), _hlc)"      ],      "full_text": [],      "triggers": []    },    {      "name": "cotton_repo_clones",      "columns": [        {          "name": "id",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": true,          "declaration": "\n    id TEXT PRIMARY KEY",          "position": 0        },        {          "name": "workspace_id",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    workspace_id TEXT NOT NULL",          "position": 1        },        {          "name": "repo_id",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    repo_id TEXT NOT NULL",          "position": 2        },        {          "name": "device_id",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    device_id TEXT NOT NULL",          "position": 3        },        {          "name": "state",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    state TEXT NOT NULL",          "position": 4        },        {          "name": "sentence",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    sentence TEXT",          "position": 5        },        {          "name": "created_at",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    created_at TEXT NOT NULL",          "position": 6        },        {          "name": "updated_at",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    updated_at TEXT NOT NULL",          "position": 7        },        {          "name": "_hlc",          "type": "TEXT",          "default": "''",          "nullable": false,          "primary_key": false,          "declaration": "\n    _hlc TEXT NOT NULL DEFAULT ''",          "position": 8        },        {          "name": "_born",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    _born TEXT",          "position": 9        }      ],      "constraints": [        {          "declaration": "\n    UNIQUE (workspace_id, repo_id, device_id)",          "position": 10        },        {          "declaration": "\n    CHECK (state IN ('ok', 'forked'))",          "position": 11        },        {          "declaration": "\n    CHECK (length(trim(device_id)) > 0)",          "position": 12        },        {          "declaration": "\n    FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE",          "position": 13        },        {          "declaration": "\n    FOREIGN KEY (repo_id) REFERENCES cotton_repos(id)\n  ",          "position": 14        }      ],      "prefix": "CREATE TABLE IF NOT EXISTS cotton_repo_clones (",      "suffix": ")",      "indexes": [        "CREATE INDEX IF NOT EXISTS idx_cotton_repo_clones_repo ON cotton_repo_clones (workspace_id, repo_id, state)",        "CREATE INDEX IF NOT EXISTS idx_cotton_repo_clones_author ON cotton_repo_clones (substr(_hlc, 20), _hlc)"      ],      "full_text": [],      "triggers": []    },    {      "name": "cotton_repo_runners",      "columns": [        {          "name": "id",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": true,          "declaration": "\n    id TEXT PRIMARY KEY",          "position": 0        },        {          "name": "workspace_id",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    workspace_id TEXT NOT NULL",          "position": 1        },        {          "name": "repo_id",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    repo_id TEXT",          "position": 2        },        {          "name": "uuid",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    uuid TEXT NOT NULL",          "position": 3        },        {          "name": "name",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    name TEXT NOT NULL",          "position": 4        },        {          "name": "labels_json",          "type": "TEXT",          "default": "'[]'",          "nullable": false,          "primary_key": false,          "declaration": "\n    labels_json TEXT NOT NULL DEFAULT '[]'",          "position": 5        },        {          "name": "device_id",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    device_id TEXT",          "position": 6        },        {          "name": "credential_id",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    credential_id TEXT NOT NULL",          "position": 7        },        {          "name": "version",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    version TEXT",          "position": 8        },        {          "name": "last_seen_at",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    last_seen_at TEXT",          "position": 9        },        {          "name": "created_at",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    created_at TEXT NOT NULL",          "position": 10        },        {          "name": "updated_at",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    updated_at TEXT NOT NULL",          "position": 11        },        {          "name": "_hlc",          "type": "TEXT",          "default": "''",          "nullable": false,          "primary_key": false,          "declaration": "\n    _hlc TEXT NOT NULL DEFAULT ''",          "position": 12        },        {          "name": "_born",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    _born TEXT",          "position": 13        }      ],      "constraints": [        {          "declaration": "\n    UNIQUE (workspace_id, uuid)",          "position": 14        },        {          "declaration": "\n    CHECK (length(trim(uuid)) > 0)",          "position": 15        },        {          "declaration": "\n    CHECK (length(trim(name)) > 0)",          "position": 16        },        {          "declaration": "\n    CHECK (length(trim(credential_id)) > 0)",          "position": 17        },        {          "declaration": "\n    CHECK (json_type(labels_json) = 'array')",          "position": 18        },        {          "declaration": "\n    CHECK (repo_id IS NULL OR length(repo_id) > 0)",          "position": 19        },        {          "declaration": "\n    CHECK (device_id IS NULL OR length(device_id) > 0)",          "position": 20        },        {          "declaration": "\n    FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE",          "position": 21        },        {          "declaration": "\n    FOREIGN KEY (repo_id) REFERENCES cotton_repos(id)\n  ",          "position": 22        }      ],      "prefix": "CREATE TABLE IF NOT EXISTS cotton_repo_runners (",      "suffix": ")",      "indexes": [        "CREATE INDEX IF NOT EXISTS idx_cotton_repo_runners_workspace ON cotton_repo_runners (workspace_id, last_seen_at DESC)",        "CREATE INDEX IF NOT EXISTS idx_cotton_repo_runners_author ON cotton_repo_runners (substr(_hlc, 20), _hlc)"      ],      "full_text": [],      "triggers": []    },    {      "name": "cotton_repo_jobs",      "columns": [        {          "name": "id",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": true,          "declaration": "\n    id TEXT PRIMARY KEY",          "position": 0        },        {          "name": "workspace_id",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    workspace_id TEXT NOT NULL",          "position": 1        },        {          "name": "run_id",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    run_id TEXT NOT NULL",          "position": 2        },        {          "name": "index_in_run",          "type": "INTEGER",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    index_in_run INTEGER NOT NULL",          "position": 3        },        {          "name": "task_id",          "type": "INTEGER",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    task_id INTEGER NOT NULL",          "position": 4        },        {          "name": "name",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    name TEXT NOT NULL",          "position": 5        },        {          "name": "runs_on",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    runs_on TEXT NOT NULL",          "position": 6        },        {          "name": "needs_json",          "type": "TEXT",          "default": "'[]'",          "nullable": false,          "primary_key": false,          "declaration": "\n    needs_json TEXT NOT NULL DEFAULT '[]'",          "position": 7        },        {          "name": "status",          "type": "TEXT",          "default": "'queued'",          "nullable": false,          "primary_key": false,          "declaration": "\n    status TEXT NOT NULL DEFAULT 'queued'",          "position": 8        },        {          "name": "conclusion",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    conclusion TEXT",          "position": 9        },        {          "name": "runner_uuid",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    runner_uuid TEXT",          "position": 10        },        {          "name": "timeout_minutes",          "type": "INTEGER",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    timeout_minutes INTEGER",          "position": 11        },        {          "name": "outputs_json",          "type": "TEXT",          "default": "'{}'",          "nullable": false,          "primary_key": false,          "declaration": "\n    outputs_json TEXT NOT NULL DEFAULT '{}'",          "position": 12        },        {          "name": "steps_json",          "type": "TEXT",          "default": "'[]'",          "nullable": false,          "primary_key": false,          "declaration": "\n    steps_json TEXT NOT NULL DEFAULT '[]'",          "position": 13        },        {          "name": "summary",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    summary TEXT",          "position": 14        },        {          "name": "log_lines",          "type": "INTEGER",          "default": "0",          "nullable": false,          "primary_key": false,          "declaration": "\n    log_lines INTEGER NOT NULL DEFAULT 0",          "position": 15        },        {          "name": "log_ack",          "type": "INTEGER",          "default": "0",          "nullable": false,          "primary_key": false,          "declaration": "\n    log_ack INTEGER NOT NULL DEFAULT 0",          "position": 16        },        {          "name": "log_key",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    log_key TEXT",          "position": 17        },        {          "name": "cancel_requested",          "type": "INTEGER",          "default": "0",          "nullable": false,          "primary_key": false,          "declaration": "\n    cancel_requested INTEGER NOT NULL DEFAULT 0",          "position": 18        },        {          "name": "requeues",          "type": "INTEGER",          "default": "0",          "nullable": false,          "primary_key": false,          "declaration": "\n    requeues INTEGER NOT NULL DEFAULT 0",          "position": 19        },        {          "name": "started_at",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    started_at TEXT",          "position": 20        },        {          "name": "finished_at",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    finished_at TEXT",          "position": 21        },        {          "name": "created_at",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    created_at TEXT NOT NULL",          "position": 22        },        {          "name": "updated_at",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    updated_at TEXT NOT NULL",          "position": 23        },        {          "name": "_hlc",          "type": "TEXT",          "default": "''",          "nullable": false,          "primary_key": false,          "declaration": "\n    _hlc TEXT NOT NULL DEFAULT ''",          "position": 24        },        {          "name": "_born",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    _born TEXT",          "position": 25        },        {          "name": "token_digest",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    token_digest TEXT",          "position": 26        }      ],      "constraints": [        {          "declaration": "\n    UNIQUE (workspace_id, run_id, index_in_run)",          "position": 27        },        {          "declaration": "\n    UNIQUE (workspace_id, task_id)",          "position": 28        },        {          "declaration": "\n    CHECK (index_in_run > 0)",          "position": 29        },        {          "declaration": "\n    CHECK (task_id > 0)",          "position": 30        },        {          "declaration": "\n    CHECK (length(trim(name)) > 0)",          "position": 31        },        {          "declaration": "\n    CHECK (length(trim(runs_on)) > 0)",          "position": 32        },        {          "declaration": "\n    CHECK (json_type(needs_json) = 'array')",          "position": 33        },        {          "declaration": "\n    CHECK (json_type(outputs_json) = 'object')",          "position": 34        },        {          "declaration": "\n    CHECK (json_type(steps_json) = 'array')",          "position": 35        },        {          "declaration": "\n    CHECK (status IN ('queued', 'in_progress', 'completed'))",          "position": 36        },        {          "declaration": "\n    CHECK (conclusion IS NULL OR conclusion IN ('success', 'failure', 'cancelled', 'skipped', 'timed_out'))",          "position": 37        },        {          "declaration": "\n    CHECK (status <> 'completed' OR conclusion IS NOT NULL)",          "position": 38        },        {          "declaration": "\n    CHECK (status = 'completed' OR conclusion IS NULL)",          "position": 39        },        {          "declaration": "\n    CHECK (timeout_minutes IS NULL OR timeout_minutes > 0)",          "position": 40        },        {          "declaration": "\n    CHECK (log_lines >= 0)",          "position": 41        },        {          "declaration": "\n    CHECK (log_ack >= 0)",          "position": 42        },        {          "declaration": "\n    CHECK (log_ack <= log_lines)",          "position": 43        },        {          "declaration": "\n    CHECK (cancel_requested IN (0, 1))",          "position": 44        },        {          "declaration": "\n    CHECK (requeues >= 0)",          "position": 45        },        {          "declaration": "\n    CHECK (summary IS NULL OR length(summary) <= 65536)",          "position": 46        },        {          "declaration": "\n    FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE",          "position": 47        },        {          "declaration": "\n    FOREIGN KEY (run_id) REFERENCES cotton_repo_runs(id)\n  ",          "position": 48        }      ],      "prefix": "CREATE TABLE IF NOT EXISTS cotton_repo_jobs (",      "suffix": ")",      "indexes": [        "CREATE INDEX IF NOT EXISTS idx_cotton_repo_jobs_run ON cotton_repo_jobs (workspace_id, run_id, index_in_run)",        "CREATE INDEX IF NOT EXISTS idx_cotton_repo_jobs_run_id ON cotton_repo_jobs (run_id)",        "CREATE INDEX IF NOT EXISTS idx_cotton_repo_jobs_queue ON cotton_repo_jobs (workspace_id, status, created_at)",        "CREATE INDEX IF NOT EXISTS idx_cotton_repo_jobs_author ON cotton_repo_jobs (substr(_hlc, 20), _hlc)"      ],      "full_text": [],      "triggers": []    },    {      "name": "cotton_repo_merge_queue",      "columns": [        {          "name": "id",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": true,          "declaration": "\n    id TEXT PRIMARY KEY",          "position": 0        },        {          "name": "workspace_id",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    workspace_id TEXT NOT NULL",          "position": 1        },        {          "name": "repo_id",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    repo_id TEXT NOT NULL",          "position": 2        },        {          "name": "pull_id",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    pull_id TEXT NOT NULL",          "position": 3        },        {          "name": "pull_number",          "type": "INTEGER",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    pull_number INTEGER NOT NULL",          "position": 4        },        {          "name": "base_ref",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    base_ref TEXT NOT NULL",          "position": 5        },        {          "name": "head_sha",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    head_sha TEXT",          "position": 6        },        {          "name": "state",          "type": "TEXT",          "default": "'queued'",          "nullable": false,          "primary_key": false,          "declaration": "\n    state TEXT NOT NULL DEFAULT 'queued'",          "position": 7        },        {          "name": "failures",          "type": "INTEGER",          "default": "0",          "nullable": false,          "primary_key": false,          "declaration": "\n    failures INTEGER NOT NULL DEFAULT 0",          "position": 8        },        {          "name": "reason",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    reason TEXT",          "position": 9        },        {          "name": "train_number",          "type": "INTEGER",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    train_number INTEGER",          "position": 10        },        {          "name": "train_base_sha",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    train_base_sha TEXT",          "position": 11        },        {          "name": "train_tip_sha",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    train_tip_sha TEXT",          "position": 12        },        {          "name": "train_run_id",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    train_run_id TEXT",          "position": 13        },        {          "name": "landed_sha",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    landed_sha TEXT",          "position": 14        },        {          "name": "enqueued_at",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    enqueued_at TEXT NOT NULL",          "position": 15        },        {          "name": "finished_at",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    finished_at TEXT",          "position": 16        },        {          "name": "created_at",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    created_at TEXT NOT NULL",          "position": 17        },        {          "name": "updated_at",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    updated_at TEXT NOT NULL",          "position": 18        },        {          "name": "_hlc",          "type": "TEXT",          "default": "''",          "nullable": false,          "primary_key": false,          "declaration": "\n    _hlc TEXT NOT NULL DEFAULT ''",          "position": 19        },        {          "name": "_born",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    _born TEXT",          "position": 20        },        {          "name": "train_squash_sha",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    train_squash_sha TEXT",          "position": 21        }      ],      "constraints": [        {          "declaration": "\n    CHECK (length(repo_id) > 0)",          "position": 22        },        {          "declaration": "\n    CHECK (length(pull_id) > 0)",          "position": 23        },        {          "declaration": "\n    CHECK (pull_number > 0)",          "position": 24        },        {          "declaration": "\n    CHECK (length(base_ref) > 0)",          "position": 25        },        {          "declaration": "\n    CHECK (state IN ('queued', 'checking', 'landed', 'ejected'))",          "position": 26        },        {          "declaration": "\n    CHECK (failures >= 0)",          "position": 27        },        {          "declaration": "\n    CHECK (reason IS NULL OR length(reason) <= 2048)",          "position": 28        },        {          "declaration": "\n    CHECK (train_number IS NULL OR train_number > 0)",          "position": 29        },        {          "declaration": "\n    FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n  ",          "position": 30        }      ],      "prefix": "CREATE TABLE IF NOT EXISTS cotton_repo_merge_queue (",      "suffix": ")",      "indexes": [        "CREATE INDEX IF NOT EXISTS idx_cotton_repo_merge_queue_author ON cotton_repo_merge_queue (substr(_hlc, 20), _hlc)",        "CREATE INDEX IF NOT EXISTS idx_cotton_repo_merge_queue_repo ON cotton_repo_merge_queue (workspace_id, repo_id, state, enqueued_at)"      ],      "full_text": [],      "triggers": []    }  ],  "delete": false}