@cosmicdrift/kumiko-framework 0.121.1 → 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.
|
|
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>",
|
|
@@ -135,6 +135,10 @@
|
|
|
135
135
|
"types": "./src/crypto/index.ts",
|
|
136
136
|
"default": "./src/crypto/index.ts"
|
|
137
137
|
},
|
|
138
|
+
"./logging": {
|
|
139
|
+
"types": "./src/logging/index.ts",
|
|
140
|
+
"default": "./src/logging/index.ts"
|
|
141
|
+
},
|
|
138
142
|
"./schema-cli": {
|
|
139
143
|
"types": "./src/schema-cli.ts",
|
|
140
144
|
"default": "./src/schema-cli.ts"
|
|
@@ -185,7 +189,7 @@
|
|
|
185
189
|
"zod": "^4.4.3"
|
|
186
190
|
},
|
|
187
191
|
"devDependencies": {
|
|
188
|
-
"@cosmicdrift/kumiko-dispatcher-live": "0.
|
|
192
|
+
"@cosmicdrift/kumiko-dispatcher-live": "0.122.1",
|
|
189
193
|
"bun-types": "^1.3.13",
|
|
190
194
|
"pino-pretty": "^13.1.3"
|
|
191
195
|
},
|
|
@@ -28,14 +28,16 @@ function tmpDir(): string {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
describe("rebuildTablesFromDiff", () => {
|
|
31
|
-
test("managed: new
|
|
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(["
|
|
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
|
|
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
|
|
|
@@ -23,12 +23,19 @@ export async function selectEventsForProjectionRebuildBatch(
|
|
|
23
23
|
afterId: bigint,
|
|
24
24
|
limit: number,
|
|
25
25
|
): Promise<ReadonlyArray<Record<string, unknown>>> {
|
|
26
|
+
// Archived streams don't replay (Marten-aligned): their aggregates are
|
|
27
|
+
// frozen ops-tombstones — replaying them would resurrect rows (or, for
|
|
28
|
+
// stranded duplicate-aggregates like fw#832, collide on unique indexes).
|
|
26
29
|
return (await asRawClient(db).unsafe(
|
|
27
|
-
`SELECT * FROM "kumiko_events"
|
|
28
|
-
WHERE "aggregate_type" = ANY($1::text[])
|
|
29
|
-
AND "type" = ANY($2::text[])
|
|
30
|
-
AND "id" > $3
|
|
31
|
-
|
|
30
|
+
`SELECT * FROM "kumiko_events" e
|
|
31
|
+
WHERE e."aggregate_type" = ANY($1::text[])
|
|
32
|
+
AND e."type" = ANY($2::text[])
|
|
33
|
+
AND e."id" > $3
|
|
34
|
+
AND NOT EXISTS (
|
|
35
|
+
SELECT 1 FROM "kumiko_archived_streams" a
|
|
36
|
+
WHERE a."tenant_id" = e."tenant_id" AND a."aggregate_id" = e."aggregate_id"
|
|
37
|
+
)
|
|
38
|
+
ORDER BY e."id" ASC
|
|
32
39
|
LIMIT $4`,
|
|
33
40
|
[aggregateTypes, eventTypes, afterId, limit],
|
|
34
41
|
)) as ReadonlyArray<Record<string, unknown>>;
|
|
@@ -43,10 +50,17 @@ export async function countSubscribedEvents(
|
|
|
43
50
|
aggregateTypes: readonly string[],
|
|
44
51
|
eventTypes: readonly string[],
|
|
45
52
|
): Promise<bigint> {
|
|
53
|
+
// Same archived-streams exclusion as the batch query — the #443 recompute
|
|
54
|
+
// compares this count against applied events; a filter mismatch would make
|
|
55
|
+
// every rebuild with an archived stream loop the full-re-replay forever.
|
|
46
56
|
const rows = (await asRawClient(db).unsafe(
|
|
47
|
-
`SELECT count(*)::bigint AS n FROM "kumiko_events"
|
|
48
|
-
WHERE "aggregate_type" = ANY($1::text[])
|
|
49
|
-
AND "type" = ANY($2::text[])
|
|
57
|
+
`SELECT count(*)::bigint AS n FROM "kumiko_events" e
|
|
58
|
+
WHERE e."aggregate_type" = ANY($1::text[])
|
|
59
|
+
AND e."type" = ANY($2::text[])
|
|
60
|
+
AND NOT EXISTS (
|
|
61
|
+
SELECT 1 FROM "kumiko_archived_streams" a
|
|
62
|
+
WHERE a."tenant_id" = e."tenant_id" AND a."aggregate_id" = e."aggregate_id"
|
|
63
|
+
)`,
|
|
50
64
|
[aggregateTypes, eventTypes],
|
|
51
65
|
)) as ReadonlyArray<{ n: bigint | string | number | null }>;
|
|
52
66
|
const raw = rows[0]?.n;
|
package/src/db/rebuild-marker.ts
CHANGED
|
@@ -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
|
|
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 (
|
|
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);
|
|
@@ -26,7 +26,7 @@ import {
|
|
|
26
26
|
defineFeature,
|
|
27
27
|
} from "../../engine";
|
|
28
28
|
import type { ProjectionDefinition } from "../../engine/types";
|
|
29
|
-
import { createEventsTable } from "../../event-store";
|
|
29
|
+
import { archiveStream, createEventsTable } from "../../event-store";
|
|
30
30
|
import {
|
|
31
31
|
createProjectionStateTable,
|
|
32
32
|
getAllProjectionProgress,
|
|
@@ -116,7 +116,7 @@ afterAll(async () => {
|
|
|
116
116
|
|
|
117
117
|
beforeEach(async () => {
|
|
118
118
|
await asRawClient(testDb.db).unsafe(
|
|
119
|
-
`TRUNCATE kumiko_events, read_rebuild_items, read_rebuild_items_per_group, kumiko_projections RESTART IDENTITY CASCADE`,
|
|
119
|
+
`TRUNCATE kumiko_events, read_rebuild_items, read_rebuild_items_per_group, kumiko_projections, kumiko_archived_streams RESTART IDENTITY CASCADE`,
|
|
120
120
|
);
|
|
121
121
|
});
|
|
122
122
|
|
|
@@ -210,6 +210,36 @@ describe("rebuildProjection — happy path", () => {
|
|
|
210
210
|
expect(result.eventsProcessed).toBe(0);
|
|
211
211
|
expect(result.lastProcessedEventId).toBe(0n);
|
|
212
212
|
});
|
|
213
|
+
|
|
214
|
+
test("archived streams don't replay (fw#832) — stranded aggregate heals via archiveStream", async () => {
|
|
215
|
+
// Heilungs-Muster fuer eventlose Read-Side-Deletes im Bestand: ein
|
|
216
|
+
// Aggregat, dessen Live-Row (vor dem fw#832-Fix) read-side entfernt
|
|
217
|
+
// wurde, hinterlaesst ein created-Event ohne deleted — jeder Rebuild
|
|
218
|
+
// wuerde die Row resurrecten (bzw. an unique-Indexen kollidieren).
|
|
219
|
+
// archiveStream friert den Stream ein UND nimmt ihn aus dem Replay.
|
|
220
|
+
const group = "00000000-0000-4000-8000-000000000020";
|
|
221
|
+
const stranded = await executor.create({ groupId: group, name: "stranded" }, admin, tdb);
|
|
222
|
+
if (!stranded.isSuccess) throw new Error("create failed");
|
|
223
|
+
await appendCreatedEvent(group, "survivor");
|
|
224
|
+
|
|
225
|
+
await archiveStream(testDb.db, {
|
|
226
|
+
tenantId: admin.tenantId,
|
|
227
|
+
aggregateId: String(stranded.data.id),
|
|
228
|
+
aggregateType: "rebuild-item",
|
|
229
|
+
archivedBy: "fw832-heal-test",
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
const result = await rebuildProjection(qualifiedProjectionName, {
|
|
233
|
+
db: testDb.db,
|
|
234
|
+
registry,
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
// Nur das survivor-Event replayed; das archivierte Aggregat traegt
|
|
238
|
+
// nicht mehr bei — auch nicht im #443-ground-truth-count (sonst
|
|
239
|
+
// wuerde der Recompute-Pfad endlos nachziehen).
|
|
240
|
+
expect(result.eventsProcessed).toBe(1);
|
|
241
|
+
expect(await getCount(group)).toBe(1);
|
|
242
|
+
});
|
|
213
243
|
});
|
|
214
244
|
|
|
215
245
|
describe("rebuildProjection — state table lifecycle", () => {
|