@nymbalhq/platform 1.2.0 → 1.3.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/dist/{chunk-UBEGSSFI.js → chunk-2PLYK5RU.js} +567 -38
- package/dist/chunk-2PLYK5RU.js.map +1 -0
- package/dist/{chunk-XVUH34US.js → chunk-QN56IB4G.js} +11 -3
- package/dist/chunk-QN56IB4G.js.map +1 -0
- package/dist/db/schema/index.d.ts +136 -0
- package/dist/db/schema/index.js +1 -1
- package/dist/index.d.ts +15 -0
- package/dist/index.js +96 -18
- package/dist/index.js.map +1 -1
- package/dist/register-UUQ64HZP.js +8 -0
- package/migrations/postgres/0012_event_subject.sql +27 -0
- package/migrations/postgres/meta/0012_snapshot.json +1926 -0
- package/migrations/postgres/meta/_journal.json +7 -0
- package/migrations/sqlite/0012_event_subject.sql +27 -0
- package/migrations/sqlite/meta/0012_snapshot.json +1728 -0
- package/migrations/sqlite/meta/_journal.json +7 -0
- package/package.json +19 -19
- package/dist/chunk-UBEGSSFI.js.map +0 -1
- package/dist/chunk-XVUH34US.js.map +0 -1
- package/dist/register-NHG3TIRQ.js +0 -8
- /package/dist/{register-NHG3TIRQ.js.map → register-UUQ64HZP.js.map} +0 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
-- Whose event each row is, so one record's history is an index range. The backfill mirrors `subjectOf`
|
|
2
|
+
-- (src/history/subject.ts): a subject needs a string id at the first path its type names, else the row has none.
|
|
3
|
+
ALTER TABLE "events" ADD COLUMN "subject_type" text;--> statement-breakpoint
|
|
4
|
+
ALTER TABLE "events" ADD COLUMN "subject_id" text;--> statement-breakpoint
|
|
5
|
+
UPDATE "events" SET
|
|
6
|
+
"subject_type" = CASE
|
|
7
|
+
WHEN starts_with("type", 'product.') THEN 'product'
|
|
8
|
+
WHEN starts_with("type", 'order.') OR starts_with("type", 'payment.') THEN 'order'
|
|
9
|
+
WHEN starts_with("type", 'customer.') THEN 'customer'
|
|
10
|
+
WHEN starts_with("type", 'inventory.') THEN 'variant'
|
|
11
|
+
END,
|
|
12
|
+
"subject_id" = CASE
|
|
13
|
+
WHEN starts_with("type", 'product.') THEN CASE
|
|
14
|
+
WHEN jsonb_typeof("envelope" #> '{payload,product,id}') = 'string' THEN "envelope" #>> '{payload,product,id}'
|
|
15
|
+
WHEN jsonb_typeof("envelope" #> '{payload,productId}') = 'string' THEN "envelope" #>> '{payload,productId}'
|
|
16
|
+
END
|
|
17
|
+
WHEN starts_with("type", 'order.') OR starts_with("type", 'payment.') THEN CASE
|
|
18
|
+
WHEN jsonb_typeof("envelope" #> '{payload,order,id}') = 'string' THEN "envelope" #>> '{payload,order,id}'
|
|
19
|
+
WHEN jsonb_typeof("envelope" #> '{payload,orderId}') = 'string' THEN "envelope" #>> '{payload,orderId}'
|
|
20
|
+
END
|
|
21
|
+
WHEN starts_with("type", 'customer.') AND jsonb_typeof("envelope" #> '{payload,customerId}') = 'string'
|
|
22
|
+
THEN "envelope" #>> '{payload,customerId}'
|
|
23
|
+
WHEN starts_with("type", 'inventory.') AND jsonb_typeof("envelope" #> '{payload,variantId}') = 'string'
|
|
24
|
+
THEN "envelope" #>> '{payload,variantId}'
|
|
25
|
+
END;--> statement-breakpoint
|
|
26
|
+
UPDATE "events" SET "subject_type" = NULL WHERE "subject_id" IS NULL;--> statement-breakpoint
|
|
27
|
+
CREATE INDEX IF NOT EXISTS "events_subject_idx" ON "events" USING btree ("subject_type","subject_id","seq");
|