@cosmicdrift/kumiko-framework 0.122.0 → 0.122.1

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": "@cosmicdrift/kumiko-framework",
3
- "version": "0.122.0",
3
+ "version": "0.122.1",
4
4
  "description": "Framework core — engine, pipeline, API, DB, and every other bit that makes Kumiko go.",
5
5
  "license": "BUSL-1.1",
6
6
  "author": "Marc Frost <marc@cosmicdriftgamestudio.com>",
@@ -189,7 +189,7 @@
189
189
  "zod": "^4.4.3"
190
190
  },
191
191
  "devDependencies": {
192
- "@cosmicdrift/kumiko-dispatcher-live": "0.122.0",
192
+ "@cosmicdrift/kumiko-dispatcher-live": "0.122.1",
193
193
  "bun-types": "^1.3.13",
194
194
  "pino-pretty": "^13.1.3"
195
195
  },
@@ -28,14 +28,16 @@ function tmpDir(): string {
28
28
  }
29
29
 
30
30
  describe("rebuildTablesFromDiff", () => {
31
- test("managed: new + changed tables included, dropped excluded, sorted + unique", () => {
31
+ test("managed: new table rebuilt, additive-only change NOT rebuilt, dropped excluded", () => {
32
+ // read_a: nur eine nullable Spalte dazu → in-place ALTER, kein Rebuild.
33
+ // read_b: neue Tabelle → Rebuild. read_c gedroppt → nie im Marker.
32
34
  const prev = snapshotFromMetas([meta("read_a"), meta("read_c")]);
33
35
  const next = snapshotFromMetas([
34
36
  meta("read_a", { name: "title", pgType: "text", notNull: false }),
35
37
  meta("read_b"),
36
38
  ]);
37
39
  const diff = diffSnapshots(prev, next);
38
- expect(rebuildTablesFromDiff(diff)).toEqual(["read_a", "read_b"]);
40
+ expect(rebuildTablesFromDiff(diff)).toEqual(["read_b"]);
39
41
  });
40
42
 
41
43
  test("no schema change → empty", () => {
@@ -51,11 +53,19 @@ describe("rebuildTablesFromDiff", () => {
51
53
  expect(rebuildTablesFromDiff(diffSnapshots(prev, next))).toEqual([]);
52
54
  });
53
55
 
54
- test("managed new nullable column → rebuild (Backfill aus Events nötig)", () => {
56
+ test("managed new NULLABLE column → NO rebuild (in-place ADD COLUMN reicht; Rebuild würde die Spalte wischen, #835)", () => {
55
57
  const prev = snapshotFromMetas([meta("read_a")]);
56
58
  const next = snapshotFromMetas([
57
59
  meta("read_a", { name: "title", pgType: "text", notNull: false }),
58
60
  ]);
61
+ expect(rebuildTablesFromDiff(diffSnapshots(prev, next))).toEqual([]);
62
+ });
63
+
64
+ test("managed new NOT-NULL column ohne Default → rebuild (recreate, kann nicht in-place)", () => {
65
+ const prev = snapshotFromMetas([meta("read_a")]);
66
+ const next = snapshotFromMetas([
67
+ meta("read_a", { name: "title", pgType: "text", notNull: true }),
68
+ ]);
59
69
  expect(rebuildTablesFromDiff(diffSnapshots(prev, next))).toEqual(["read_a"]);
60
70
  });
61
71
 
@@ -32,12 +32,28 @@ function markerPathFor(migrationsDir: string, migrationId: string): string {
32
32
  return join(migrationsDir, `${migrationId}.rebuild.json`);
33
33
  }
34
34
 
35
- // Only managed tables (event-stream derivatives) get rebuild markers — unmanaged carry real data, never rebuilt from events; sorted+deduped for stable PR diff.
35
+ // Only managed tables (event-stream derivatives) get rebuild markers — unmanaged
36
+ // carry real data, never rebuilt from events; sorted+deduped for stable PR diff.
37
+ //
38
+ // A changed table needs a rebuild ONLY when the generated SQL RECREATES it
39
+ // (managedChangeRequiresRecreate: drop/NOT-NULL-w/o-default/unique-index/type-
40
+ // or nullability-change) — then the table is emptied and must be re-derived from
41
+ // events. A pure additive nullable column is an in-place `ADD COLUMN` ALTER that
42
+ // already brings the table to the target state (same logic #181 applied to
43
+ // index-/default-only changes). Rebuilding it anyway is wasted replay AND — the
44
+ // bug this closes — a co-triggered rebuild can drop the fresh column (rebuild
45
+ // runs from the rebuilding process's registry meta; on a rolling deploy an older
46
+ // pod's meta lacks the column → shadow-swap wipes it → phantom migration + boot-
47
+ // drift crash; see 0008_add_pending_deletion_request_id / #494 / #835).
48
+ //
49
+ // If a NEW additive column genuinely needs value-backfill from historical events
50
+ // (a column DERIVED from existing event fields), opt in explicitly by hand-adding
51
+ // a `NNNN_<name>.rebuild.json` next to the migration (readRebuildMarker reads it).
36
52
  export function rebuildTablesFromDiff(diff: SchemaDiff): readonly string[] {
37
53
  const names = new Set<string>();
38
54
  for (const t of diff.changedTables) {
39
55
  if (t.nextMeta.source !== "managed") continue;
40
- if (t.newColumns.length > 0 || managedChangeRequiresRecreate(t)) names.add(t.tableName);
56
+ if (managedChangeRequiresRecreate(t)) names.add(t.tableName);
41
57
  }
42
58
  for (const t of diff.newTables) {
43
59
  if (t.source === "managed") names.add(t.tableName);