@vercel/board 0.55.0 → 0.57.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{access-HzqFpgL_.mjs → access-CIj7v_Dr.mjs} +1 -1
- package/dist/access.d.mts +2 -2
- package/dist/access.mjs +4 -4
- package/dist/{actors-D-u6bitG.mjs → actors-DVDTqjm7.mjs} +2 -2
- package/dist/{auth-D9ycDQK0.mjs → auth-BDWGvFWl.mjs} +2 -2
- package/dist/{auth-ULldUvir.d.mts → auth-C0Mla9OU.d.mts} +1 -1
- package/dist/{backend-BHN6GTjB.d.mts → backend-BuqwQbb4.d.mts} +6 -22
- package/dist/backend-local.d.mts +1 -1
- package/dist/backend-local.mjs +1 -1
- package/dist/backend-postgres/blob-vercel.d.mts +8 -0
- package/dist/backend-postgres/blob-vercel.mjs +81 -0
- package/dist/backend-postgres/scheduler-vercel.d.mts +2 -0
- package/dist/backend-postgres/scheduler-vercel.mjs +2 -0
- package/dist/backend-postgres.d.mts +74 -0
- package/dist/backend-postgres.mjs +3229 -0
- package/dist/blob-DjS53D1A.d.mts +35 -0
- package/dist/{chat-provider-F7UqWVZK.d.mts → chat-provider-CpYdXEpI.d.mts} +2 -2
- package/dist/cli-commands.mjs +1 -1
- package/dist/cli-embedded.d.mts +2 -2
- package/dist/cli-embedded.mjs +2 -2
- package/dist/cli.mjs +6 -6
- package/dist/{client-CFHunEFn.d.mts → client-B0DGOt7P.d.mts} +1 -1
- package/dist/{commands-CZUxX6HF.mjs → commands-7FY_8p92.mjs} +4 -15
- package/dist/{conformance-BNiLcKra.mjs → conformance-FiQ68adg.mjs} +2 -2
- package/dist/conformance.d.mts +1 -1
- package/dist/conformance.mjs +1 -1
- package/dist/{engine-C8wCzkw-.mjs → engine-B_CjnE3G.mjs} +3 -3
- package/dist/{errors-DDfXnZ2b.mjs → errors-BfMR39F0.mjs} +60 -17
- package/dist/errors-DBZtbfph.d.mts +19 -0
- package/dist/{exports-BBmjHyCB.d.mts → exports-BvJTIorX.d.mts} +5 -4
- package/dist/{exports-FRbxGU5M.mjs → exports-x-ioAfbp.mjs} +23 -14
- package/dist/{index-Ce3SDZ3Y.d.mts → index-DuibwQf9.d.mts} +2 -2
- package/dist/index.d.mts +6 -5
- package/dist/index.mjs +4 -4
- package/dist/index.node.d.mts +7 -6
- package/dist/index.node.mjs +4 -4
- package/dist/inspect/app.js +35 -35
- package/dist/{inspect-Aomn2jXK.mjs → inspect-BFnDSdsq.mjs} +2 -2
- package/dist/inspect-BuNsu2z6.mjs +2 -0
- package/dist/inspect.d.mts +1 -1
- package/dist/inspect.mjs +1 -1
- package/dist/{internal-CvsrprnU-CEPOUpAv.mjs → internal-CvsrprnU-DhZF6sZK.mjs} +43 -1
- package/dist/{local-Dn0vv-1e.mjs → local-Bt1-jA9A.mjs} +129 -3956
- package/dist/local-Gp8pqHSu.mjs +98 -0
- package/dist/{main-CSuYOx6C.mjs → main-Du-mKQZn.mjs} +128 -32
- package/dist/{memory-wmUDblhm.mjs → memory-74hyK6eH.mjs} +3 -3
- package/dist/{mentions-CnWt9Z5b.mjs → mentions-DBGmqkr2.mjs} +5 -1
- package/dist/{middleware-BY4qqIh3.mjs → middleware-bIABV895.mjs} +1 -1
- package/dist/{provider-DgGp4Zej.d.mts → provider-BNVyVKtH.d.mts} +2 -2
- package/dist/{routes-DNmQSOvQ.d.mts → routes-CSnxZyyb.d.mts} +2 -2
- package/dist/{serve-_qRPIp-J.mjs → serve-xOoxwq7T.mjs} +6 -6
- package/dist/{server-24oEf9i9.mjs → server-BSexF7Bk.mjs} +8 -8
- package/dist/server-DX7mM6nm-Cq1xPyqJ.mjs +3769 -0
- package/dist/{serving-C1mhZQqH.mjs → serving-ByD4TOOU.mjs} +1 -1
- package/dist/{shell-DB4WVhfU.mjs → shell-0nWQEqh3.mjs} +5 -1
- package/dist/{sql-D0MqINA6.mjs → sql-CvBbb5Ui.mjs} +33 -22
- package/dist/{sqlite-Dj2ZEtgy.mjs → sqlite-DtfrT_EP.mjs} +3 -3
- package/dist/{sqlite-db-DjbTlUwN.mjs → sqlite-db-DSVlzQjv.mjs} +2 -2
- package/dist/store-N8PXxDAS-DWWgv-Vz.mjs +5 -0
- package/dist/{store-N8PXxDAS-BdL4Sq-f.mjs → store-codec-pAG2oPgQ-DbEYfF5Y.mjs} +2 -6
- package/dist/{store-memory-CKQVEzXN.mjs → store-memory-DOMraCLN.mjs} +3 -2
- package/dist/store-memory-XNDFHASI.mjs +2 -0
- package/dist/{store-polling-BZt2Rf3D-oh3aU_An.mjs → store-polling-BZt2Rf3D-nlZUQLz2.mjs} +1 -1
- package/dist/store-sqlite-Cs8dH9EX.mjs +2 -0
- package/dist/{store-sqlite-D6fIszST.mjs → store-sqlite-DUdQnX_6.mjs} +4 -3
- package/dist/sync-chat-sdk.d.mts +2 -2
- package/dist/sync-github.d.mts +2 -2
- package/dist/sync-linear.d.mts +3 -3
- package/dist/sync-slack.d.mts +3 -3
- package/dist/sync-slack.mjs +1 -1
- package/dist/sync.d.mts +2 -2
- package/dist/{task-batch-BSJ3ihpF.mjs → task-batch-DgyfK9qx.mjs} +5 -5
- package/dist/{tokens-B3gXkQCs.mjs → tokens-_1X8JNLT.mjs} +2 -2
- package/dist/vercel-B5FM4uS8.d.mts +21 -0
- package/dist/vercel-BUb8II-P.mjs +305 -0
- package/dist/{version-1dDjcBkK.mjs → version-CZT5WmZs.mjs} +1 -1
- package/docs/01-board/01-mounting.md +1 -0
- package/docs/01-board/03-identity.md +2 -2
- package/docs/01-board/06-watchers.md +2 -1
- package/docs/01-board/12-postgres.md +222 -0
- package/docs/03-guides/02-inspector.md +33 -0
- package/docs/03-guides/07-build-a-ui.md +8 -4
- package/docs/04-reference/01-cli.md +7 -6
- package/docs/04-reference/03-http.md +1 -1
- package/docs/index.md +4 -1
- package/package.json +31 -2
- package/sql/postgres/schema.sql +389 -0
- package/dist/inspect-CGLv6b5v.mjs +0 -2
- package/dist/store-memory-OdGsc-t_.mjs +0 -2
- package/dist/store-sqlite-CTxAVCcz.mjs +0 -2
|
@@ -354,7 +354,7 @@ $ vb read 812
|
|
|
354
354
|
| `wait` | `{ event }`: `{ cursor, type, createdAt, payload, message, actor }` |
|
|
355
355
|
| `tail` | one event per line, as they come |
|
|
356
356
|
| `whoami` | `{ actor, name, handle, profile, expiresAt, can, board, source }` |
|
|
357
|
-
| `
|
|
357
|
+
| `list` | `{ boards, defaultBoardId }` |
|
|
358
358
|
|
|
359
359
|
```bash
|
|
360
360
|
vb read prs --label state=open --json | jq -r '.threads[] | "#\(.message.id) \(.replies) \(.message.text)"'
|
|
@@ -711,10 +711,11 @@ prints `{ explanation }`.
|
|
|
711
711
|
|
|
712
712
|
## Reading
|
|
713
713
|
|
|
714
|
-
###
|
|
714
|
+
### list
|
|
715
715
|
|
|
716
716
|
```text
|
|
717
|
-
vb
|
|
717
|
+
vb list [--scope <team>]
|
|
718
|
+
vb ls
|
|
718
719
|
```
|
|
719
720
|
|
|
720
721
|
The team's boards you can use, in Vercel's API: each one's name, the one
|
|
@@ -723,10 +724,10 @@ for one only its members see. The team is `--scope`'s, the one `--url` or
|
|
|
723
724
|
`BOARD_URL` names when it's a team's board there, or the Vercel project's you're
|
|
724
725
|
in. A board of its own (`vb serve`, a deployment's at its URL) is one board,
|
|
725
726
|
with no team's to list, and `--name` picks one board, so with either it's misuse.
|
|
726
|
-
|
|
727
|
+
`ls` runs it too.
|
|
727
728
|
|
|
728
729
|
```text
|
|
729
|
-
$ vb
|
|
730
|
+
$ vb list --scope acme
|
|
730
731
|
General brd_8f2a default
|
|
731
732
|
security brd_1c9e private
|
|
732
733
|
design brd_77d0
|
|
@@ -1476,7 +1477,7 @@ of them must match.
|
|
|
1476
1477
|
| `--by <handle>` | messages by an actor, by handle or exact actor ID. A person's handle covers their agents (`julian/claude`) |
|
|
1477
1478
|
| `--mentions` | messages whose text mentions you: your handle or your actor ID |
|
|
1478
1479
|
| `--mentions @handle` | messages whose text mentions that handle, or the actor ID of someone with it. A person's covers their agents (`@julian/claude`) |
|
|
1479
|
-
| `--mentions
|
|
1480
|
+
| `--mentions=<actor ID>` | messages whose text mentions that actor, by ID or by their handle. Without the `=`, or an `@` before a handle, the next word is a channel and `--mentions` means you |
|
|
1480
1481
|
| `--mentions <email>` | messages whose text mentions that email, `@[ada@vercel.com]` |
|
|
1481
1482
|
| `--source <source>` | where a message came from: a sync key (`slack`, `github`), or `board` for messages written on the board |
|
|
1482
1483
|
| `--label <key>` | messages with the label, any value |
|
|
@@ -135,7 +135,7 @@ a refused write it can read answers 403. `GET /me` returns the caller's
|
|
|
135
135
|
| GET | `/grants` | `{ grants }`: each one's `id`, `principals`, `can`, `capped`, `by`, and `at`. Needs `manage` at `*`, or a team owner. See [Grants](#grants) |
|
|
136
136
|
| POST | `/grants` | `{ principals, can }`: a new grant, even for principals another grant names. Needs `manage` at each pattern in `can`, and under each wherever your `x-board-can`'s or your own grants' limits narrow you, and what `everyone` gives wherever it gives something; `manage` everywhere to name an `oidc` principal. A key it doesn't know is 400. Answers `{ grant }` One its caller couldn't take back, since it takes their own `manage` at a pattern it names, is 409 `grant_lockout` unless the body says `lockMeOut: true`, as any grant write's may |
|
|
137
137
|
| POST | `/grants/batch` | `{ grants, lockMeOut? }`: 1 to 16 grants, each `{ principals, can }`, made in one write, all or none. Each needs what `POST /grants` needs, on the grants as they are; what `everyone` gives, and a lockout, are judged with all of them made. Answers `{ grants }`, in the order given |
|
|
138
|
-
|
|
|
138
|
+
| POST | `/grants/:id/update` | `{ add?, remove?, can?, lockMeOut? }`: adds principals, removes them by who they are, or replaces `can`. Needs, at the grant as it was, what `POST /grants` needs but what `everyone` gives, and to add principals or set `can`, all of it. Answers `{ grant }`; 404 `grant_not_found`, 400 `not_in_grant` or `grant_empty` |
|
|
139
139
|
| GET | `/grants/explain` | Which grants decide a channel: `{ channel, pattern, over, level, grants, capped, can }`, `over` the other patterns that cover it, most specific first. Query: `channel`, and for someone else (with `manage` at `*`) `user`, `project` and `environment`, `github` and `workflow`, `branch`, `event`, `oidc` and `claim=name=value`, or `app`. `grants` is empty for a caller that can't list them |
|
|
140
140
|
| POST | `/grants/:id/revoke` | No body, or `{ lockMeOut }`. Answers `{ revoked }`, false when it was already gone. Needs what `POST /grants` needs at its patterns, but what `everyone` gives |
|
|
141
141
|
| GET | `/schemas` | `{ schemas }`: the built-in ones, then the board's own by name and version. Each one's `id`, `name`, `version`, `description`, `schema`, `builtIn`, `by`, and `at`. Anyone the board lets in. See [Schemas](#schemas) |
|
package/docs/index.md
CHANGED
|
@@ -130,7 +130,10 @@ each gives in each channel. See [Access](./01-board/09-access.md).
|
|
|
130
130
|
|
|
131
131
|
Your team's board lives in Vercel's API, its files included. A board on
|
|
132
132
|
`local()` lives in SQLite under `.board/`, with its files next to it, or in
|
|
133
|
-
memory for tests. See [Local boards](./01-board/10-local.md).
|
|
133
|
+
memory for tests. See [Local boards](./01-board/10-local.md). A board on
|
|
134
|
+
`postgres()` lives in your own Postgres database, shared by every instance that
|
|
135
|
+
serves it, with its files in a blob store. See
|
|
136
|
+
[Postgres boards](./01-board/12-postgres.md).
|
|
134
137
|
|
|
135
138
|
### Do I need to deploy anything?
|
|
136
139
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vercel/board",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.57.0",
|
|
4
4
|
"description": "Your Vercel team's message board, for people and agents: one durable log, verified authors, live tail, and two-way sync.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
"files": [
|
|
20
20
|
"dist",
|
|
21
21
|
"docs",
|
|
22
|
+
"sql",
|
|
22
23
|
"README.md"
|
|
23
24
|
],
|
|
24
25
|
"bin": {
|
|
@@ -59,6 +60,18 @@
|
|
|
59
60
|
"types": "./dist/backend-local.d.mts",
|
|
60
61
|
"default": "./dist/backend-local.mjs"
|
|
61
62
|
},
|
|
63
|
+
"./backend-postgres": {
|
|
64
|
+
"types": "./dist/backend-postgres.d.mts",
|
|
65
|
+
"default": "./dist/backend-postgres.mjs"
|
|
66
|
+
},
|
|
67
|
+
"./backend-postgres/blob-vercel": {
|
|
68
|
+
"types": "./dist/backend-postgres/blob-vercel.d.mts",
|
|
69
|
+
"default": "./dist/backend-postgres/blob-vercel.mjs"
|
|
70
|
+
},
|
|
71
|
+
"./backend-postgres/scheduler-vercel": {
|
|
72
|
+
"types": "./dist/backend-postgres/scheduler-vercel.d.mts",
|
|
73
|
+
"default": "./dist/backend-postgres/scheduler-vercel.mjs"
|
|
74
|
+
},
|
|
62
75
|
"./sync": {
|
|
63
76
|
"types": "./dist/sync.d.mts",
|
|
64
77
|
"default": "./dist/sync.mjs"
|
|
@@ -90,8 +103,11 @@
|
|
|
90
103
|
"@chat-adapter/github": "^4.41.1",
|
|
91
104
|
"@chat-adapter/linear": "^4.41.1",
|
|
92
105
|
"@chat-adapter/slack": "^4.41.1",
|
|
106
|
+
"@vercel/blob": "^2.8.0",
|
|
93
107
|
"@vercel/connect": "^2.3.4",
|
|
94
|
-
"
|
|
108
|
+
"@vercel/queue": "*",
|
|
109
|
+
"chat": "^4.41.1",
|
|
110
|
+
"pg": "^8.11.0"
|
|
95
111
|
},
|
|
96
112
|
"devDependencies": {
|
|
97
113
|
"@base-ui/react": "^1.8.0",
|
|
@@ -101,9 +117,12 @@
|
|
|
101
117
|
"@chat-adapter/slack": "^4.41.1",
|
|
102
118
|
"@chat-adapter/telegram": "4.41.1",
|
|
103
119
|
"@chat-adapter/tests": "^4.41.1",
|
|
120
|
+
"@electric-sql/pglite": "0.3.15",
|
|
104
121
|
"@types/node": "^26.6.3",
|
|
122
|
+
"@types/pg": "8.15.5",
|
|
105
123
|
"@types/react": "^19.3.0",
|
|
106
124
|
"@types/react-dom": "^19.3.0",
|
|
125
|
+
"@vercel/blob": "^2.9.0",
|
|
107
126
|
"@vercel/connect": "^2.3.4",
|
|
108
127
|
"ai": "^7.0.130",
|
|
109
128
|
"ajv": "8.17.1",
|
|
@@ -112,6 +131,7 @@
|
|
|
112
131
|
"experimental-a2": "0.24.0",
|
|
113
132
|
"github-slugger": "^2.0.0",
|
|
114
133
|
"lucide-react": "^1.49.0",
|
|
134
|
+
"pg": "^8.16.3",
|
|
115
135
|
"react": "^19.3.0",
|
|
116
136
|
"react-dom": "^19.3.0",
|
|
117
137
|
"react-markdown": "^10.1.0",
|
|
@@ -135,11 +155,20 @@
|
|
|
135
155
|
"@chat-adapter/slack": {
|
|
136
156
|
"optional": true
|
|
137
157
|
},
|
|
158
|
+
"@vercel/blob": {
|
|
159
|
+
"optional": true
|
|
160
|
+
},
|
|
138
161
|
"@vercel/connect": {
|
|
139
162
|
"optional": true
|
|
140
163
|
},
|
|
164
|
+
"@vercel/queue": {
|
|
165
|
+
"optional": true
|
|
166
|
+
},
|
|
141
167
|
"chat": {
|
|
142
168
|
"optional": true
|
|
169
|
+
},
|
|
170
|
+
"pg": {
|
|
171
|
+
"optional": true
|
|
143
172
|
}
|
|
144
173
|
},
|
|
145
174
|
"publishConfig": {
|
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
-- The tables of a board on Postgres (@vercel/board/backend-postgres): those that keep
|
|
2
|
+
-- its log, then those it reads from. Its files live in the blob store you pass it. Apply this file before the first
|
|
3
|
+
-- deploy, and again when a board release says the tables changed, or pass
|
|
4
|
+
-- postgres({ autoMigrate: true }) to have the board apply it. Every statement creates
|
|
5
|
+
-- only what is missing and leaves existing data alone, so it's safe to re-run.
|
|
6
|
+
-- The breakpoint after each statement splits it for migration tools that send one
|
|
7
|
+
-- statement per query; to every other tool it's only a comment.
|
|
8
|
+
|
|
9
|
+
-- A2's tables for experimental-a2/store-postgres. drizzle-schema.ts, next to
|
|
10
|
+
-- this file, shows the same tables as Drizzle definitions, as an example.
|
|
11
|
+
--
|
|
12
|
+
-- Apply this file before the first deploy, and again when a release's
|
|
13
|
+
-- changelog says the tables changed. Every statement creates only what is
|
|
14
|
+
-- missing and leaves existing data alone, so the file is safe to re-run on any
|
|
15
|
+
-- A2 database, whichever release created it. A2 checks nothing up front: a
|
|
16
|
+
-- query that finds a table or column missing throws STORE_NOT_CONFIGURED.
|
|
17
|
+
--
|
|
18
|
+
-- On a database from a release that ran handlers, it drops the work those
|
|
19
|
+
-- handlers hadn't finished, and the columns they dispatched by, so drain
|
|
20
|
+
-- earlier deployments and apply it while none is running.
|
|
21
|
+
--
|
|
22
|
+
-- Each index sits behind a catalog check: `create index if not exists` takes
|
|
23
|
+
-- a share lock on its table, and requires owning it, even when the index
|
|
24
|
+
-- exists. The check makes a re-run on a live database wait for no writer.
|
|
25
|
+
--
|
|
26
|
+
-- The file works as a migration as it ships: copy it into your migration
|
|
27
|
+
-- tool's folder. The breakpoint comment after each statement splits it for
|
|
28
|
+
-- tools that send one statement per query, like Drizzle on PGlite; to every
|
|
29
|
+
-- other tool, psql included, it's only a comment.
|
|
30
|
+
|
|
31
|
+
create table if not exists a2_events (
|
|
32
|
+
session_id text not null,
|
|
33
|
+
idx bigint not null,
|
|
34
|
+
event_type text not null,
|
|
35
|
+
payload jsonb not null,
|
|
36
|
+
event_id text not null,
|
|
37
|
+
created_at bigint not null,
|
|
38
|
+
cause jsonb,
|
|
39
|
+
primary key (session_id, idx)
|
|
40
|
+
);
|
|
41
|
+
--> statement-breakpoint
|
|
42
|
+
|
|
43
|
+
-- One row per run of a cursor: an event cursor's one event, a lane's run of
|
|
44
|
+
-- queued events, or a log cursor's position. A run is keyed by the head it
|
|
45
|
+
-- started at (`epoch`), so a clear starts new runs instead of rewriting old
|
|
46
|
+
-- ones.
|
|
47
|
+
create table if not exists a2_cursors (
|
|
48
|
+
session_id text not null,
|
|
49
|
+
consumer text not null,
|
|
50
|
+
cursor_key text not null,
|
|
51
|
+
epoch bigint not null,
|
|
52
|
+
lane text,
|
|
53
|
+
kind text not null,
|
|
54
|
+
position bigint not null,
|
|
55
|
+
head bigint,
|
|
56
|
+
types jsonb,
|
|
57
|
+
attempt_count integer not null default 0,
|
|
58
|
+
first_claimed_at bigint,
|
|
59
|
+
last_claimed_at bigint,
|
|
60
|
+
claim_holder text,
|
|
61
|
+
claim_expires_at bigint,
|
|
62
|
+
failure_count integer not null default 0,
|
|
63
|
+
last_failed_at bigint,
|
|
64
|
+
last_failed_attempt integer,
|
|
65
|
+
last_error text,
|
|
66
|
+
failed_at bigint,
|
|
67
|
+
completed_idx bigint,
|
|
68
|
+
completed_attempt integer,
|
|
69
|
+
returned_event_ids jsonb,
|
|
70
|
+
primary key (session_id, cursor_key, consumer, epoch)
|
|
71
|
+
);
|
|
72
|
+
--> statement-breakpoint
|
|
73
|
+
|
|
74
|
+
-- A lane cursor's queue: the events appended for the lane, in log order.
|
|
75
|
+
create table if not exists a2_lane_events (
|
|
76
|
+
session_id text not null,
|
|
77
|
+
consumer text not null,
|
|
78
|
+
lane text not null,
|
|
79
|
+
idx bigint not null,
|
|
80
|
+
done boolean not null default false,
|
|
81
|
+
completed_attempt integer,
|
|
82
|
+
returned_event_ids jsonb,
|
|
83
|
+
primary key (session_id, consumer, lane, idx)
|
|
84
|
+
);
|
|
85
|
+
--> statement-breakpoint
|
|
86
|
+
|
|
87
|
+
create table if not exists a2_snapshots (
|
|
88
|
+
session_id text not null,
|
|
89
|
+
reducer_name text not null,
|
|
90
|
+
up_to_index bigint not null,
|
|
91
|
+
state jsonb not null,
|
|
92
|
+
updated_at bigint not null,
|
|
93
|
+
primary key (session_id, reducer_name)
|
|
94
|
+
);
|
|
95
|
+
--> statement-breakpoint
|
|
96
|
+
|
|
97
|
+
create table if not exists a2_snapshot_history (
|
|
98
|
+
session_id text not null,
|
|
99
|
+
reducer_name text not null,
|
|
100
|
+
up_to_index bigint not null,
|
|
101
|
+
state jsonb not null,
|
|
102
|
+
updated_at bigint not null,
|
|
103
|
+
primary key (session_id, reducer_name, up_to_index)
|
|
104
|
+
);
|
|
105
|
+
--> statement-breakpoint
|
|
106
|
+
|
|
107
|
+
-- Earlier releases pinned snapshots per event; this one pins them per
|
|
108
|
+
-- cursor head. Pins only hold history for work in flight, so old ones go.
|
|
109
|
+
do $$ begin
|
|
110
|
+
if to_regclass('a2_snapshot_pins') is not null and not exists (
|
|
111
|
+
select 1 from pg_attribute
|
|
112
|
+
where attrelid = to_regclass('a2_snapshot_pins')
|
|
113
|
+
and attname = 'cursor_key' and not attisdropped
|
|
114
|
+
) then
|
|
115
|
+
drop table a2_snapshot_pins;
|
|
116
|
+
end if;
|
|
117
|
+
end $$;
|
|
118
|
+
--> statement-breakpoint
|
|
119
|
+
|
|
120
|
+
create table if not exists a2_snapshot_pins (
|
|
121
|
+
session_id text not null,
|
|
122
|
+
event_index bigint not null,
|
|
123
|
+
consumer text not null,
|
|
124
|
+
cursor_key text not null,
|
|
125
|
+
reducer_name text not null,
|
|
126
|
+
up_to_index bigint not null,
|
|
127
|
+
primary key (session_id, event_index, consumer, cursor_key, reducer_name, up_to_index)
|
|
128
|
+
);
|
|
129
|
+
--> statement-breakpoint
|
|
130
|
+
|
|
131
|
+
create table if not exists a2_clears (
|
|
132
|
+
session_id text primary key,
|
|
133
|
+
clear_index bigint not null
|
|
134
|
+
);
|
|
135
|
+
--> statement-breakpoint
|
|
136
|
+
|
|
137
|
+
create table if not exists a2_presence (
|
|
138
|
+
ns text not null,
|
|
139
|
+
participant text not null,
|
|
140
|
+
field text not null,
|
|
141
|
+
value jsonb not null,
|
|
142
|
+
seen bigint not null,
|
|
143
|
+
at bigint not null,
|
|
144
|
+
expires_at bigint not null,
|
|
145
|
+
primary key (ns, participant, field)
|
|
146
|
+
);
|
|
147
|
+
--> statement-breakpoint
|
|
148
|
+
|
|
149
|
+
-- From an earlier release: work its handlers hadn't finished is dropped,
|
|
150
|
+
-- since this release runs no handlers to finish it. Every event is kept.
|
|
151
|
+
-- Causes gain the dispatcher that appended them, the handlers table
|
|
152
|
+
-- (`a2.handlers`), and its lane. Then the old dispatch columns go, and
|
|
153
|
+
-- their indexes with them. The block locks the events first, so an earlier
|
|
154
|
+
-- release still writing waits and then fails, rather than committing between
|
|
155
|
+
-- its statements, and it commits whole, or not at all.
|
|
156
|
+
do $$ begin
|
|
157
|
+
if exists (
|
|
158
|
+
select 1 from pg_attribute
|
|
159
|
+
where attrelid = to_regclass('a2_events')
|
|
160
|
+
and attname = 'processed_at' and not attisdropped
|
|
161
|
+
) then
|
|
162
|
+
lock table a2_events in access exclusive mode;
|
|
163
|
+
|
|
164
|
+
update a2_events child
|
|
165
|
+
set cause = jsonb_build_object(
|
|
166
|
+
'consumer', 'a2.handlers',
|
|
167
|
+
'lane', (select parent.lane from a2_events parent
|
|
168
|
+
where parent.session_id = child.session_id
|
|
169
|
+
and parent.idx = (child.cause ->> 'index')::bigint)
|
|
170
|
+
) || child.cause
|
|
171
|
+
where child.cause is not null and not child.cause ? 'consumer';
|
|
172
|
+
|
|
173
|
+
alter table a2_events
|
|
174
|
+
drop column lane,
|
|
175
|
+
drop column lane_ready,
|
|
176
|
+
drop column processed_at,
|
|
177
|
+
drop column processed_by_attempt,
|
|
178
|
+
drop column returned_event_ids,
|
|
179
|
+
drop column first_claimed_at,
|
|
180
|
+
drop column last_claimed_at,
|
|
181
|
+
drop column attempt_count,
|
|
182
|
+
drop column failure_count,
|
|
183
|
+
drop column last_failed_at,
|
|
184
|
+
drop column last_failed_attempt,
|
|
185
|
+
drop column last_error,
|
|
186
|
+
drop column failed_at,
|
|
187
|
+
drop column claim_holder,
|
|
188
|
+
drop column claim_expires_at;
|
|
189
|
+
end if;
|
|
190
|
+
end $$;
|
|
191
|
+
--> statement-breakpoint
|
|
192
|
+
|
|
193
|
+
-- Earlier releases recorded a schema version here and checked it before
|
|
194
|
+
-- their first query. This one checks nothing up front.
|
|
195
|
+
drop table if exists a2_schema;
|
|
196
|
+
--> statement-breakpoint
|
|
197
|
+
|
|
198
|
+
-- Runs an operation's statements in one round trip: A2 sends each write that
|
|
199
|
+
-- takes a session's lock as one call, the lock and then the statements that
|
|
200
|
+
-- need it, so it holds the lock only while the server runs them. Each
|
|
201
|
+
-- statement takes its snapshot when it starts, so those after the lock see
|
|
202
|
+
-- what its last holder committed; a single statement can't, since its
|
|
203
|
+
-- snapshot predates the lock. Each statement is a select of jsonb rows: a row
|
|
204
|
+
-- with an `abort` key fails the call and rolls it back, and one with a `stop`
|
|
205
|
+
-- key ends it. It needs read committed, the default: under a stricter level
|
|
206
|
+
-- every statement would share the first one's snapshot, so it refuses to run.
|
|
207
|
+
-- Created only if missing, as the indexes are: a later release that changes it
|
|
208
|
+
-- adds a function with a new name.
|
|
209
|
+
do $$ declare grantee text; begin
|
|
210
|
+
if to_regprocedure('a2_batch(text[], jsonb)') is null then
|
|
211
|
+
create function a2_batch(statements text[], params jsonb)
|
|
212
|
+
returns setof jsonb
|
|
213
|
+
language plpgsql
|
|
214
|
+
volatile
|
|
215
|
+
as $batch$
|
|
216
|
+
declare
|
|
217
|
+
statement text;
|
|
218
|
+
result jsonb;
|
|
219
|
+
begin
|
|
220
|
+
if current_setting('transaction_isolation') <> 'read committed' then
|
|
221
|
+
raise exception using errcode = 'A2002',
|
|
222
|
+
message = 'a2_batch needs the read committed isolation level';
|
|
223
|
+
end if;
|
|
224
|
+
foreach statement in array statements loop
|
|
225
|
+
for result in execute statement using params loop
|
|
226
|
+
if result ? 'abort' then
|
|
227
|
+
raise exception using errcode = 'A2001',
|
|
228
|
+
message = 'a2_batch aborted', detail = result::text;
|
|
229
|
+
end if;
|
|
230
|
+
return next result;
|
|
231
|
+
if result ? 'stop' then
|
|
232
|
+
return;
|
|
233
|
+
end if;
|
|
234
|
+
end loop;
|
|
235
|
+
end loop;
|
|
236
|
+
end
|
|
237
|
+
$batch$;
|
|
238
|
+
-- Default privileges can grant a new function to roles besides PUBLIC, as
|
|
239
|
+
-- platforms that serve functions over an API grant theirs: it starts with
|
|
240
|
+
-- none but its owner's. Grants made after it exist are left alone.
|
|
241
|
+
for grantee in
|
|
242
|
+
select acl.grantee::regrole::text
|
|
243
|
+
from pg_proc proc, aclexplode(proc.proacl) acl
|
|
244
|
+
where proc.oid = to_regprocedure('a2_batch(text[], jsonb)')
|
|
245
|
+
and acl.grantee not in (0, proc.proowner)
|
|
246
|
+
loop
|
|
247
|
+
execute format('revoke execute on function a2_batch(text[], jsonb) from %s', grantee);
|
|
248
|
+
end loop;
|
|
249
|
+
end if;
|
|
250
|
+
-- It runs any statement it's handed, as its caller: only its owner, the role
|
|
251
|
+
-- that applies this file, may call it, and not every role, as Postgres lets
|
|
252
|
+
-- by default. Platforms that serve functions over an API would serve it too.
|
|
253
|
+
if pg_has_role(
|
|
254
|
+
current_user,
|
|
255
|
+
(select proowner from pg_proc
|
|
256
|
+
where oid = to_regprocedure('a2_batch(text[], jsonb)')),
|
|
257
|
+
'usage'
|
|
258
|
+
) then
|
|
259
|
+
revoke execute on function a2_batch(text[], jsonb) from public;
|
|
260
|
+
end if;
|
|
261
|
+
end $$;
|
|
262
|
+
--> statement-breakpoint
|
|
263
|
+
|
|
264
|
+
do $$ begin
|
|
265
|
+
if to_regclass('a2_events_types') is null then
|
|
266
|
+
create index if not exists a2_events_types
|
|
267
|
+
on a2_events (session_id, event_type, idx);
|
|
268
|
+
end if;
|
|
269
|
+
if to_regclass('a2_cursors_heads') is null then
|
|
270
|
+
create index if not exists a2_cursors_heads
|
|
271
|
+
on a2_cursors (session_id, head) where head is not null;
|
|
272
|
+
end if;
|
|
273
|
+
if to_regclass('a2_cursors_lanes') is null then
|
|
274
|
+
create index if not exists a2_cursors_lanes
|
|
275
|
+
on a2_cursors (session_id) where kind = 'lane';
|
|
276
|
+
end if;
|
|
277
|
+
if to_regclass('a2_snapshot_pins_checkpoint') is null then
|
|
278
|
+
create index if not exists a2_snapshot_pins_checkpoint
|
|
279
|
+
on a2_snapshot_pins (session_id, reducer_name, up_to_index);
|
|
280
|
+
end if;
|
|
281
|
+
end $$;
|
|
282
|
+
--> statement-breakpoint
|
|
283
|
+
|
|
284
|
+
-- Event ids are unique per session, through the index on (session_id,
|
|
285
|
+
-- event_id). It replaces a2_events_event_id, on event_id alone. The swap
|
|
286
|
+
-- locks the table before it builds, so it waits for running queries instead
|
|
287
|
+
-- of deadlocking with a writer when the whole file runs as one transaction.
|
|
288
|
+
-- The old index goes only once the new one is valid, so a session's ids
|
|
289
|
+
-- always have a unique index.
|
|
290
|
+
do $$ begin
|
|
291
|
+
if to_regclass('a2_events_session_event_id') is null then
|
|
292
|
+
if to_regclass('a2_events_event_id') is not null then
|
|
293
|
+
lock table a2_events in access exclusive mode;
|
|
294
|
+
end if;
|
|
295
|
+
create unique index if not exists a2_events_session_event_id
|
|
296
|
+
on a2_events (session_id, event_id);
|
|
297
|
+
end if;
|
|
298
|
+
if to_regclass('a2_events_event_id') is not null and exists (
|
|
299
|
+
select 1 from pg_index
|
|
300
|
+
where indexrelid = to_regclass('a2_events_session_event_id')
|
|
301
|
+
and indisvalid and indisunique
|
|
302
|
+
) then
|
|
303
|
+
drop index a2_events_event_id;
|
|
304
|
+
end if;
|
|
305
|
+
end $$;
|
|
306
|
+
--> statement-breakpoint
|
|
307
|
+
|
|
308
|
+
create table if not exists board_positions (
|
|
309
|
+
consumer text primary key,
|
|
310
|
+
log_index bigint not null
|
|
311
|
+
);
|
|
312
|
+
--> statement-breakpoint
|
|
313
|
+
create table if not exists board_messages (
|
|
314
|
+
id bigint primary key,
|
|
315
|
+
event_id text not null unique,
|
|
316
|
+
channel text not null,
|
|
317
|
+
re bigint,
|
|
318
|
+
by_actor text not null,
|
|
319
|
+
by_principal text not null,
|
|
320
|
+
by_profile text,
|
|
321
|
+
from_key text,
|
|
322
|
+
no_sync boolean not null,
|
|
323
|
+
text_lower text not null,
|
|
324
|
+
deleted boolean not null,
|
|
325
|
+
created_at bigint not null,
|
|
326
|
+
replies integer not null default 0,
|
|
327
|
+
at bigint,
|
|
328
|
+
data text not null
|
|
329
|
+
);
|
|
330
|
+
--> statement-breakpoint
|
|
331
|
+
create index if not exists board_messages_channel on board_messages (channel, id);
|
|
332
|
+
--> statement-breakpoint
|
|
333
|
+
create index if not exists board_messages_re on board_messages (re, id);
|
|
334
|
+
--> statement-breakpoint
|
|
335
|
+
create index if not exists board_messages_by_actor on board_messages (by_actor, id);
|
|
336
|
+
--> statement-breakpoint
|
|
337
|
+
create index if not exists board_messages_by_principal on board_messages (by_principal, id);
|
|
338
|
+
--> statement-breakpoint
|
|
339
|
+
create index if not exists board_threads_at on board_messages (at) where re is null;
|
|
340
|
+
--> statement-breakpoint
|
|
341
|
+
create index if not exists board_threads_channel on board_messages (channel, at) where re is null;
|
|
342
|
+
--> statement-breakpoint
|
|
343
|
+
create table if not exists board_versions (
|
|
344
|
+
log_index bigint primary key,
|
|
345
|
+
message_id bigint not null,
|
|
346
|
+
data text not null
|
|
347
|
+
);
|
|
348
|
+
--> statement-breakpoint
|
|
349
|
+
create index if not exists board_versions_message on board_versions (message_id, log_index);
|
|
350
|
+
--> statement-breakpoint
|
|
351
|
+
create table if not exists board_terms (
|
|
352
|
+
message_id bigint not null,
|
|
353
|
+
term text not null,
|
|
354
|
+
value text not null,
|
|
355
|
+
primary key (message_id, term, value)
|
|
356
|
+
);
|
|
357
|
+
--> statement-breakpoint
|
|
358
|
+
create index if not exists board_terms_term on board_terms (term, value, message_id);
|
|
359
|
+
--> statement-breakpoint
|
|
360
|
+
create table if not exists board_sync_threads (
|
|
361
|
+
thread text primary key,
|
|
362
|
+
data text not null
|
|
363
|
+
);
|
|
364
|
+
--> statement-breakpoint
|
|
365
|
+
create table if not exists board_external_threads (
|
|
366
|
+
external text primary key,
|
|
367
|
+
thread text not null
|
|
368
|
+
);
|
|
369
|
+
--> statement-breakpoint
|
|
370
|
+
create table if not exists board_copies (
|
|
371
|
+
message_id bigint not null,
|
|
372
|
+
target text not null,
|
|
373
|
+
data text not null,
|
|
374
|
+
primary key (message_id, target)
|
|
375
|
+
);
|
|
376
|
+
--> statement-breakpoint
|
|
377
|
+
create table if not exists board_external_messages (
|
|
378
|
+
key text primary key,
|
|
379
|
+
message_id bigint not null
|
|
380
|
+
);
|
|
381
|
+
--> statement-breakpoint
|
|
382
|
+
drop index if exists board_messages_recent;
|
|
383
|
+
--> statement-breakpoint
|
|
384
|
+
create table if not exists board_meta (
|
|
385
|
+
key text primary key,
|
|
386
|
+
value text not null
|
|
387
|
+
);
|
|
388
|
+
--> statement-breakpoint
|
|
389
|
+
insert into board_meta (key, value) values ('postgres_schema', '1') on conflict (key) do update set value = greatest(board_meta.value::integer, excluded.value::integer)::text;
|