@catalyst-cloud/schema 0.1.54 → 0.1.55
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/package.json +2 -2
- package/src/migrations.generated.ts +9 -0
- package/src/mirror.ts +12 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@catalyst-cloud/schema",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.55",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Typed Drizzle schema = single source of truth for the per-tenant Mirror DO SQLite store (CTC-13 / ADR-0002). Shared by the mirror Worker, the host-sync replica, and the browser OPFS replica.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@catalyst-cloud/typescript-config": "workspace:*",
|
|
34
|
-
"@types/node": "^26.
|
|
34
|
+
"@types/node": "^26.5.1",
|
|
35
35
|
"drizzle-kit": "^0.31.0",
|
|
36
36
|
"prettier": "^3.9.6",
|
|
37
37
|
"typescript": "^7.0.2",
|
|
@@ -298,6 +298,13 @@ export const MIRROR_MIGRATIONS = {
|
|
|
298
298
|
tag: "0040_ctc1885_workflow_state_name_backfill",
|
|
299
299
|
breakpoints: true,
|
|
300
300
|
},
|
|
301
|
+
{
|
|
302
|
+
idx: 41,
|
|
303
|
+
version: "6",
|
|
304
|
+
when: 1790195407572,
|
|
305
|
+
tag: "0041_many_marvel_boy",
|
|
306
|
+
breakpoints: true,
|
|
307
|
+
},
|
|
301
308
|
],
|
|
302
309
|
},
|
|
303
310
|
migrations: {
|
|
@@ -380,5 +387,7 @@ export const MIRROR_MIGRATIONS = {
|
|
|
380
387
|
"CREATE TABLE `flow_daily` (\n\t`repo_id` text NOT NULL,\n\t`day` text NOT NULL,\n\t`active_count` integer NOT NULL,\n\t`entries` integer NOT NULL,\n\t`exits_to_done` integer NOT NULL,\n\t`exits_to_canceled` integer NOT NULL,\n\t`stage_counts` text,\n\t`aging_p50_seconds` integer,\n\t`aging_p90_seconds` integer,\n\t`fleet_active_count` integer,\n\t`fleet_exits_to_done` integer,\n\t`fleet_cycle_p50_seconds` integer,\n\t`fleet_cycle_p90_seconds` integer,\n\t`interactive_active_count` integer,\n\t`interactive_exits_to_done` integer,\n\t`interactive_cycle_p50_seconds` integer,\n\t`interactive_cycle_p90_seconds` integer,\n\t`stalled_count` integer,\n\t`estimated_ticket_count` integer,\n\t`open_pr_count` integer,\n\t`open_pr_draft_count` integer,\n\t`prs_merged` integer,\n\t`pr_cycle_p50_seconds` integer,\n\t`pr_cycle_p90_seconds` integer,\n\t`pr_age_p50_seconds` integer,\n\t`pr_age_p90_seconds` integer,\n\t`computed_at` integer NOT NULL,\n\tPRIMARY KEY(`repo_id`, `day`)\n);\n--> statement-breakpoint\nCREATE INDEX `idx_flow_daily_day` ON `flow_daily` (`day`);",
|
|
381
388
|
"0040_ctc1885_workflow_state_name_backfill":
|
|
382
389
|
"-- CTC-1885 — re-stamp cached workflow-state NAMES from the authoritative workflow_states row, by\n-- stable state id.\n--\n-- ⭐ Deliberately a pure DATA migration in the SHARED bundle (the 0014/0031/0037 pattern): the DO\n-- and every host / OPFS replica apply the same MIRROR_MIGRATIONS through the same runner, so each\n-- store repairs its OWN rows locally. That converges the already-stale corpus WITHOUT emitting a\n-- change_log delta per historical row (migrations bypass appendChange), so the 200k-row / 7-day ring\n-- buffer is not flooded by the very backlog this repairs, and a replica that was OFFLINE at deploy\n-- time heals itself the moment it next opens and applies the bundle.\n--\n-- The defect: `issues.state` is denormalized at issue ingest and `team_workflow_mapping.\n-- linear_state_name` at mapping projection, while `workflow_states.name` is written by the\n-- workflow-state sweep. A Linear rename (Triage -> Intake) updated only the latter, so issues kept\n-- answering the OLD name (/api/v1/issues returns the column verbatim; the board keys columns by it)\n-- and the mapping kept displaying it. Runtime cascade (this ticket's reconcile change) covers FUTURE\n-- renames; THIS migration repairs every row already stale at upgrade time, including on stores the\n-- runtime never gets to replay.\n--\n-- Matching is by STABLE ID, never by the mutable old string (the table's own header: the name is a\n-- display snapshot, never a lookup key — a same-named row under a different state id must not move):\n-- • issues: `issues.state_id` -> `workflow_states.id`. The state id is globally unique (Linear\n-- UUID), which IS the team scoping — an issue's state belongs to exactly one team's workflow.\n-- • team_workflow_mapping: `linear_state_id` AND `team_id` both resolve. The mapping's team fence\n-- is kept because a Linear-to-Linear import can re-mint ids per team (CTC-403).\n-- Both updates are guarded by `ws.name IS NOT <cached>` so already-converged rows are untouched and\n-- a replay (execReplaySafe re-runs a statement after a crash between success and tag-record) is a\n-- no-op. `IS` / `IS NOT` keep every comparison NULL-safe.\n--\n-- ⛔ NO timestamps, revisions, or tombstones are rewritten: `updated_at`, `workflow_rev`, and\n-- `removed_at` survive exactly as stored. A state rename is provider-owned state metadata, not an\n-- issue mutation and not a tenant mapping decision; advancing those fields would corrupt freshness,\n-- board ranking, last-write-wins ordering, and the host workflow-rev receipt. Only the NAME fields\n-- converge. (Tombstoned mapping rows converge too — a dead row's display snapshot changing is\n-- unobservable and emits nothing; the runtime cascade, which DOES emit deltas, stays live-only.)\nUPDATE `issues`\n SET `state` = (SELECT `ws`.`name` FROM `workflow_states` `ws` WHERE `ws`.`id` = `issues`.`state_id`)\n WHERE EXISTS (\n SELECT 1 FROM `workflow_states` `ws`\n WHERE `ws`.`id` = `issues`.`state_id`\n AND `ws`.`name` IS NOT NULL\n AND `ws`.`name` IS NOT `issues`.`state`);\n--> statement-breakpoint\nUPDATE `team_workflow_mapping`\n SET `linear_state_name` = (SELECT `ws`.`name`\n FROM `workflow_states` `ws`\n WHERE `ws`.`id` = `team_workflow_mapping`.`linear_state_id`\n AND `ws`.`team_id` = `team_workflow_mapping`.`team_id`)\n WHERE EXISTS (\n SELECT 1 FROM `workflow_states` `ws`\n WHERE `ws`.`id` = `team_workflow_mapping`.`linear_state_id`\n AND `ws`.`team_id` = `team_workflow_mapping`.`team_id`\n AND `ws`.`name` IS NOT NULL\n AND `ws`.`name` IS NOT `team_workflow_mapping`.`linear_state_name`);\n",
|
|
390
|
+
"0041_many_marvel_boy":
|
|
391
|
+
'-- CTC-3123: re-key flow_daily from (repo_id, day) to (project_id, day), so a per-project Flow page\n-- never double-counts a repo that two projects share (ADR-0013\'s project_repos).\n--\n-- A table recreation, because SQLite cannot change a primary key in place. Two edits to the\n-- drizzle-kit output, both deliberate:\n-- • The copy writes `\'repo:\' || repo_id` into project_id. The repo-to-project map lives in the\n-- registry D1, not in this store, so a migration cannot know a row\'s project. The snapshot writer\n-- (apps/mirror/src/do/flow-snapshot.ts) re-stamps `repo:<owner>/<name>` rows to the real project\n-- id on its next pass. A repo with no registry project keeps the marker: still readable, never\n-- dropped, and counted by the flow route\'s `flow-daily-unkeyed-rows` log line.\n-- • No PRAGMA foreign_keys lines: flow_daily has no foreign keys, so toggling enforcement buys\n-- nothing, and no earlier migration in this bundle issues a pragma. The leading DROP of `__new_flow_daily` makes a replay after a\n-- partial run start clean instead of colliding on the half-built table.\nDROP TABLE IF EXISTS `__new_flow_daily`;--> statement-breakpoint\nCREATE TABLE `__new_flow_daily` (\n\t`project_id` text NOT NULL,\n\t`repo_id` text NOT NULL,\n\t`day` text NOT NULL,\n\t`active_count` integer NOT NULL,\n\t`entries` integer NOT NULL,\n\t`exits_to_done` integer NOT NULL,\n\t`exits_to_canceled` integer NOT NULL,\n\t`stage_counts` text,\n\t`aging_p50_seconds` integer,\n\t`aging_p90_seconds` integer,\n\t`fleet_active_count` integer,\n\t`fleet_exits_to_done` integer,\n\t`fleet_cycle_p50_seconds` integer,\n\t`fleet_cycle_p90_seconds` integer,\n\t`interactive_active_count` integer,\n\t`interactive_exits_to_done` integer,\n\t`interactive_cycle_p50_seconds` integer,\n\t`interactive_cycle_p90_seconds` integer,\n\t`stalled_count` integer,\n\t`estimated_ticket_count` integer,\n\t`open_pr_count` integer,\n\t`open_pr_draft_count` integer,\n\t`prs_merged` integer,\n\t`pr_cycle_p50_seconds` integer,\n\t`pr_cycle_p90_seconds` integer,\n\t`pr_age_p50_seconds` integer,\n\t`pr_age_p90_seconds` integer,\n\t`computed_at` integer NOT NULL,\n\tPRIMARY KEY(`project_id`, `day`)\n);\n--> statement-breakpoint\nINSERT INTO `__new_flow_daily`("project_id", "repo_id", "day", "active_count", "entries", "exits_to_done", "exits_to_canceled", "stage_counts", "aging_p50_seconds", "aging_p90_seconds", "fleet_active_count", "fleet_exits_to_done", "fleet_cycle_p50_seconds", "fleet_cycle_p90_seconds", "interactive_active_count", "interactive_exits_to_done", "interactive_cycle_p50_seconds", "interactive_cycle_p90_seconds", "stalled_count", "estimated_ticket_count", "open_pr_count", "open_pr_draft_count", "prs_merged", "pr_cycle_p50_seconds", "pr_cycle_p90_seconds", "pr_age_p50_seconds", "pr_age_p90_seconds", "computed_at") SELECT \'repo:\' || "repo_id", "repo_id", "day", "active_count", "entries", "exits_to_done", "exits_to_canceled", "stage_counts", "aging_p50_seconds", "aging_p90_seconds", "fleet_active_count", "fleet_exits_to_done", "fleet_cycle_p50_seconds", "fleet_cycle_p90_seconds", "interactive_active_count", "interactive_exits_to_done", "interactive_cycle_p50_seconds", "interactive_cycle_p90_seconds", "stalled_count", "estimated_ticket_count", "open_pr_count", "open_pr_draft_count", "prs_merged", "pr_cycle_p50_seconds", "pr_cycle_p90_seconds", "pr_age_p50_seconds", "pr_age_p90_seconds", "computed_at" FROM `flow_daily`;--> statement-breakpoint\nDROP TABLE `flow_daily`;--> statement-breakpoint\nALTER TABLE `__new_flow_daily` RENAME TO `flow_daily`;--> statement-breakpoint\nCREATE INDEX `idx_flow_daily_day` ON `flow_daily` (`day`);',
|
|
383
392
|
},
|
|
384
393
|
} as const;
|
package/src/mirror.ts
CHANGED
|
@@ -1495,8 +1495,8 @@ export const fleet_health_sends = sqliteTable(
|
|
|
1495
1495
|
* already carries, so broadcasting it account-wide would put a recomputable aggregate on every host
|
|
1496
1496
|
* replica and every browser OPFS DB for no reader.
|
|
1497
1497
|
*
|
|
1498
|
-
* ⚠️ NO `tenant_id` — the DO IS the tenant (this file's header). The
|
|
1499
|
-
*
|
|
1498
|
+
* ⚠️ NO `tenant_id` — the DO IS the tenant (this file's header). The key is (project_id, day) since
|
|
1499
|
+
* CTC-3123; it was (repo_id, day) before.
|
|
1500
1500
|
*
|
|
1501
1501
|
* ⭐ EVERY DURATION IS SECONDS, and every column that holds one says so in its name (`*_seconds`). The
|
|
1502
1502
|
* ticket's adaptive-rendering rule (minutes as the fleet improves) lives in the client; the store never
|
|
@@ -1505,6 +1505,15 @@ export const fleet_health_sends = sqliteTable(
|
|
|
1505
1505
|
export const flow_daily = sqliteTable(
|
|
1506
1506
|
"flow_daily",
|
|
1507
1507
|
{
|
|
1508
|
+
/**
|
|
1509
|
+
* CTC-3123: the registry project id (`projects.id`, e.g. `tenant-0:catalyst`), the row's key with
|
|
1510
|
+
* `day`. Keyed by project, not repo, so a repo shared by two projects (ADR-0013's `project_repos`)
|
|
1511
|
+
* never double-counts on a per-project Flow page. A row carried over from the repo-keyed table by
|
|
1512
|
+
* migration 0041 holds `repo:<owner>/<name>` until the snapshot writer re-stamps it
|
|
1513
|
+
* (`flow-snapshot.ts`); a repo with no registry project keeps that marker and stays readable.
|
|
1514
|
+
*/
|
|
1515
|
+
project_id: text("project_id").notNull(),
|
|
1516
|
+
/** `owner/name` of the project's repository. Descriptive since CTC-3123, no longer the key. */
|
|
1508
1517
|
repo_id: text("repo_id").notNull(),
|
|
1509
1518
|
/** UTC `YYYY-MM-DD` — `utcDayString`, never a raw timestamp (write-budget.ts's boundary rule). */
|
|
1510
1519
|
day: text("day").notNull(),
|
|
@@ -1540,5 +1549,5 @@ export const flow_daily = sqliteTable(
|
|
|
1540
1549
|
},
|
|
1541
1550
|
// The index lives in the Drizzle SSOT ONLY (NOT schema.sql) — migrate.ts's generated CREATE INDEX is
|
|
1542
1551
|
// replay-safe; schema.sql would break the adoption test (the same rule idx_issues_sort_order states).
|
|
1543
|
-
(t) => [primaryKey({ columns: [t.
|
|
1552
|
+
(t) => [primaryKey({ columns: [t.project_id, t.day] }), index("idx_flow_daily_day").on(t.day)],
|
|
1544
1553
|
);
|