@chaos-overlords/storage 0.9.6 → 0.9.8

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.
Files changed (41) hide show
  1. package/LICENSE +21 -674
  2. package/NOTICE +9 -12
  3. package/README.md +1 -1
  4. package/dist/postgres/events.d.ts.map +1 -1
  5. package/dist/postgres/events.js +34 -1
  6. package/dist/postgres/events.js.map +1 -1
  7. package/dist/postgres/repositories.js +44 -5
  8. package/dist/postgres/repositories.js.map +1 -1
  9. package/dist/postgres/schema.d.ts +51 -0
  10. package/dist/postgres/schema.d.ts.map +1 -1
  11. package/dist/postgres/schema.js +24 -2
  12. package/dist/postgres/schema.js.map +1 -1
  13. package/dist/postgres/takeovers.d.ts.map +1 -1
  14. package/dist/postgres/takeovers.js +24 -1
  15. package/dist/postgres/takeovers.js.map +1 -1
  16. package/dist/shared/constraints.d.ts +9 -3
  17. package/dist/shared/constraints.d.ts.map +1 -1
  18. package/dist/shared/constraints.js +9 -3
  19. package/dist/shared/constraints.js.map +1 -1
  20. package/dist/shared/mappers.d.ts +1 -0
  21. package/dist/shared/mappers.d.ts.map +1 -1
  22. package/dist/shared/mappers.js.map +1 -1
  23. package/dist/sqlite/events.d.ts.map +1 -1
  24. package/dist/sqlite/events.js +34 -1
  25. package/dist/sqlite/events.js.map +1 -1
  26. package/dist/sqlite/repositories.js +46 -6
  27. package/dist/sqlite/repositories.js.map +1 -1
  28. package/dist/sqlite/schema.d.ts +53 -0
  29. package/dist/sqlite/schema.d.ts.map +1 -1
  30. package/dist/sqlite/schema.js +24 -2
  31. package/dist/sqlite/schema.js.map +1 -1
  32. package/dist/sqlite/takeovers.d.ts.map +1 -1
  33. package/dist/sqlite/takeovers.js +24 -1
  34. package/dist/sqlite/takeovers.js.map +1 -1
  35. package/migrations/postgres/0006_stiff_newton_destine.sql +22 -0
  36. package/migrations/postgres/meta/0006_snapshot.json +942 -0
  37. package/migrations/postgres/meta/_journal.json +7 -0
  38. package/migrations/sqlite/0006_flawless_bedlam.sql +22 -0
  39. package/migrations/sqlite/meta/0006_snapshot.json +891 -0
  40. package/migrations/sqlite/meta/_journal.json +7 -0
  41. package/package.json +5 -5
@@ -43,6 +43,13 @@
43
43
  "when": 1789920763943,
44
44
  "tag": "0005_old_husk",
45
45
  "breakpoints": true
46
+ },
47
+ {
48
+ "idx": 6,
49
+ "version": "7",
50
+ "when": 1790451003982,
51
+ "tag": "0006_stiff_newton_destine",
52
+ "breakpoints": true
46
53
  }
47
54
  ]
48
55
  }
@@ -0,0 +1,22 @@
1
+ ALTER TABLE `match_events` ADD `dedupe_key` text;--> statement-breakpoint
2
+ CREATE UNIQUE INDEX `match_events_dedupe_idx` ON `match_events` (`match_id`,`dedupe_key`);--> statement-breakpoint
3
+ CREATE INDEX `match_events_type_idx` ON `match_events` (`match_id`,`type`,`seq`);--> statement-breakpoint
4
+ ALTER TABLE `takeover_prompts` ADD `announced_at` integer;--> statement-breakpoint
5
+ ALTER TABLE `turns` ADD `settled_at` integer;--> statement-breakpoint
6
+ CREATE INDEX `turns_settled_idx` ON `turns` (`status`,`settled_at`);--> statement-breakpoint
7
+ -- Backfill: an announcement logged before this column existed carries no key, so the first repeat
8
+ -- of it after the upgrade (the sweep finishing a seal whose successor never opened, say) would find
9
+ -- nothing under its key and log it a second time. The earliest event of each fact takes the key its
10
+ -- announcement is now published under; a fact the old code logged twice keeps its later copy unkeyed.
11
+ UPDATE `match_events` SET `dedupe_key` = 'turn.sealed:' || json_extract(`payload`, '$.turn') WHERE `dedupe_key` IS NULL AND `type` = 'turn.sealed' AND `seq` = (SELECT min(e.`seq`) FROM `match_events` e WHERE e.`match_id` = `match_events`.`match_id` AND e.`type` = 'turn.sealed' AND json_extract(e.`payload`, '$.turn') = json_extract(`match_events`.`payload`, '$.turn'));--> statement-breakpoint
12
+ UPDATE `match_events` SET `dedupe_key` = 'turn.confirmed:' || json_extract(`payload`, '$.turn') WHERE `dedupe_key` IS NULL AND `type` = 'turn.confirmed' AND `seq` = (SELECT min(e.`seq`) FROM `match_events` e WHERE e.`match_id` = `match_events`.`match_id` AND e.`type` = 'turn.confirmed' AND json_extract(e.`payload`, '$.turn') = json_extract(`match_events`.`payload`, '$.turn'));--> statement-breakpoint
13
+ UPDATE `match_events` SET `dedupe_key` = 'turn.desynced:' || json_extract(`payload`, '$.turn') WHERE `dedupe_key` IS NULL AND `type` = 'turn.desynced' AND `seq` = (SELECT min(e.`seq`) FROM `match_events` e WHERE e.`match_id` = `match_events`.`match_id` AND e.`type` = 'turn.desynced' AND json_extract(e.`payload`, '$.turn') = json_extract(`match_events`.`payload`, '$.turn'));--> statement-breakpoint
14
+ UPDATE `match_events` SET `dedupe_key` = 'match.statusChanged:finished' WHERE `dedupe_key` IS NULL AND `type` = 'match.statusChanged' AND json_extract(`payload`, '$.status') = 'finished' AND `seq` = (SELECT min(e.`seq`) FROM `match_events` e WHERE e.`match_id` = `match_events`.`match_id` AND e.`type` = 'match.statusChanged' AND json_extract(e.`payload`, '$.status') = 'finished');--> statement-breakpoint
15
+ -- Backfill: a prompt opened before this column existed was announced by the call that opened it.
16
+ -- Without a stamp it would read as still owing its announcement, and the next call to ask about
17
+ -- the seat would publish `match.takeoverVoteRequested` a second time.
18
+ UPDATE `takeover_prompts` SET `announced_at` = `opened_at` WHERE `announced_at` IS NULL;--> statement-breakpoint
19
+ -- Backfill: a turn confirmed before this column existed had its follow-ups run by the verdict that
20
+ -- confirmed it. Without a stamp every one of them would be handed to the sweep as a verdict cut
21
+ -- short, and `turn.confirmed` would be logged again for the whole history of every live match.
22
+ UPDATE `turns` SET `settled_at` = coalesce(`sealed_at`, unixepoch() * 1000) WHERE `status` = 'confirmed' AND `settled_at` IS NULL;