lastlight-core 0.25.9 → 0.27.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/config/default.yaml +317 -1
- package/dist/admin/chat-session-reader.d.ts +3 -3
- package/dist/admin/chat-session-reader.js +8 -8
- package/dist/admin/chat-session-reader.js.map +1 -1
- package/dist/admin/docker.js.map +1 -1
- package/dist/admin/routes.js +97 -99
- package/dist/admin/routes.js.map +1 -1
- package/dist/admin/sessions.d.ts +7 -7
- package/dist/admin/sessions.js +6 -4
- package/dist/admin/sessions.js.map +1 -1
- package/dist/admin/tail.js.map +1 -1
- package/dist/config/config.d.ts +29 -0
- package/dist/config/config.js +141 -0
- package/dist/config/config.js.map +1 -1
- package/dist/config/repo-config.js +6 -7
- package/dist/config/repo-config.js.map +1 -1
- package/dist/connectors/messaging/base.js +2 -2
- package/dist/connectors/messaging/base.js.map +1 -1
- package/dist/connectors/messaging/session-manager.d.ts +29 -31
- package/dist/connectors/messaging/session-manager.js +156 -189
- package/dist/connectors/messaging/session-manager.js.map +1 -1
- package/dist/connectors/messaging/thread-transcript.d.ts +2 -2
- package/dist/connectors/messaging/thread-transcript.js +14 -8
- package/dist/connectors/messaging/thread-transcript.js.map +1 -1
- package/dist/connectors/slack/connector.js +5 -5
- package/dist/connectors/slack/connector.js.map +1 -1
- package/dist/cron/dependabot-discovery.js.map +1 -1
- package/dist/cron/feedback-poll.js +6 -6
- package/dist/cron/feedback-poll.js.map +1 -1
- package/dist/cron/handlers.js +3 -3
- package/dist/cron/handlers.js.map +1 -1
- package/dist/cron/jobs.d.ts +1 -1
- package/dist/cron/jobs.js +2 -2
- package/dist/cron/jobs.js.map +1 -1
- package/dist/cron/repo-digest.js +4 -4
- package/dist/cron/repo-digest.js.map +1 -1
- package/dist/cron/review-discovery.js.map +1 -1
- package/dist/cron/runner.js +2 -2
- package/dist/cron/runner.js.map +1 -1
- package/dist/cron/scheduler.js +1 -1
- package/dist/cron/scheduler.js.map +1 -1
- package/dist/engine/agent-executor.d.ts +25 -1
- package/dist/engine/agent-executor.js +41 -1
- package/dist/engine/agent-executor.js.map +1 -1
- package/dist/engine/chat/chat-prompt.d.ts +11 -4
- package/dist/engine/chat/chat-prompt.js.map +1 -1
- package/dist/engine/chat/chat-runner.d.ts +3 -2
- package/dist/engine/chat/chat-runner.js +9 -7
- package/dist/engine/chat/chat-runner.js.map +1 -1
- package/dist/engine/dispatcher.js +29 -25
- package/dist/engine/dispatcher.js.map +1 -1
- package/dist/engine/event-shim.d.ts +18 -0
- package/dist/engine/event-shim.js +2 -0
- package/dist/engine/event-shim.js.map +1 -1
- package/dist/engine/executors/orchestrator.d.ts +120 -1
- package/dist/engine/executors/orchestrator.js +214 -47
- package/dist/engine/executors/orchestrator.js.map +1 -1
- package/dist/engine/executors/shared.js.map +1 -1
- package/dist/engine/feedback/ingest.d.ts +4 -4
- package/dist/engine/feedback/ingest.js +13 -13
- package/dist/engine/feedback/ingest.js.map +1 -1
- package/dist/engine/feedback/slack.d.ts +2 -2
- package/dist/engine/feedback/slack.js +6 -6
- package/dist/engine/feedback/slack.js.map +1 -1
- package/dist/engine/fix-harvest.d.ts +1 -1
- package/dist/engine/fix-harvest.js +3 -3
- package/dist/engine/fix-harvest.js.map +1 -1
- package/dist/engine/github/github.d.ts +59 -0
- package/dist/engine/github/github.js +72 -0
- package/dist/engine/github/github.js.map +1 -1
- package/dist/engine/github/installations.js.map +1 -1
- package/dist/engine/github/review-poster.d.ts +388 -9
- package/dist/engine/github/review-poster.js +550 -50
- package/dist/engine/github/review-poster.js.map +1 -1
- package/dist/engine/github/team-visibility.js +7 -7
- package/dist/engine/github/team-visibility.js.map +1 -1
- package/dist/engine/llm.js.map +1 -1
- package/dist/engine/pr-decisions.d.ts +13 -5
- package/dist/engine/pr-decisions.js +204 -5
- package/dist/engine/pr-decisions.js.map +1 -1
- package/dist/engine/pr-escalation.js +7 -7
- package/dist/engine/pr-escalation.js.map +1 -1
- package/dist/engine/pr-state.d.ts +59 -1
- package/dist/engine/pr-state.js +76 -10
- package/dist/engine/pr-state.js.map +1 -1
- package/dist/engine/review-check.d.ts +1 -1
- package/dist/engine/review-check.js +5 -5
- package/dist/engine/review-check.js.map +1 -1
- package/dist/engine/review-spec.d.ts +264 -0
- package/dist/engine/review-spec.js +723 -0
- package/dist/engine/review-spec.js.map +1 -0
- package/dist/engine/router.js +3 -3
- package/dist/engine/router.js.map +1 -1
- package/dist/engine/screen/classifier.js.map +1 -1
- package/dist/engine/screen/screen.js.map +1 -1
- package/dist/evals-api.d.ts +3 -0
- package/dist/evals-api.js +20 -0
- package/dist/evals-api.js.map +1 -1
- package/dist/index.js +145 -67
- package/dist/index.js.map +1 -1
- package/dist/notify/digest-blocks.js.map +1 -1
- package/dist/notify/model.js.map +1 -1
- package/dist/notify/transports/github.js.map +1 -1
- package/dist/notify/transports/slack.js.map +1 -1
- package/dist/sandbox/artifact-backend.js.map +1 -1
- package/dist/sandbox/artifact-store.js.map +1 -1
- package/dist/sandbox/docker.d.ts +56 -5
- package/dist/sandbox/docker.js +96 -2
- package/dist/sandbox/docker.js.map +1 -1
- package/dist/sandbox/egress-allowlist.js.map +1 -1
- package/dist/sandbox/k8s/agent-context-registry.js.map +1 -1
- package/dist/sandbox/k8s/client.js.map +1 -1
- package/dist/sandbox/k8s/kubernetes-sandbox.d.ts +3 -0
- package/dist/sandbox/k8s/kubernetes-sandbox.js +9 -0
- package/dist/sandbox/k8s/kubernetes-sandbox.js.map +1 -1
- package/dist/sandbox/k8s/pod.d.ts +11 -0
- package/dist/sandbox/k8s/pod.js +11 -6
- package/dist/sandbox/k8s/pod.js.map +1 -1
- package/dist/sandbox/k8s/resource-name.js.map +1 -1
- package/dist/sandbox/k8s/run-id.js.map +1 -1
- package/dist/sandbox/k8s/run-secrets.js.map +1 -1
- package/dist/sandbox/k8s/service-containers.d.ts +43 -0
- package/dist/sandbox/k8s/service-containers.js +87 -0
- package/dist/sandbox/k8s/service-containers.js.map +1 -0
- package/dist/sandbox/k8s/skill-bundle.js.map +1 -1
- package/dist/sandbox/k8s/workspace-provisioner.js +10 -2
- package/dist/sandbox/k8s/workspace-provisioner.js.map +1 -1
- package/dist/sandbox/reap.d.ts +9 -0
- package/dist/sandbox/reap.js +36 -0
- package/dist/sandbox/reap.js.map +1 -1
- package/dist/sandbox/sandbox.d.ts +34 -0
- package/dist/sandbox/sandbox.js +36 -6
- package/dist/sandbox/sandbox.js.map +1 -1
- package/dist/sandbox/service-containers-docker.d.ts +45 -0
- package/dist/sandbox/service-containers-docker.js +78 -0
- package/dist/sandbox/service-containers-docker.js.map +1 -0
- package/dist/session-log.js.map +1 -1
- package/dist/state/approval-store.d.ts +23 -14
- package/dist/state/approval-store.js +137 -86
- package/dist/state/approval-store.js.map +1 -1
- package/dist/state/build-assets.js.map +1 -1
- package/dist/state/client.d.ts +105 -0
- package/dist/state/client.js +68 -0
- package/dist/state/client.js.map +1 -0
- package/dist/state/cron-run-store.d.ts +32 -12
- package/dist/state/cron-run-store.js +105 -39
- package/dist/state/cron-run-store.js.map +1 -1
- package/dist/state/data-migrate.d.ts +135 -0
- package/dist/state/data-migrate.js +309 -0
- package/dist/state/data-migrate.js.map +1 -0
- package/dist/state/db.d.ts +82 -23
- package/dist/state/db.js +201 -105
- package/dist/state/db.js.map +1 -1
- package/dist/state/dialect.d.ts +77 -0
- package/dist/state/dialect.js +129 -0
- package/dist/state/dialect.js.map +1 -0
- package/dist/state/execution-store.d.ts +124 -103
- package/dist/state/execution-store.js +569 -374
- package/dist/state/execution-store.js.map +1 -1
- package/dist/state/feedback-store.d.ts +20 -20
- package/dist/state/feedback-store.js +241 -187
- package/dist/state/feedback-store.js.map +1 -1
- package/dist/state/legacy-sqlite.d.ts +15 -0
- package/dist/state/legacy-sqlite.js +131 -0
- package/dist/state/legacy-sqlite.js.map +1 -0
- package/dist/state/pg-client.d.ts +44 -0
- package/dist/state/pg-client.js +81 -0
- package/dist/state/pg-client.js.map +1 -0
- package/dist/state/repo-ref.d.ts +9 -4
- package/dist/state/repo-ref.js +12 -6
- package/dist/state/repo-ref.js.map +1 -1
- package/dist/state/schema/pg.d.ts +2788 -0
- package/dist/state/schema/pg.js +301 -0
- package/dist/state/schema/pg.js.map +1 -0
- package/dist/state/schema/sqlite.d.ts +3063 -0
- package/dist/state/schema/sqlite.js +391 -0
- package/dist/state/schema/sqlite.js.map +1 -0
- package/dist/state/state-cli.d.ts +8 -0
- package/dist/state/state-cli.js +247 -0
- package/dist/state/state-cli.js.map +1 -0
- package/dist/state/team-store.d.ts +26 -13
- package/dist/state/team-store.js +140 -93
- package/dist/state/team-store.js.map +1 -1
- package/dist/state/user-store.d.ts +31 -13
- package/dist/state/user-store.js +180 -80
- package/dist/state/user-store.js.map +1 -1
- package/dist/state/workflow-run-store.d.ts +95 -56
- package/dist/state/workflow-run-store.js +419 -314
- package/dist/state/workflow-run-store.js.map +1 -1
- package/dist/telemetry/index.js.map +1 -1
- package/dist/workflows/admission.d.ts +4 -3
- package/dist/workflows/admission.js +34 -10
- package/dist/workflows/admission.js.map +1 -1
- package/dist/workflows/handlers/fanout.d.ts +157 -0
- package/dist/workflows/handlers/fanout.js +663 -0
- package/dist/workflows/handlers/fanout.js.map +1 -0
- package/dist/workflows/handlers/post-review.d.ts +98 -8
- package/dist/workflows/handlers/post-review.js +394 -23
- package/dist/workflows/handlers/post-review.js.map +1 -1
- package/dist/workflows/resume.js +22 -15
- package/dist/workflows/resume.js.map +1 -1
- package/dist/workflows/runner.js +60 -12
- package/dist/workflows/runner.js.map +1 -1
- package/dist/workflows/simple.d.ts +23 -0
- package/dist/workflows/simple.js +40 -16
- package/dist/workflows/simple.js.map +1 -1
- package/docker-compose.yml +50 -0
- package/drizzle/pg/0000_init.sql +235 -0
- package/drizzle/pg/meta/0000_snapshot.json +1751 -0
- package/drizzle/pg/meta/_journal.json +13 -0
- package/drizzle/sqlite/0000_baseline.sql +257 -0
- package/drizzle/sqlite/0001_backfill_repo_refs.sql +74 -0
- package/drizzle/sqlite/meta/0000_snapshot.json +1593 -0
- package/drizzle/sqlite/meta/0001_snapshot.json +1593 -0
- package/drizzle/sqlite/meta/_journal.json +20 -0
- package/package.json +31 -15
- package/sandbox.Dockerfile +54 -0
- package/skills/code-review/SKILL.md +98 -13
- package/skills/pr-review/SKILL.md +97 -21
- package/skills/pr-review/references/findings-schema.md +37 -6
- package/workflows/pr-review.yaml +567 -0
- package/workflows/prompts/dependabot-pr-merge.md +22 -2
- package/workflows/prompts/review-adjudicate.md +323 -0
- package/workflows/prompts/review-falsify.md +149 -0
- package/workflows/prompts/review.md +80 -0
- package/workflows/prompts/survey-contract.md +109 -0
- package/workflows/prompts/survey-enforcement.md +126 -0
- package/workflows/prompts/survey-security.md +118 -0
- package/workflows/prompts/survey-spec.md +110 -0
- package/workflows/prompts/survey-state.md +143 -0
- package/workflows/prompts/survey-tests.md +99 -0
- package/dist/state/migrate.d.ts +0 -15
- package/dist/state/migrate.js +0 -518
- package/dist/state/migrate.js.map +0 -1
|
@@ -1,4 +1,32 @@
|
|
|
1
1
|
import { randomUUID } from "crypto";
|
|
2
|
+
import { and, desc, eq, isNotNull, sql } from "drizzle-orm";
|
|
3
|
+
import { tablesOf } from "./client.js";
|
|
4
|
+
import { rows } from "./dialect.js";
|
|
5
|
+
/**
|
|
6
|
+
* A lexicographically-sortable row id: a fixed-width millisecond stamp, a
|
|
7
|
+
* per-process counter, then a uuid.
|
|
8
|
+
*
|
|
9
|
+
* `started_at` has millisecond resolution, so two fires in the same millisecond
|
|
10
|
+
* tie — and both reads below break that tie on `id`. Under sqlite the tiebreak
|
|
11
|
+
* used to be `rowid`, i.e. INSERTION ORDER, which PostgreSQL has no equivalent
|
|
12
|
+
* of; a plain `randomUUID()` is a total order but an ARBITRARY one, and
|
|
13
|
+
* arbitrary is not good enough here. `recentFailures` walks newest-first until
|
|
14
|
+
* it meets an `ok`, so a tie straddling an `ok` and a `failed` yields a
|
|
15
|
+
* different count depending which way it happened to sort — the failure alert
|
|
16
|
+
* flickering on a cron that is fine, or staying quiet on one that is not. This
|
|
17
|
+
* restores insertion order without a schema change and reads identically in
|
|
18
|
+
* both dialects.
|
|
19
|
+
*
|
|
20
|
+
* Rows written before this existed carry a bare uuid, which sorts differently —
|
|
21
|
+
* harmless, because the tiebreak only ever compares rows from the SAME
|
|
22
|
+
* millisecond and no millisecond spans the deploy that introduced it.
|
|
23
|
+
*/
|
|
24
|
+
let idSeq = 0;
|
|
25
|
+
function creationOrderedId() {
|
|
26
|
+
const stamp = Date.now().toString(16).padStart(12, "0");
|
|
27
|
+
idSeq = (idSeq + 1) & 0xffffff;
|
|
28
|
+
return `${stamp}-${idSeq.toString(16).padStart(6, "0")}-${randomUUID()}`;
|
|
29
|
+
}
|
|
2
30
|
/**
|
|
3
31
|
* Owns the `cron_runs` ledger — one row per cron FIRE, scheduled or manual,
|
|
4
32
|
* for `workflow:` and `handler:` crons alike.
|
|
@@ -16,40 +44,75 @@ import { randomUUID } from "crypto";
|
|
|
16
44
|
* and vice versa (issue #327).
|
|
17
45
|
*/
|
|
18
46
|
export class CronRunStore {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
47
|
+
client;
|
|
48
|
+
/**
|
|
49
|
+
* Table objects for THIS client's dialect. Every method destructures what it
|
|
50
|
+
* needs off this instead of importing from `schema/sqlite.js` — see
|
|
51
|
+
* `client.ts` → {@link tablesOf} for why the cast alone cannot do it.
|
|
52
|
+
*/
|
|
53
|
+
t;
|
|
54
|
+
constructor(client) {
|
|
55
|
+
this.client = client;
|
|
56
|
+
this.t = tablesOf(client);
|
|
22
57
|
}
|
|
23
58
|
/** Insert a `running` row and return its id. */
|
|
24
|
-
start(meta) {
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
59
|
+
async start(meta) {
|
|
60
|
+
const { cronRuns } = this.t;
|
|
61
|
+
const id = creationOrderedId();
|
|
62
|
+
await this.client.insert(cronRuns).values({
|
|
63
|
+
id,
|
|
64
|
+
cronName: meta.cronName,
|
|
65
|
+
workflow: meta.workflow ?? null,
|
|
66
|
+
handler: meta.handler ?? null,
|
|
67
|
+
source: meta.source,
|
|
68
|
+
actor: meta.actor,
|
|
69
|
+
startedAt: new Date().toISOString(),
|
|
70
|
+
status: "running",
|
|
71
|
+
});
|
|
30
72
|
return id;
|
|
31
73
|
}
|
|
32
74
|
/** Stamp `finished_at` and the terminal fields. */
|
|
33
|
-
finish(id, result) {
|
|
34
|
-
this.
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
75
|
+
async finish(id, result) {
|
|
76
|
+
const { cronRuns } = this.t;
|
|
77
|
+
await this.client
|
|
78
|
+
.update(cronRuns)
|
|
79
|
+
.set({
|
|
80
|
+
finishedAt: new Date().toISOString(),
|
|
81
|
+
status: result.status,
|
|
82
|
+
reposEligible: result.reposEligible ?? null,
|
|
83
|
+
reposScanned: result.reposScanned ?? null,
|
|
84
|
+
discovered: result.discovered ?? null,
|
|
85
|
+
dispatched: result.dispatched ?? null,
|
|
86
|
+
failures: result.failures ?? null,
|
|
87
|
+
error: result.error ?? null,
|
|
88
|
+
})
|
|
89
|
+
.where(eq(cronRuns.id, id));
|
|
40
90
|
}
|
|
41
|
-
/**
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
91
|
+
/**
|
|
92
|
+
* Most recent row per cron name — what the dashboard's crons list reads.
|
|
93
|
+
*
|
|
94
|
+
* A window function, so it stays raw SQL. Two portability notes: the derived
|
|
95
|
+
* table carries an explicit alias (Postgres rejects a `FROM` subquery without
|
|
96
|
+
* one), and `rn` is a `ROW_NUMBER()` rank — `rn = 1` is an integer compare,
|
|
97
|
+
* not a boolean. The tiebreak is `id DESC` — a real recency order, because
|
|
98
|
+
* the ids are minted in creation order ({@link creationOrderedId}); picking
|
|
99
|
+
* the wrong row of a tie here would show the dashboard the wrong outcome.
|
|
100
|
+
*
|
|
101
|
+
* `rows()` results are NOT column-mapped, so {@link mapCronRunRow} reads the
|
|
102
|
+
* raw snake_case column names.
|
|
103
|
+
*/
|
|
104
|
+
async latestByCron() {
|
|
105
|
+
const { cronRuns } = this.t;
|
|
106
|
+
const ranked = await rows(this.client, sql `SELECT * FROM (
|
|
107
|
+
SELECT *, ROW_NUMBER() OVER (
|
|
108
|
+
PARTITION BY ${cronRuns.cronName}
|
|
109
|
+
ORDER BY ${cronRuns.startedAt} DESC, ${cronRuns.id} DESC
|
|
110
|
+
) AS rn
|
|
111
|
+
FROM ${cronRuns}
|
|
112
|
+
) AS ranked
|
|
113
|
+
WHERE rn = 1`);
|
|
51
114
|
const map = new Map();
|
|
52
|
-
for (const row of
|
|
115
|
+
for (const row of ranked) {
|
|
53
116
|
const record = mapCronRunRow(row);
|
|
54
117
|
map.set(record.cronName, record);
|
|
55
118
|
}
|
|
@@ -63,20 +126,23 @@ export class CronRunStore {
|
|
|
63
126
|
* it. Mirrors `ExecutionStore.consecutiveFailures` in shape so the
|
|
64
127
|
* scheduler's call site changes key and table but not logic.
|
|
65
128
|
*
|
|
66
|
-
* `
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
129
|
+
* `id DESC` breaks ties on `started_at`, and the ids are minted in creation
|
|
130
|
+
* order for exactly that purpose — see {@link creationOrderedId}. A merely
|
|
131
|
+
* DETERMINISTIC tiebreak is not sufficient here, which is the trap: this walk
|
|
132
|
+
* stops at the first `ok`, so a tie holding one `ok` and one `failed` returns
|
|
133
|
+
* a different count depending which sorts first. It has to be the RIGHT
|
|
134
|
+
* order, not just a stable one.
|
|
70
135
|
*/
|
|
71
|
-
recentFailures(cronName) {
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
.
|
|
136
|
+
async recentFailures(cronName) {
|
|
137
|
+
const { cronRuns } = this.t;
|
|
138
|
+
const recent = await this.client
|
|
139
|
+
.select({ status: cronRuns.status })
|
|
140
|
+
.from(cronRuns)
|
|
141
|
+
.where(and(eq(cronRuns.cronName, cronName), isNotNull(cronRuns.finishedAt)))
|
|
142
|
+
.orderBy(desc(cronRuns.startedAt), desc(cronRuns.id))
|
|
143
|
+
.limit(10);
|
|
78
144
|
let count = 0;
|
|
79
|
-
for (const row of
|
|
145
|
+
for (const row of recent) {
|
|
80
146
|
if (row.status !== "ok")
|
|
81
147
|
count++;
|
|
82
148
|
else
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cron-run-store.js","sourceRoot":"","sources":["../../src/state/cron-run-store.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cron-run-store.js","sourceRoot":"","sources":["../../src/state/cron-run-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,QAAQ,EAAsC,MAAM,aAAa,CAAC;AAC3E,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAEpC;;;;;;;;;;;;;;;;;;GAkBG;AACH,IAAI,KAAK,GAAG,CAAC,CAAC;AACd,SAAS,iBAAiB;IACxB,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;IACxD,KAAK,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,QAAQ,CAAC;IAC/B,OAAO,GAAG,KAAK,IAAI,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,IAAI,UAAU,EAAE,EAAE,CAAC;AAC3E,CAAC;AAsDD;;;;;;;;;;;;;;;GAeG;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AAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;aACpD,KAAK,CAAC,EAAE,CAAC,CAAC;QAEb,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,KAAK,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC;YACzB,IAAI,GAAG,CAAC,MAAM,KAAK,IAAI;gBAAE,KAAK,EAAE,CAAC;;gBAC5B,MAAM;QACb,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAED,SAAS,aAAa,CAAC,GAA4B;IACjD,OAAO;QACL,EAAE,EAAE,GAAG,CAAC,EAAY;QACpB,QAAQ,EAAE,GAAG,CAAC,SAAmB;QACjC,QAAQ,EAAG,GAAG,CAAC,QAA0B,IAAI,IAAI;QACjD,OAAO,EAAG,GAAG,CAAC,OAAyB,IAAI,IAAI;QAC/C,MAAM,EAAE,GAAG,CAAC,MAAuB;QACnC,KAAK,EAAG,GAAG,CAAC,KAAuB,IAAI,IAAI;QAC3C,SAAS,EAAE,GAAG,CAAC,UAAoB;QACnC,UAAU,EAAG,GAAG,CAAC,WAA6B,IAAI,IAAI;QACtD,MAAM,EAAE,GAAG,CAAC,MAAuB;QACnC,aAAa,EAAG,GAAG,CAAC,cAAgC,IAAI,IAAI;QAC5D,YAAY,EAAG,GAAG,CAAC,aAA+B,IAAI,IAAI;QAC1D,UAAU,EAAG,GAAG,CAAC,UAA4B,IAAI,IAAI;QACrD,UAAU,EAAG,GAAG,CAAC,UAA4B,IAAI,IAAI;QACrD,QAAQ,EAAG,GAAG,CAAC,QAA0B,IAAI,IAAI;QACjD,KAAK,EAAG,GAAG,CAAC,KAAuB,IAAI,IAAI;KAC5C,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { StateDb } from "./db.js";
|
|
2
|
+
import { type StateTables } from "./client.js";
|
|
3
|
+
import { type PgDriver } from "lastlight-shared/database-url";
|
|
4
|
+
/** The schema export names, in an order no foreign key can object to. */
|
|
5
|
+
type TableKey = keyof StateTables;
|
|
6
|
+
interface TableSpec {
|
|
7
|
+
key: TableKey;
|
|
8
|
+
/** Property names forming a stable total order, so batched reads cannot skip or repeat a row. */
|
|
9
|
+
orderBy: string[];
|
|
10
|
+
/**
|
|
11
|
+
* Columns the TARGET generates and an insert must not supply. Only
|
|
12
|
+
* `messaging_messages.id`, which is `AUTOINCREMENT` on SQLite and
|
|
13
|
+
* `GENERATED ALWAYS AS IDENTITY` on Postgres — the latter rejects an explicit
|
|
14
|
+
* value outright. Nothing references that id, so letting Postgres re-assign
|
|
15
|
+
* it loses nothing; reading in id order keeps the message sequence intact.
|
|
16
|
+
*/
|
|
17
|
+
omit?: string[];
|
|
18
|
+
}
|
|
19
|
+
export declare const TABLE_ORDER: readonly TableSpec[];
|
|
20
|
+
export interface MigrateStateDataOptions {
|
|
21
|
+
/** Source: a SQLite path, `file:` URL or `:memory:` — anything `StateDb.open` takes. */
|
|
22
|
+
from: string;
|
|
23
|
+
/** Target: a `postgres://` URL. */
|
|
24
|
+
to: string;
|
|
25
|
+
/** Postgres driver override; unset auto-detects from the target host. */
|
|
26
|
+
driver?: PgDriver;
|
|
27
|
+
/** Rows per read/insert round trip. */
|
|
28
|
+
batchSize?: number;
|
|
29
|
+
/** Count and report without writing anything. */
|
|
30
|
+
dryRun?: boolean;
|
|
31
|
+
/** Delete existing target rows first. Without it a non-empty target aborts. */
|
|
32
|
+
truncate?: boolean;
|
|
33
|
+
/** Progress sink. The CLI renders these; callers that don't care omit it. */
|
|
34
|
+
onProgress?: (event: MigrateProgress) => void;
|
|
35
|
+
}
|
|
36
|
+
export type MigrateProgress = {
|
|
37
|
+
type: "start";
|
|
38
|
+
tables: number;
|
|
39
|
+
} | {
|
|
40
|
+
type: "table-start";
|
|
41
|
+
table: string;
|
|
42
|
+
rows: number;
|
|
43
|
+
} | {
|
|
44
|
+
type: "batch";
|
|
45
|
+
table: string;
|
|
46
|
+
copied: number;
|
|
47
|
+
rows: number;
|
|
48
|
+
} | {
|
|
49
|
+
type: "table-done";
|
|
50
|
+
table: string;
|
|
51
|
+
copied: number;
|
|
52
|
+
} | {
|
|
53
|
+
type: "done";
|
|
54
|
+
totalRows: number;
|
|
55
|
+
durationMs: number;
|
|
56
|
+
};
|
|
57
|
+
export interface TableResult {
|
|
58
|
+
table: string;
|
|
59
|
+
/** Rows read from the source. */
|
|
60
|
+
source: number;
|
|
61
|
+
/** Rows inserted into the target. */
|
|
62
|
+
copied: number;
|
|
63
|
+
/** Rows counted in the target afterwards — the verification pass. */
|
|
64
|
+
target: number;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* A migration failure that knows whether anything was written yet.
|
|
68
|
+
*
|
|
69
|
+
* The distinction is the whole difference between two operator actions: a
|
|
70
|
+
* refusal *before* the first insert (wrong direction, occupied target) leaves
|
|
71
|
+
* the target exactly as it was and wants the input fixed; a failure *after*
|
|
72
|
+
* leaves a partially-filled database that must be truncated before a retry.
|
|
73
|
+
* Telling someone to truncate a database this run never touched is how they
|
|
74
|
+
* end up deleting the wrong one.
|
|
75
|
+
*/
|
|
76
|
+
export declare class StateMigrationError extends Error {
|
|
77
|
+
/** True if at least one row may have been inserted before the failure. */
|
|
78
|
+
readonly wrote: boolean;
|
|
79
|
+
constructor(message: string,
|
|
80
|
+
/** True if at least one row may have been inserted before the failure. */
|
|
81
|
+
wrote: boolean, options?: {
|
|
82
|
+
cause?: unknown;
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
export interface MigrateStateDataResult {
|
|
86
|
+
tables: TableResult[];
|
|
87
|
+
totalRows: number;
|
|
88
|
+
durationMs: number;
|
|
89
|
+
dryRun: boolean;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Copy every row from a SQLite state database into a Postgres one.
|
|
93
|
+
*
|
|
94
|
+
* Not transactional as a whole, and cannot be: 15 tables and potentially
|
|
95
|
+
* hundreds of thousands of rows in one Postgres transaction is a recipe for a
|
|
96
|
+
* bloated WAL and a lock held for minutes. The design point that makes that
|
|
97
|
+
* acceptable is the empty-target precondition — a failed run leaves a
|
|
98
|
+
* partially-filled database that is safe to `--truncate` and retry, and the
|
|
99
|
+
* verification pass names exactly where it stopped.
|
|
100
|
+
*
|
|
101
|
+
* **Take a snapshot of the source first.** Opening it runs the source's own
|
|
102
|
+
* migrations (that is the point — both ends must be at the same schema
|
|
103
|
+
* version), which is a write. The harness should be stopped, or the source
|
|
104
|
+
* should be a copy: never point this at a database a running Last Light is
|
|
105
|
+
* writing to.
|
|
106
|
+
*/
|
|
107
|
+
export declare function migrateStateData(opts: MigrateStateDataOptions): Promise<MigrateStateDataResult>;
|
|
108
|
+
/**
|
|
109
|
+
* The copy itself, over two already-open databases.
|
|
110
|
+
*
|
|
111
|
+
* Separate from {@link migrateStateData} so it can be driven against a PGlite
|
|
112
|
+
* target in the hermetic test suite: PGlite has no URL, so a function that owns
|
|
113
|
+
* its own `open()` calls could only ever be tested against a real server, and
|
|
114
|
+
* the whole value-mapping contract would go unexercised in CI.
|
|
115
|
+
*/
|
|
116
|
+
export declare function copyStateData(source: StateDb, target: StateDb, opts: Omit<MigrateStateDataOptions, "from" | "to" | "driver">): Promise<MigrateStateDataResult>;
|
|
117
|
+
/**
|
|
118
|
+
* A hand-maintained table list silently skips whatever is added after it was
|
|
119
|
+
* written, and a state migration that skips a table destroys data without
|
|
120
|
+
* erroring. So the list is checked against the schema's own exports on every
|
|
121
|
+
* run — `schema/sqlite.ts` is the source of truth, and adding a table there
|
|
122
|
+
* fails this loudly until it is placed in {@link TABLE_ORDER} at an
|
|
123
|
+
* FK-respecting position.
|
|
124
|
+
*/
|
|
125
|
+
export declare function assertCoversEveryTable(): void;
|
|
126
|
+
/**
|
|
127
|
+
* The message a human can act on, from anywhere in the cause chain.
|
|
128
|
+
*
|
|
129
|
+
* Drizzle wraps every driver error in a `DrizzleQueryError` whose message is
|
|
130
|
+
* just the SQL it was running, so the actual reason — "password authentication
|
|
131
|
+
* failed", "no such table" — is one or two levels down. Reporting only the top
|
|
132
|
+
* of the chain turns every failure into "Failed query: select 1".
|
|
133
|
+
*/
|
|
134
|
+
export declare function describeError(error: unknown): string;
|
|
135
|
+
export {};
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SQLite → Postgres state migration.
|
|
3
|
+
*
|
|
4
|
+
* The move that makes "choose your database" true for an EXISTING deployment
|
|
5
|
+
* rather than only a fresh one: it copies every row of a live `lastlight.db`
|
|
6
|
+
* into a Postgres server, table by table, through the two Drizzle schemas.
|
|
7
|
+
*
|
|
8
|
+
* **Why this is a read-and-insert loop and not a dump/restore.** Both schemas
|
|
9
|
+
* carry the same `$type<T>()` on every column, and Drizzle maps values at the
|
|
10
|
+
* driver boundary in both directions — so a `boolean` column arrives from
|
|
11
|
+
* SQLite as a JS `true` and goes into Postgres as a real `true`, and a
|
|
12
|
+
* `text({mode:'json'})` column arrives as a parsed object and goes into `jsonb`
|
|
13
|
+
* as one. The JS value in the middle is dialect-neutral, which is exactly what
|
|
14
|
+
* `pg_dump`-style text transport is not: it would have to know that `success`
|
|
15
|
+
* is `0/1` here and `false` there, and that `context` is a string here and a
|
|
16
|
+
* document there.
|
|
17
|
+
*
|
|
18
|
+
* Direction is deliberately one-way. Postgres → SQLite is not supported and is
|
|
19
|
+
* not a symmetric problem (identity columns, jsonb key order, wider integers).
|
|
20
|
+
*
|
|
21
|
+
* ## Invariants
|
|
22
|
+
*
|
|
23
|
+
* - **Both ends are migrated first.** Each side is opened through
|
|
24
|
+
* `StateDb.open()`, so the source gets the legacy-compat pre-step + its
|
|
25
|
+
* journalled migrations and the target gets `drizzle/pg`. Copying between two
|
|
26
|
+
* different schema versions is the failure this prevents.
|
|
27
|
+
* - **FK order is load-bearing** for exactly one pair —
|
|
28
|
+
* `messaging_sessions` → `messaging_messages`, the only declared foreign key
|
|
29
|
+
* in the 15-table schema. {@link TABLE_ORDER} encodes it.
|
|
30
|
+
* - **The target must be empty**, unless `truncate` is passed. Copying into a
|
|
31
|
+
* populated database would half-succeed on primary-key collisions and leave
|
|
32
|
+
* an interleaved mess that is worse than either input.
|
|
33
|
+
* - **Every table is covered or the migration refuses to start.** The coverage
|
|
34
|
+
* check against the schema's own exports is what stops a 16th table added
|
|
35
|
+
* later from being silently left behind — the failure mode of a hand-kept
|
|
36
|
+
* list, and one nobody would notice until the data was already gone.
|
|
37
|
+
*/
|
|
38
|
+
import { is, Table, asc, sql } from "drizzle-orm";
|
|
39
|
+
import { StateDb } from "./db.js";
|
|
40
|
+
import { tablesOf } from "./client.js";
|
|
41
|
+
import * as sqliteSchema from "./schema/sqlite.js";
|
|
42
|
+
export const TABLE_ORDER = [
|
|
43
|
+
{ key: "executions", orderBy: ["id"] },
|
|
44
|
+
{ key: "workflowRuns", orderBy: ["id"] },
|
|
45
|
+
{ key: "workflowApprovals", orderBy: ["id"] },
|
|
46
|
+
{ key: "cronOverrides", orderBy: ["name"] },
|
|
47
|
+
{ key: "cronRuns", orderBy: ["id"] },
|
|
48
|
+
{ key: "workflowOverrides", orderBy: ["name"] },
|
|
49
|
+
{ key: "users", orderBy: ["id"] },
|
|
50
|
+
{ key: "feedbackAnchors", orderBy: ["id"] },
|
|
51
|
+
{ key: "feedbackSignals", orderBy: ["id"] },
|
|
52
|
+
{ key: "githubTeams", orderBy: ["org", "slug"] },
|
|
53
|
+
{ key: "githubTeamRepos", orderBy: ["org", "teamSlug", "repo"] },
|
|
54
|
+
{ key: "githubTeamMembers", orderBy: ["org", "teamSlug", "login"] },
|
|
55
|
+
{ key: "githubVisibilitySync", orderBy: ["login"] },
|
|
56
|
+
// ── The one foreign key in the schema: sessions before their messages. ──
|
|
57
|
+
{ key: "messagingSessions", orderBy: ["id"] },
|
|
58
|
+
{ key: "messagingMessages", orderBy: ["id"], omit: ["id"] },
|
|
59
|
+
];
|
|
60
|
+
/**
|
|
61
|
+
* A migration failure that knows whether anything was written yet.
|
|
62
|
+
*
|
|
63
|
+
* The distinction is the whole difference between two operator actions: a
|
|
64
|
+
* refusal *before* the first insert (wrong direction, occupied target) leaves
|
|
65
|
+
* the target exactly as it was and wants the input fixed; a failure *after*
|
|
66
|
+
* leaves a partially-filled database that must be truncated before a retry.
|
|
67
|
+
* Telling someone to truncate a database this run never touched is how they
|
|
68
|
+
* end up deleting the wrong one.
|
|
69
|
+
*/
|
|
70
|
+
export class StateMigrationError extends Error {
|
|
71
|
+
wrote;
|
|
72
|
+
constructor(message,
|
|
73
|
+
/** True if at least one row may have been inserted before the failure. */
|
|
74
|
+
wrote, options) {
|
|
75
|
+
super(message, options);
|
|
76
|
+
this.wrote = wrote;
|
|
77
|
+
this.name = "StateMigrationError";
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Copy every row from a SQLite state database into a Postgres one.
|
|
82
|
+
*
|
|
83
|
+
* Not transactional as a whole, and cannot be: 15 tables and potentially
|
|
84
|
+
* hundreds of thousands of rows in one Postgres transaction is a recipe for a
|
|
85
|
+
* bloated WAL and a lock held for minutes. The design point that makes that
|
|
86
|
+
* acceptable is the empty-target precondition — a failed run leaves a
|
|
87
|
+
* partially-filled database that is safe to `--truncate` and retry, and the
|
|
88
|
+
* verification pass names exactly where it stopped.
|
|
89
|
+
*
|
|
90
|
+
* **Take a snapshot of the source first.** Opening it runs the source's own
|
|
91
|
+
* migrations (that is the point — both ends must be at the same schema
|
|
92
|
+
* version), which is a write. The harness should be stopped, or the source
|
|
93
|
+
* should be a copy: never point this at a database a running Last Light is
|
|
94
|
+
* writing to.
|
|
95
|
+
*/
|
|
96
|
+
export async function migrateStateData(opts) {
|
|
97
|
+
const source = await StateDb.open(opts.from);
|
|
98
|
+
let target;
|
|
99
|
+
try {
|
|
100
|
+
target = await StateDb.open(opts.to, { driver: opts.driver });
|
|
101
|
+
return await copyStateData(source, target, opts);
|
|
102
|
+
}
|
|
103
|
+
finally {
|
|
104
|
+
await source.close();
|
|
105
|
+
await target?.close();
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* The copy itself, over two already-open databases.
|
|
110
|
+
*
|
|
111
|
+
* Separate from {@link migrateStateData} so it can be driven against a PGlite
|
|
112
|
+
* target in the hermetic test suite: PGlite has no URL, so a function that owns
|
|
113
|
+
* its own `open()` calls could only ever be tested against a real server, and
|
|
114
|
+
* the whole value-mapping contract would go unexercised in CI.
|
|
115
|
+
*/
|
|
116
|
+
export async function copyStateData(source, target, opts) {
|
|
117
|
+
const batchSize = opts.batchSize && opts.batchSize > 0 ? Math.floor(opts.batchSize) : 500;
|
|
118
|
+
const started = Date.now();
|
|
119
|
+
const report = opts.onProgress ?? (() => { });
|
|
120
|
+
assertCoversEveryTable();
|
|
121
|
+
if (source.dialect !== "sqlite") {
|
|
122
|
+
throw new StateMigrationError(`Source must be a SQLite database (got dialect "${source.dialect}"). ` +
|
|
123
|
+
"Postgres → SQLite is not supported.", false);
|
|
124
|
+
}
|
|
125
|
+
if (target.dialect !== "postgres") {
|
|
126
|
+
throw new StateMigrationError(`Target must be a Postgres database (got dialect "${target.dialect}").`, false);
|
|
127
|
+
}
|
|
128
|
+
const srcTables = tablesOf(source.client);
|
|
129
|
+
const dstTables = tablesOf(target.client);
|
|
130
|
+
// Preflight EVERY table before writing any of them: discovering table 12 is
|
|
131
|
+
// occupied after 11 have been copied is the worst possible time to find out.
|
|
132
|
+
await preflightTarget(target.client, dstTables, opts);
|
|
133
|
+
report({ type: "start", tables: TABLE_ORDER.length });
|
|
134
|
+
const results = [];
|
|
135
|
+
for (const spec of TABLE_ORDER) {
|
|
136
|
+
try {
|
|
137
|
+
results.push(await copyTable(spec, source.client, target.client, srcTables, dstTables, {
|
|
138
|
+
batchSize,
|
|
139
|
+
dryRun: !!opts.dryRun,
|
|
140
|
+
report,
|
|
141
|
+
}));
|
|
142
|
+
}
|
|
143
|
+
catch (err) {
|
|
144
|
+
// Past the preflight, so earlier tables are already in the target.
|
|
145
|
+
throw new StateMigrationError(`Copying ${String(spec.key)} failed: ${describeError(err)}`, !opts.dryRun, { cause: err });
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
const totalRows = results.reduce((n, r) => n + r.copied, 0);
|
|
149
|
+
const durationMs = Date.now() - started;
|
|
150
|
+
report({ type: "done", totalRows, durationMs });
|
|
151
|
+
// The verification pass is not decoration: an insert that silently dropped
|
|
152
|
+
// rows (a partial batch, a swallowed conflict) is invisible otherwise.
|
|
153
|
+
const mismatched = results.filter((r) => !opts.dryRun && r.target !== r.source);
|
|
154
|
+
if (mismatched.length) {
|
|
155
|
+
throw new StateMigrationError("Row-count verification failed after copying — the target does not match the source: " +
|
|
156
|
+
mismatched.map((r) => `${r.table} (${r.source} → ${r.target})`).join(", "), true);
|
|
157
|
+
}
|
|
158
|
+
return { tables: results, totalRows, durationMs, dryRun: !!opts.dryRun };
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* A hand-maintained table list silently skips whatever is added after it was
|
|
162
|
+
* written, and a state migration that skips a table destroys data without
|
|
163
|
+
* erroring. So the list is checked against the schema's own exports on every
|
|
164
|
+
* run — `schema/sqlite.ts` is the source of truth, and adding a table there
|
|
165
|
+
* fails this loudly until it is placed in {@link TABLE_ORDER} at an
|
|
166
|
+
* FK-respecting position.
|
|
167
|
+
*/
|
|
168
|
+
export function assertCoversEveryTable() {
|
|
169
|
+
const declared = new Set(TABLE_ORDER.map((s) => s.key));
|
|
170
|
+
const actual = Object.entries(sqliteSchema)
|
|
171
|
+
.filter(([, value]) => is(value, Table))
|
|
172
|
+
.map(([name]) => name);
|
|
173
|
+
const missing = actual.filter((name) => !declared.has(name));
|
|
174
|
+
const stale = [...declared].filter((name) => !actual.includes(name));
|
|
175
|
+
if (missing.length || stale.length) {
|
|
176
|
+
throw new Error("data-migrate's TABLE_ORDER is out of sync with schema/sqlite.ts" +
|
|
177
|
+
(missing.length ? ` — not copied: ${missing.join(", ")}` : "") +
|
|
178
|
+
(stale.length ? ` — no longer in the schema: ${stale.join(", ")}` : "") +
|
|
179
|
+
". Add each new table in an order its foreign keys allow.");
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* The empty-target rule (or the `--truncate` escape hatch).
|
|
184
|
+
*
|
|
185
|
+
* Deletes in REVERSE {@link TABLE_ORDER}, so `messaging_messages` goes before
|
|
186
|
+
* the `messaging_sessions` rows it references.
|
|
187
|
+
*/
|
|
188
|
+
async function preflightTarget(client, dstTables, opts) {
|
|
189
|
+
if (opts.dryRun)
|
|
190
|
+
return;
|
|
191
|
+
if (opts.truncate) {
|
|
192
|
+
for (const spec of [...TABLE_ORDER].reverse()) {
|
|
193
|
+
await client.delete(tableOf(dstTables, spec.key));
|
|
194
|
+
}
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
const occupied = [];
|
|
198
|
+
for (const spec of TABLE_ORDER) {
|
|
199
|
+
const table = tableOf(dstTables, spec.key);
|
|
200
|
+
if ((await countRows(client, table)) > 0)
|
|
201
|
+
occupied.push(tableName(table));
|
|
202
|
+
}
|
|
203
|
+
if (occupied.length) {
|
|
204
|
+
throw new StateMigrationError(`Target database is not empty (${occupied.join(", ")}). ` +
|
|
205
|
+
"Migrate into a fresh database, or pass --truncate to delete the existing rows first.", false);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
async function copyTable(spec, srcClient, dstClient, srcTables, dstTables, { batchSize, dryRun, report }) {
|
|
209
|
+
const srcTable = tableOf(srcTables, spec.key);
|
|
210
|
+
const dstTable = tableOf(dstTables, spec.key);
|
|
211
|
+
const name = tableName(srcTable);
|
|
212
|
+
const sourceRows = await countRows(srcClient, srcTable);
|
|
213
|
+
report({ type: "table-start", table: name, rows: sourceRows });
|
|
214
|
+
let copied = 0;
|
|
215
|
+
if (!dryRun && sourceRows > 0) {
|
|
216
|
+
const order = spec.orderBy.map((prop) => asc(columnOf(srcTable, prop)));
|
|
217
|
+
for (let offset = 0; offset < sourceRows; offset += batchSize) {
|
|
218
|
+
// Keyset pagination would be faster, but the order columns differ per
|
|
219
|
+
// table (three of them are composite) and these are one-shot migrations
|
|
220
|
+
// over tens of thousands of rows. LIMIT/OFFSET over a stable total order
|
|
221
|
+
// is correct, and correctness is what matters here.
|
|
222
|
+
const batch = (await srcClient
|
|
223
|
+
.select()
|
|
224
|
+
.from(srcTable)
|
|
225
|
+
.orderBy(...order)
|
|
226
|
+
.limit(batchSize)
|
|
227
|
+
.offset(offset));
|
|
228
|
+
if (!batch.length)
|
|
229
|
+
break;
|
|
230
|
+
const values = spec.omit
|
|
231
|
+
? batch.map((row) => omitKeys(row, spec.omit))
|
|
232
|
+
: batch;
|
|
233
|
+
await dstClient.insert(dstTable).values(values);
|
|
234
|
+
copied += batch.length;
|
|
235
|
+
report({ type: "batch", table: name, copied, rows: sourceRows });
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
report({ type: "table-done", table: name, copied });
|
|
239
|
+
return {
|
|
240
|
+
table: name,
|
|
241
|
+
source: sourceRows,
|
|
242
|
+
copied,
|
|
243
|
+
target: dryRun ? 0 : await countRows(dstClient, dstTable),
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* The message a human can act on, from anywhere in the cause chain.
|
|
248
|
+
*
|
|
249
|
+
* Drizzle wraps every driver error in a `DrizzleQueryError` whose message is
|
|
250
|
+
* just the SQL it was running, so the actual reason — "password authentication
|
|
251
|
+
* failed", "no such table" — is one or two levels down. Reporting only the top
|
|
252
|
+
* of the chain turns every failure into "Failed query: select 1".
|
|
253
|
+
*/
|
|
254
|
+
export function describeError(error) {
|
|
255
|
+
const parts = [];
|
|
256
|
+
for (let e = error, depth = 0; e != null && depth < 6; depth++) {
|
|
257
|
+
const message = e.message;
|
|
258
|
+
if (message && !parts.includes(message))
|
|
259
|
+
parts.push(message);
|
|
260
|
+
e = e.cause;
|
|
261
|
+
}
|
|
262
|
+
if (!parts.length)
|
|
263
|
+
return String(error);
|
|
264
|
+
if (parts.length === 1)
|
|
265
|
+
return parts[0];
|
|
266
|
+
// The innermost cause is the reason; the outermost is which query was
|
|
267
|
+
// running, worth keeping but only its first line — Drizzle appends the full
|
|
268
|
+
// statement and a `params:` dump, which buries the reason it wraps.
|
|
269
|
+
return `${parts.at(-1)} (while running: ${parts[0].split("\n")[0]})`;
|
|
270
|
+
}
|
|
271
|
+
function omitKeys(row, keys) {
|
|
272
|
+
const out = {};
|
|
273
|
+
for (const [k, v] of Object.entries(row))
|
|
274
|
+
if (!keys.includes(k))
|
|
275
|
+
out[k] = v;
|
|
276
|
+
return out;
|
|
277
|
+
}
|
|
278
|
+
async function countRows(client, table) {
|
|
279
|
+
const [row] = (await client
|
|
280
|
+
.select({ n: sql `count(*)` })
|
|
281
|
+
.from(table));
|
|
282
|
+
// int8 arrives as a string from a real pg driver without the OID-20 parser;
|
|
283
|
+
// `makePgClient` registers it, but this must not depend on that to be right.
|
|
284
|
+
return Number(row?.n ?? 0);
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* The schema objects are resolved per dialect off the client (`tablesOf`), so
|
|
288
|
+
* they are only weakly typed at this level — the two schemas mirror each other
|
|
289
|
+
* export-for-export (`schema-parity.test.ts` is the guard), which is what makes
|
|
290
|
+
* indexing one with the other's key sound.
|
|
291
|
+
*/
|
|
292
|
+
function tableOf(tables, key) {
|
|
293
|
+
const table = tables[key];
|
|
294
|
+
if (!table || !is(table, Table)) {
|
|
295
|
+
throw new Error(`Schema has no table export "${String(key)}" — schemas out of sync.`);
|
|
296
|
+
}
|
|
297
|
+
return table;
|
|
298
|
+
}
|
|
299
|
+
function columnOf(table, prop) {
|
|
300
|
+
const column = table[prop];
|
|
301
|
+
if (!column) {
|
|
302
|
+
throw new Error(`Table ${tableName(table)} has no column property "${prop}".`);
|
|
303
|
+
}
|
|
304
|
+
return column;
|
|
305
|
+
}
|
|
306
|
+
function tableName(table) {
|
|
307
|
+
return table[Table.Symbol.Name];
|
|
308
|
+
}
|
|
309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