@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.
@@ -85,6 +85,13 @@
85
85
  "when": 1792659500377,
86
86
  "tag": "0011_audit_entries",
87
87
  "breakpoints": true
88
+ },
89
+ {
90
+ "idx": 12,
91
+ "version": "7",
92
+ "when": 1792853533921,
93
+ "tag": "0012_event_subject",
94
+ "breakpoints": true
88
95
  }
89
96
  ]
90
97
  }
@@ -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 `subject_type` text;--> statement-breakpoint
4
+ ALTER TABLE `events` ADD `subject_id` text;--> statement-breakpoint
5
+ UPDATE `events` SET
6
+ `subject_type` = CASE
7
+ WHEN `type` GLOB 'product.*' THEN 'product'
8
+ WHEN `type` GLOB 'order.*' OR `type` GLOB 'payment.*' THEN 'order'
9
+ WHEN `type` GLOB 'customer.*' THEN 'customer'
10
+ WHEN `type` GLOB 'inventory.*' THEN 'variant'
11
+ END,
12
+ `subject_id` = CASE
13
+ WHEN `type` GLOB 'product.*' THEN CASE
14
+ WHEN json_type(`envelope`, '$.payload.product.id') = 'text' THEN json_extract(`envelope`, '$.payload.product.id')
15
+ WHEN json_type(`envelope`, '$.payload.productId') = 'text' THEN json_extract(`envelope`, '$.payload.productId')
16
+ END
17
+ WHEN `type` GLOB 'order.*' OR `type` GLOB 'payment.*' THEN CASE
18
+ WHEN json_type(`envelope`, '$.payload.order.id') = 'text' THEN json_extract(`envelope`, '$.payload.order.id')
19
+ WHEN json_type(`envelope`, '$.payload.orderId') = 'text' THEN json_extract(`envelope`, '$.payload.orderId')
20
+ END
21
+ WHEN `type` GLOB 'customer.*' AND json_type(`envelope`, '$.payload.customerId') = 'text'
22
+ THEN json_extract(`envelope`, '$.payload.customerId')
23
+ WHEN `type` GLOB 'inventory.*' AND json_type(`envelope`, '$.payload.variantId') = 'text'
24
+ THEN json_extract(`envelope`, '$.payload.variantId')
25
+ END;--> statement-breakpoint
26
+ UPDATE `events` SET `subject_type` = NULL WHERE `subject_id` IS NULL;--> statement-breakpoint
27
+ CREATE INDEX `events_subject_idx` ON `events` (`subject_type`,`subject_id`,`seq`);