@catalyst-cloud/schema 0.1.33 → 0.1.34

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@catalyst-cloud/schema",
3
- "version": "0.1.33",
3
+ "version": "0.1.34",
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",
@@ -242,6 +242,13 @@ export const MIRROR_MIGRATIONS = {
242
242
  tag: "0032_elite_donald_blake",
243
243
  breakpoints: true,
244
244
  },
245
+ {
246
+ idx: 33,
247
+ version: "6",
248
+ when: 1788282183348,
249
+ tag: "0033_lethal_electro",
250
+ breakpoints: true,
251
+ },
245
252
  ],
246
253
  },
247
254
  migrations: {
@@ -308,5 +315,7 @@ export const MIRROR_MIGRATIONS = {
308
315
  "-- CTC-851 — backfill comment parents + quarantine the pre-fix empty-issue_id orphans.\n--\n-- 0030 adds the parent_type/parent_entity_id columns and fixes both WRITE legs (webhook normalizer +\n-- reconcile) so new/re-swept comments carry a real parent, but that alone converges only rows the\n-- reconcile re-sweeps — and it walks OPEN issues, so a non-issue comment (or a comment on a closed\n-- issue) keeps its corrupt shape forever. This backfill is what makes the CORPUS canonical rather\n-- than just the new writes.\n--\n-- ⭐ Deliberately a DATA migration in the SHARED bundle (the 0014 pattern): the DO and every host /\n-- OPFS replica apply the same MIRROR_MIGRATIONS through the same runner, so each side repairs its OWN\n-- rows locally. That converges every replica WITHOUT emitting a change_log delta per row (migrations\n-- bypass appendChange), so no ring-buffer flood (the CTC-279 concern).\n--\n-- (a) Healthy rows (a real issue_id) → parent_type='issue', parent_entity_id=issue_id.\n-- (b) Orphans (issue_id empty-string — the measured shape — or NULL, defensively) cannot be repaired\n-- from row data: the replica comments table has no `raw` column and no parent signal beyond the\n-- comment-reply parent_id. A pure in-bundle DML migration cannot call Linear, so it QUARANTINES\n-- them: parent_type='unresolved', issue_id nulled — MARKED with a stated reason, never deleted\n-- (the AC explicitly permits quarantine-with-reason). CTC-851 measured 54 such rows live.\n--\n-- Idempotent by the `parent_type IS NULL` guard: once a row is stamped it is skipped on replay, so a\n-- crash between a statement succeeding and its tag being recorded (execReplaySafe) is safe.\nUPDATE `comments`\n SET `parent_type` = 'issue', `parent_entity_id` = `issue_id`\n WHERE `parent_type` IS NULL AND `issue_id` IS NOT NULL AND `issue_id` <> '';\n--> statement-breakpoint\nUPDATE `comments`\n SET `parent_type` = 'unresolved', `issue_id` = NULL\n WHERE `parent_type` IS NULL AND (`issue_id` = '' OR `issue_id` IS NULL);\n",
309
316
  "0032_elite_donald_blake":
310
317
  "ALTER TABLE `issues` ADD `creator_id` text;--> statement-breakpoint\nALTER TABLE `issues` ADD `creator_name` text;--> statement-breakpoint\nALTER TABLE `issues` ADD `creator_avatar_url` text;",
318
+ "0033_lethal_electro":
319
+ "ALTER TABLE `labels` ADD `team_id` text;--> statement-breakpoint\nCREATE INDEX `idx_labels_team` ON `labels` (`team_id`);",
311
320
  },
312
321
  } as const;
package/src/mirror.ts CHANGED
@@ -101,13 +101,24 @@ export const issues = sqliteTable(
101
101
  ],
102
102
  );
103
103
 
104
- export const labels = sqliteTable("labels", {
105
- id: text("id").primaryKey(),
106
- name: text("name"),
107
- color: text("color"),
108
- updated_at: integer("updated_at"),
109
- removed_at: integer("removed_at"),
110
- });
104
+ // CTC-1088: `team_id` is nullable and ADVISORY, never a gate — NULL means "workspace-scoped, or not
105
+ // yet stamped by the authoritative sweep" (an ambiguity the org-wide reconcile leg bounds to one pass,
106
+ // since it fetches `team { id }` and re-stamps every label every sweep — ADR-0022). Written UNCONDITIONALLY
107
+ // only by that reconcile leg; a webhook or issue-nested label upsert OMITS the column entirely rather
108
+ // than writing null over a real value — the SAME `users.email` precedent this file already documents
109
+ // (see users, above), made safe by `upsertRow`'s `Object.keys(row)` column derivation (do/upsert.ts).
110
+ export const labels = sqliteTable(
111
+ "labels",
112
+ {
113
+ id: text("id").primaryKey(),
114
+ team_id: text("team_id"),
115
+ name: text("name"),
116
+ color: text("color"),
117
+ updated_at: integer("updated_at"),
118
+ removed_at: integer("removed_at"),
119
+ },
120
+ (t) => [index("idx_labels_team").on(t.team_id)],
121
+ );
111
122
 
112
123
  // Teammate identities (CTC-USERS): resolves issue assignees + delegate AGENTS (and comment/PR
113
124
  // authors/reviewers) to a name + avatar so the UI never renders a gray "Unknown" chip. AGENT