@composable-os/cli 0.1.0-beta.10 → 0.1.0-beta.11

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 (64) hide show
  1. package/dist/{accounts-X4CKM3HL.js → accounts-UHYLCLEY.js} +10 -11
  2. package/dist/{blocks-YWDHEBOK.js → blocks-5IFU25J6.js} +2 -2
  3. package/dist/chunk-2IVEVPMY.js +669 -0
  4. package/dist/{chunk-QGGJ2G6Z.js → chunk-2TWV3SVB.js} +3 -3
  5. package/dist/chunk-2XC5JLBO.js +1931 -0
  6. package/dist/chunk-324WJXNP.js +320 -0
  7. package/dist/chunk-6ELZRNUU.js +116 -0
  8. package/dist/{chunk-YJJHF65I.js → chunk-6WGFA2IV.js} +58 -174
  9. package/dist/{chunk-A4NTSYWV.js → chunk-6XTU2MTP.js} +196 -10
  10. package/dist/{chunk-Q4N55M2Z.js → chunk-7D4GKZOX.js} +66 -3
  11. package/dist/{chunk-GYSGVT6R.js → chunk-7OGCMQXG.js} +9 -9
  12. package/dist/chunk-DHS2CV2M.js +139 -0
  13. package/dist/{chunk-LJFLENFC.js → chunk-E64SG24J.js} +1 -1
  14. package/dist/{chunk-Z3RMMB6S.js → chunk-FJIZGS5Q.js} +45 -15
  15. package/dist/chunk-K34UKWEI.js +298 -0
  16. package/dist/{chunk-LLULPZAJ.js → chunk-LAAL4YGR.js} +4 -4
  17. package/dist/{chunk-CP6BXI6F.js → chunk-LO6WGU5Y.js} +1338 -974
  18. package/dist/{chunk-Y7JZFSTQ.js → chunk-MBIKVRAC.js} +6 -6
  19. package/dist/{chunk-WC5LHBBA.js → chunk-P6UWZ6QQ.js} +1 -1
  20. package/dist/{chunk-6VXHPKGG.js → chunk-PDD2ETVF.js} +8 -8
  21. package/dist/{chunk-6UPUF4ML.js → chunk-UB4I2QKR.js} +1957 -380
  22. package/dist/{chunk-M7A6FR2Z.js → chunk-WHKJGF36.js} +154 -322
  23. package/dist/{chunk-VY64DMQO.js → chunk-XIDLW3EP.js} +190 -21
  24. package/dist/{chunk-IFG4FRW5.js → chunk-YFTLIEWU.js} +1 -1
  25. package/dist/{chunk-JJHHNV46.js → chunk-YNUZRTPH.js} +5 -50
  26. package/dist/{chunk-WO6D3XP3.js → chunk-ZAWES2UD.js} +31 -18
  27. package/dist/{chunk-K6T42YCH.js → chunk-ZZFWMVJO.js} +5 -5
  28. package/dist/{cli-2DFENR62.js → cli-5UNY5G5L.js} +22 -20
  29. package/dist/{cli-YIOVSKOD.js → cli-UYZMVQMR.js} +16 -13
  30. package/dist/cli.js +1 -1
  31. package/dist/{client-repo-PRU3VCQQ.js → client-repo-SE4EKG6W.js} +2 -2
  32. package/dist/create.js +1 -1
  33. package/dist/{fields-2NC7LSYE.js → fields-FTWWMD7N.js} +3 -3
  34. package/dist/grants-LOW6TSWD.js +32 -0
  35. package/dist/invoke-6KVT6WJI.js +41 -0
  36. package/dist/moves-E2HKYCTK.js +41 -0
  37. package/dist/{order-PUWD65BC.js → order-U4KZLLSJ.js} +2 -2
  38. package/dist/{person-WIQQ7ITU.js → person-UHLVBVLR.js} +9 -10
  39. package/dist/plan-on-sale-TJPFCNL7.js +26 -0
  40. package/dist/platform/migrations/0610_waitlists.sql +54 -0
  41. package/dist/platform/migrations/0630_subscription_changes.sql +122 -0
  42. package/dist/platform/migrations/0650_person_links.sql +90 -0
  43. package/dist/platform/migrations/0670_unmoved_guard.sql +52 -0
  44. package/dist/platform/migrations/0690_sellable_refund_due.sql +98 -0
  45. package/dist/platform/sdk/capacity.ts +102 -0
  46. package/dist/platform/sdk/contract.ts +25 -0
  47. package/dist/platform/sdk/manifest.ts +77 -1
  48. package/dist/platform/sdk/sellable.ts +251 -1
  49. package/dist/platform/sdk/states.ts +163 -49
  50. package/dist/{run-RT2HVWMK.js → run-7P4RQALH.js} +2 -2
  51. package/dist/{run-PZUCSDDL.js → run-PO3W5BFA.js} +1 -1
  52. package/dist/{run-Y7T4TVOL.js → run-ZCGFMEZF.js} +2 -2
  53. package/dist/src-CRO35DYY.js +46 -0
  54. package/dist/{src-XTOD7EXW.js → src-I3IJ4NKC.js} +8 -2
  55. package/dist/{visibility-DLGHU4YN.js → visibility-TVXZ67FD.js} +12 -4
  56. package/package.json +2 -2
  57. package/dist/chunk-6GDEDOV7.js +0 -157
  58. package/dist/chunk-O2UIZHND.js +0 -249
  59. package/dist/chunk-R4W5XAUD.js +0 -837
  60. package/dist/chunk-TQFGGSA4.js +0 -748
  61. package/dist/grants-QXMKYMGB.js +0 -32
  62. package/dist/invoke-I3NNNXVL.js +0 -39
  63. package/dist/plan-on-sale-NB774CQL.js +0 -26
  64. package/dist/src-GYS6NBQB.js +0 -44
@@ -3,24 +3,24 @@ import {
3
3
  checkEvaluated,
4
4
  checkManifest,
5
5
  createDb
6
- } from "./chunk-WO6D3XP3.js";
7
- import "./chunk-LJFLENFC.js";
8
- import "./chunk-JJHHNV46.js";
9
- import "./chunk-O2UIZHND.js";
10
- import "./chunk-QGGJ2G6Z.js";
11
- import "./chunk-K6T42YCH.js";
12
- import "./chunk-TQFGGSA4.js";
6
+ } from "./chunk-ZAWES2UD.js";
7
+ import "./chunk-E64SG24J.js";
8
+ import "./chunk-YNUZRTPH.js";
9
+ import "./chunk-6ELZRNUU.js";
10
+ import "./chunk-2TWV3SVB.js";
11
+ import "./chunk-ZZFWMVJO.js";
12
+ import "./chunk-2XC5JLBO.js";
13
13
  import "./chunk-KGHA67HG.js";
14
14
  import {
15
15
  refreshSchemaRegistry
16
- } from "./chunk-A4NTSYWV.js";
17
- import "./chunk-IFG4FRW5.js";
18
- import "./chunk-Q4N55M2Z.js";
16
+ } from "./chunk-6XTU2MTP.js";
17
+ import "./chunk-YFTLIEWU.js";
18
+ import "./chunk-7D4GKZOX.js";
19
19
  import {
20
20
  OLD_OPS_SPECIFIER,
21
21
  OPS_MODULE,
22
22
  OPS_SPECIFIER
23
- } from "./chunk-CP6BXI6F.js";
23
+ } from "./chunk-LO6WGU5Y.js";
24
24
  import {
25
25
  __commonJS,
26
26
  __toESM
@@ -24451,8 +24451,9 @@ function outsideSummary(manifest) {
24451
24451
  for (const [name, object] of Object.entries(manifest.objects)) {
24452
24452
  if (object.sellable) {
24453
24453
  const grants = object.sellable.grants;
24454
+ const moves = object.sellable.moves;
24454
24455
  lines.push(
24455
- ` anyone can buy ${manifest.id}.${name} (priced by ${object.sellable.price})` + (grants ? `; a paid line grants ${grants.object}` : "")
24456
+ moves ? ` anyone can have the host make ${manifest.id}.${name} held ("${moves.held}") while its order is unpaid, priced by ${moves.price?.field ?? object.sellable.price}${moves.price?.setting ? ` else the setting ${moves.price.setting}` : ""}; paid: "${moves.paid}"; unpaid: "${moves.expired}"${moves.refund?.length ? `; a refund a person approves on ${moves.refund.join(", ")}` : ""}` : ` anyone can buy ${manifest.id}.${name} (priced by ${object.sellable.price})` + (grants ? `; a paid line grants ${grants.object}` : "")
24456
24457
  );
24457
24458
  }
24458
24459
  const p = object.public;
@@ -24480,8 +24481,10 @@ function outsideSummary(manifest) {
24480
24481
  }
24481
24482
  const c = object.customer;
24482
24483
  if (!c) continue;
24484
+ const g = c.guardians;
24485
+ const whose = g ? `is them or a child linked to them (${g.write ? "read and write" : "read only"})` : "is them";
24483
24486
  lines.push(
24484
- ` customers see ${manifest.id}.${name} where ${c.field} is them: read ${c.read.join(", ") || "nothing"}; write ${c.write.join(", ") || "nothing"}`
24487
+ ` customers see ${manifest.id}.${name} where ${c.field} ${whose}: read ${c.read.join(", ") || "nothing"}; write ${c.write.join(", ") || "nothing"}`
24485
24488
  );
24486
24489
  }
24487
24490
  for (const [name, tool] of Object.entries(manifest.tools)) {
package/dist/cli.js CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  Redactor,
8
8
  runCli,
9
9
  terminalIo
10
- } from "./chunk-6VXHPKGG.js";
10
+ } from "./chunk-PDD2ETVF.js";
11
11
  import "./chunk-DU6OIFOU.js";
12
12
  import "./chunk-KGHA67HG.js";
13
13
  import "./chunk-2ABSVMGB.js";
@@ -22,8 +22,8 @@ import {
22
22
  upgradeRepo,
23
23
  withEnvBinding,
24
24
  withTsExtensions
25
- } from "./chunk-Y7JZFSTQ.js";
26
- import "./chunk-6VXHPKGG.js";
25
+ } from "./chunk-MBIKVRAC.js";
26
+ import "./chunk-PDD2ETVF.js";
27
27
  import "./chunk-DU6OIFOU.js";
28
28
  import "./chunk-KGHA67HG.js";
29
29
  import "./chunk-2ABSVMGB.js";
package/dist/create.js CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  Redactor,
8
8
  runCli,
9
9
  terminalIo
10
- } from "./chunk-6VXHPKGG.js";
10
+ } from "./chunk-PDD2ETVF.js";
11
11
  import "./chunk-DU6OIFOU.js";
12
12
  import "./chunk-KGHA67HG.js";
13
13
  import "./chunk-2ABSVMGB.js";
@@ -9,7 +9,7 @@ import {
9
9
  personObject,
10
10
  setExtensionObjects,
11
11
  taskObject
12
- } from "./chunk-IFG4FRW5.js";
12
+ } from "./chunk-YFTLIEWU.js";
13
13
  import {
14
14
  BASE_OBJECTS,
15
15
  BASE_TABLES,
@@ -21,10 +21,10 @@ import {
21
21
  orderLineObject,
22
22
  orderObject,
23
23
  timelineFields
24
- } from "./chunk-Q4N55M2Z.js";
24
+ } from "./chunk-7D4GKZOX.js";
25
25
  import {
26
26
  MEDIA_TYPES
27
- } from "./chunk-CP6BXI6F.js";
27
+ } from "./chunk-LO6WGU5Y.js";
28
28
  import "./chunk-5KSXSK7Y.js";
29
29
  export {
30
30
  BASE_OBJECTS,
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ GRANT_CODE_LENGTH,
4
+ grantFieldValue,
5
+ grantsFollowPerson,
6
+ handGrantValues,
7
+ newGrantCode,
8
+ readGrantItem,
9
+ validFrom
10
+ } from "./chunk-K34UKWEI.js";
11
+ import "./chunk-WHKJGF36.js";
12
+ import "./chunk-324WJXNP.js";
13
+ import "./chunk-FJIZGS5Q.js";
14
+ import "./chunk-YNUZRTPH.js";
15
+ import "./chunk-6ELZRNUU.js";
16
+ import "./chunk-ZZFWMVJO.js";
17
+ import "./chunk-2XC5JLBO.js";
18
+ import "./chunk-KGHA67HG.js";
19
+ import "./chunk-6XTU2MTP.js";
20
+ import "./chunk-YFTLIEWU.js";
21
+ import "./chunk-7D4GKZOX.js";
22
+ import "./chunk-LO6WGU5Y.js";
23
+ import "./chunk-5KSXSK7Y.js";
24
+ export {
25
+ GRANT_CODE_LENGTH,
26
+ grantFieldValue,
27
+ grantsFollowPerson,
28
+ handGrantValues,
29
+ newGrantCode,
30
+ readGrantItem,
31
+ validFrom
32
+ };
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ coreInvoker,
4
+ coreRegistry,
5
+ createInvoker,
6
+ invoke,
7
+ invokeByName,
8
+ listOperations
9
+ } from "./chunk-UB4I2QKR.js";
10
+ import "./chunk-DHS2CV2M.js";
11
+ import "./chunk-K34UKWEI.js";
12
+ import "./chunk-2IVEVPMY.js";
13
+ import "./chunk-6WGFA2IV.js";
14
+ import "./chunk-WHKJGF36.js";
15
+ import "./chunk-324WJXNP.js";
16
+ import "./chunk-7OGCMQXG.js";
17
+ import "./chunk-XIDLW3EP.js";
18
+ import "./chunk-FJIZGS5Q.js";
19
+ import "./chunk-ZAWES2UD.js";
20
+ import "./chunk-E64SG24J.js";
21
+ import "./chunk-YNUZRTPH.js";
22
+ import "./chunk-6ELZRNUU.js";
23
+ import "./chunk-2TWV3SVB.js";
24
+ import "./chunk-ZZFWMVJO.js";
25
+ import "./chunk-2XC5JLBO.js";
26
+ import "./chunk-DU6OIFOU.js";
27
+ import "./chunk-KGHA67HG.js";
28
+ import "./chunk-6UWRT4VM.js";
29
+ import "./chunk-6XTU2MTP.js";
30
+ import "./chunk-YFTLIEWU.js";
31
+ import "./chunk-7D4GKZOX.js";
32
+ import "./chunk-LO6WGU5Y.js";
33
+ import "./chunk-5KSXSK7Y.js";
34
+ export {
35
+ coreInvoker,
36
+ coreRegistry,
37
+ createInvoker,
38
+ invoke,
39
+ invokeByName,
40
+ listOperations
41
+ };
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ DEFAULT_HOLD_PERCENT,
4
+ UNSETTLED_RELEASES,
5
+ UNSETTLED_SCAN,
6
+ movesFollowPerson,
7
+ movesOf,
8
+ oweLateRefund,
9
+ releaseUnsettledGuest,
10
+ startHeld,
11
+ unsettledGuests
12
+ } from "./chunk-2IVEVPMY.js";
13
+ import "./chunk-6WGFA2IV.js";
14
+ import "./chunk-WHKJGF36.js";
15
+ import "./chunk-324WJXNP.js";
16
+ import "./chunk-7OGCMQXG.js";
17
+ import "./chunk-XIDLW3EP.js";
18
+ import "./chunk-FJIZGS5Q.js";
19
+ import "./chunk-YNUZRTPH.js";
20
+ import "./chunk-6ELZRNUU.js";
21
+ import "./chunk-2TWV3SVB.js";
22
+ import "./chunk-ZZFWMVJO.js";
23
+ import "./chunk-2XC5JLBO.js";
24
+ import "./chunk-KGHA67HG.js";
25
+ import "./chunk-6UWRT4VM.js";
26
+ import "./chunk-6XTU2MTP.js";
27
+ import "./chunk-YFTLIEWU.js";
28
+ import "./chunk-7D4GKZOX.js";
29
+ import "./chunk-LO6WGU5Y.js";
30
+ import "./chunk-5KSXSK7Y.js";
31
+ export {
32
+ DEFAULT_HOLD_PERCENT,
33
+ UNSETTLED_RELEASES,
34
+ UNSETTLED_SCAN,
35
+ movesFollowPerson,
36
+ movesOf,
37
+ oweLateRefund,
38
+ releaseUnsettledGuest,
39
+ startHeld,
40
+ unsettledGuests
41
+ };
@@ -6,8 +6,8 @@ import {
6
6
  ORDER_STATES,
7
7
  orderLineObject,
8
8
  orderObject
9
- } from "./chunk-Q4N55M2Z.js";
10
- import "./chunk-CP6BXI6F.js";
9
+ } from "./chunk-7D4GKZOX.js";
10
+ import "./chunk-LO6WGU5Y.js";
11
11
  import "./chunk-5KSXSK7Y.js";
12
12
  export {
13
13
  BASE_OBJECTS,
@@ -24,20 +24,19 @@ import {
24
24
  phoneInputSchema,
25
25
  socialProfileSchema,
26
26
  updatePerson
27
- } from "./chunk-VY64DMQO.js";
28
- import "./chunk-Z3RMMB6S.js";
29
- import "./chunk-6GDEDOV7.js";
30
- import "./chunk-QGGJ2G6Z.js";
27
+ } from "./chunk-XIDLW3EP.js";
28
+ import "./chunk-FJIZGS5Q.js";
29
+ import "./chunk-2TWV3SVB.js";
31
30
  import {
32
31
  TRASH_RETENTION_DAYS
33
- } from "./chunk-K6T42YCH.js";
34
- import "./chunk-TQFGGSA4.js";
32
+ } from "./chunk-ZZFWMVJO.js";
33
+ import "./chunk-2XC5JLBO.js";
35
34
  import "./chunk-KGHA67HG.js";
36
35
  import "./chunk-6UWRT4VM.js";
37
- import "./chunk-A4NTSYWV.js";
38
- import "./chunk-IFG4FRW5.js";
39
- import "./chunk-Q4N55M2Z.js";
40
- import "./chunk-CP6BXI6F.js";
36
+ import "./chunk-6XTU2MTP.js";
37
+ import "./chunk-YFTLIEWU.js";
38
+ import "./chunk-7D4GKZOX.js";
39
+ import "./chunk-LO6WGU5Y.js";
41
40
  import "./chunk-5KSXSK7Y.js";
42
41
  export {
43
42
  TRASH_RETENTION_DAYS,
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ PLANS_LOOKED_AT,
4
+ PLAN_ON_SALE_MEMO_MS,
5
+ findPlanOnSale,
6
+ forgetPlanOnSale,
7
+ hasPlanOnSale
8
+ } from "./chunk-DHS2CV2M.js";
9
+ import "./chunk-6WGFA2IV.js";
10
+ import "./chunk-324WJXNP.js";
11
+ import "./chunk-E64SG24J.js";
12
+ import "./chunk-6ELZRNUU.js";
13
+ import "./chunk-2XC5JLBO.js";
14
+ import "./chunk-KGHA67HG.js";
15
+ import "./chunk-6XTU2MTP.js";
16
+ import "./chunk-YFTLIEWU.js";
17
+ import "./chunk-7D4GKZOX.js";
18
+ import "./chunk-LO6WGU5Y.js";
19
+ import "./chunk-5KSXSK7Y.js";
20
+ export {
21
+ PLANS_LOOKED_AT,
22
+ PLAN_ON_SALE_MEMO_MS,
23
+ findPlanOnSale,
24
+ forgetPlanOnSale,
25
+ hasPlanOnSale
26
+ };
@@ -0,0 +1,54 @@
1
+ -- Migration 0610: waitlists on capacity claimants (stage 31a step 5, ADR 0520).
2
+ --
3
+ -- A claimant that declares a waitlist (a booking waiting for a full class) holds no place while it
4
+ -- waits. Until its cut-off, a place given back while anyone waits is handed to the waitlist in the
5
+ -- statements that give it back: a claim of its own on the class's counter, `for_type = 'waitlist'`
6
+ -- and `for_id` the claimant object, held. Nobody booking directly can take it, because the counter
7
+ -- counts it. The host promotes the first waiter from a current read; the promotion's batch gives
8
+ -- one waitlist hold back and claims the waiter's place, so the counter never goes past its places
9
+ -- and two promotions for one hold cannot both succeed (the second finds the class full).
10
+ --
11
+ -- Nothing new is stored beyond those claims; this migration adds:
12
+ -- * an index for the minute cron's sweep of waitlist holds;
13
+ -- * a guard kind for a waiter's join: the class must be full when the join commits, so nobody
14
+ -- waits behind a free place. core_write_guard stores nothing, so it is made again with the
15
+ -- new kind (SQLite cannot change a CHECK in place).
16
+ CREATE INDEX core_capacity_claim_waitlist_idx ON core_capacity_claim (for_type, state, object_type, record_id)
17
+ WHERE for_type = 'waitlist';
18
+
19
+ DROP TRIGGER core_write_guard_check;
20
+ DROP TABLE core_write_guard;
21
+
22
+ -- As migration 0560's, with kind 'full': the counter has places and they are all held or taken.
23
+ CREATE TABLE core_write_guard (
24
+ kind TEXT NOT NULL CHECK (kind IN ('claimed', 'claimant', 'series', 'full')),
25
+ object_type TEXT NOT NULL,
26
+ record_id TEXT NOT NULL,
27
+ expected INTEGER NOT NULL
28
+ );
29
+
30
+ CREATE TRIGGER core_write_guard_check
31
+ BEFORE INSERT ON core_write_guard
32
+ BEGIN
33
+ SELECT CASE
34
+ WHEN NEW.kind = 'claimed' AND coalesce((SELECT held + taken FROM core_capacity
35
+ WHERE object_type = NEW.object_type AND record_id = NEW.record_id), 0) != NEW.expected
36
+ THEN RAISE(ABORT, 'core_recurrence_stale')
37
+ WHEN NEW.kind = 'series' AND coalesce((SELECT version FROM core_recurrence_series
38
+ WHERE object_type = NEW.object_type AND record_id = NEW.record_id), 0) != NEW.expected
39
+ THEN RAISE(ABORT, 'core_recurrence_stale')
40
+ WHEN NEW.kind = 'claimant' AND (SELECT count(*) FROM core_capacity_claim
41
+ WHERE for_type = NEW.object_type AND for_id = NEW.record_id
42
+ AND state IN ('held', 'confirmed')) != NEW.expected
43
+ THEN RAISE(ABORT, 'core_claim_live')
44
+ WHEN NEW.kind = 'full' AND NOT EXISTS (SELECT 1 FROM core_capacity
45
+ WHERE object_type = NEW.object_type AND record_id = NEW.record_id
46
+ AND places IS NOT NULL AND held + taken >= places)
47
+ THEN RAISE(ABORT, 'core_waitlist_not_full')
48
+ ELSE RAISE(IGNORE)
49
+ END;
50
+ END;
51
+
52
+ -- Guarded: migrations land out of order (docs/parallel-work.md).
53
+ UPDATE core_meta SET value = '610'
54
+ WHERE key = 'schema_version' AND CAST(value AS INTEGER) < 610;
@@ -0,0 +1,122 @@
1
+ -- Migration 0630: plan changes and pauses of a subscription (stage 32b, ADRs 0530 and 0531).
2
+ --
3
+ -- A change the host asked the provider for: a plan change (an upgrade now, a downgrade from the
4
+ -- next period) or a pause (from now or a moment, until a moment). The provider runs it; this row is
5
+ -- what the host asked, so a verified read that shows it can be told from a change made at the
6
+ -- provider some other way, and so the member's terms follow the plan only from a read that shows
7
+ -- the change. Nothing here moves the subscription: its state is the provider's, mirrored.
8
+ --
9
+ -- requested asked of the provider (written before the call is made, after the operation's
10
+ -- batch claims the subscription's one open change); not yet in a verified read
11
+ -- waiting a downgrade the provider shows (its price is the new one), whose terms follow when
12
+ -- the next period starts (`effective_at`, the period end of the read that showed it)
13
+ -- applied the member holds the new plan (a change), or the pause is running or over
14
+ -- lapsed past `expires_at` and never shown by the provider (an upgrade's pending update
15
+ -- expires within 23 hours), or the provider refused the call outright
16
+ -- withdrawn closed by staff (`subscription.change.withdraw`, `subscription.unpause` of a pause
17
+ -- not started), or a waiting downgrade the provider no longer shows (its price put back)
18
+ --
19
+ -- One definition of "open": state requested or waiting and `expires_at` still ahead. Every reader
20
+ -- (the host's TypeScript and this view) uses it; a row found past it is closed as lapsed.
21
+ CREATE TABLE core_subscription_change (
22
+ -- sbc_… (ids.ts); the provider's idempotency key for the call.
23
+ id TEXT PRIMARY KEY NOT NULL,
24
+ subscription_id TEXT NOT NULL REFERENCES core_subscription (id) ON DELETE CASCADE,
25
+ kind TEXT NOT NULL CHECK (kind IN ('upgrade', 'downgrade', 'pause')),
26
+ state TEXT NOT NULL CHECK (state IN ('requested', 'waiting', 'applied', 'lapsed', 'withdrawn')),
27
+ -- The plan held when it was asked, and the plan asked for (a change; null for a pause).
28
+ from_plan_id TEXT NOT NULL,
29
+ from_plan_title TEXT NOT NULL,
30
+ from_amount INTEGER NOT NULL CHECK (from_amount > 0),
31
+ to_plan_id TEXT,
32
+ to_plan_title TEXT,
33
+ to_amount INTEGER CHECK (to_amount IS NULL OR to_amount > 0),
34
+ -- A pause's window: from (null: now) and until, as asked.
35
+ pause_from TEXT,
36
+ pause_until TEXT,
37
+ -- When the member's terms follow a change: the period's end for a downgrade, the moment the
38
+ -- provider showed it for an upgrade.
39
+ effective_at TEXT,
40
+ -- When an open change stops being trusted, never shown by the provider: a day after it was
41
+ -- asked (a pause: a day after it was due to start), a week after a waiting downgrade's period end.
42
+ expires_at TEXT NOT NULL,
43
+ -- What came of the host's call to the provider: sent (applied at the gatekeeper), pending (waiting
44
+ -- for approval), unknown (it may or may not have reached the provider: verified reads decide),
45
+ -- refused (it did not). Null until the call returns.
46
+ call_outcome TEXT CHECK (call_outcome IS NULL OR call_outcome IN ('sent', 'pending', 'unknown', 'refused')),
47
+ call_error TEXT,
48
+ -- The provider's page to confirm an upgrade's charge (3D Secure), while it waits.
49
+ action_url TEXT,
50
+ -- The call that ends or undoes it: ending a pause early, putting a withdrawn downgrade's price back.
51
+ end_outcome TEXT CHECK (end_outcome IS NULL OR end_outcome IN ('sent', 'pending', 'unknown', 'refused')),
52
+ end_error TEXT,
53
+ end_at TEXT,
54
+ reason TEXT NOT NULL,
55
+ -- Who asked: `staff:<user id>` or `customer:<customer id>`.
56
+ requested_by TEXT NOT NULL,
57
+ requested_at TEXT NOT NULL,
58
+ applied_at TEXT,
59
+ updated_at TEXT NOT NULL,
60
+ CHECK ((kind = 'pause') = (to_plan_id IS NULL)),
61
+ CHECK (kind <> 'pause' OR pause_until IS NOT NULL)
62
+ );
63
+ -- One open change per subscription: two asked at once, the second's whole batch fails, so the
64
+ -- provider is asked once.
65
+ CREATE UNIQUE INDEX core_subscription_change_open_uq ON core_subscription_change (subscription_id)
66
+ WHERE state IN ('requested', 'waiting');
67
+ CREATE INDEX core_subscription_change_subscription_idx
68
+ ON core_subscription_change (subscription_id, requested_at);
69
+
70
+ CREATE VIEW rec_subscription_change AS
71
+ SELECT
72
+ id, subscription_id, kind, state, from_plan_id, from_plan_title, from_amount, to_plan_id,
73
+ to_plan_title, to_amount, pause_from, pause_until, effective_at, expires_at, call_outcome,
74
+ end_outcome, reason, requested_at,
75
+ applied_at
76
+ FROM core_subscription_change;
77
+
78
+ -- The subscription as the seam reads it gains the change it shows: its open change (asked, or a
79
+ -- downgrade waiting for its period, or a pause not yet started), or the pause it is in while
80
+ -- paused. An upgrade asked over a day ago and never shown by the provider reads `lapsed`.
81
+ DROP VIEW rec_subscription;
82
+ CREATE VIEW rec_subscription AS
83
+ SELECT
84
+ s.id, s.payer_person_id, s.holder_person_id, s.email, s.placed_as, s.plan_object, s.plan_id,
85
+ s.plan_title, s.amount, s.currency, s.interval, s.tax_code IS NOT NULL AS taxed, s.state,
86
+ s.provider, s.provider_ref, s.trial_end, s.current_period_start, s.current_period_end,
87
+ s.cancel_at_period_end, s.cancel_at, s.canceled_at, s.ended_at, s.end_reason, s.action_url,
88
+ s.failing_since, s.created_at, s.updated_at,
89
+ c.id AS change_id,
90
+ c.kind AS change_kind,
91
+ CASE
92
+ WHEN c.state IN ('requested', 'waiting')
93
+ AND c.expires_at <= strftime('%Y-%m-%dT%H:%M:%fZ', 'now') THEN 'lapsed'
94
+ ELSE c.state
95
+ END AS change_state,
96
+ c.call_outcome AS change_call_outcome,
97
+ -- Only while the change is open: a lapsed or withdrawn upgrade shows no page to pay.
98
+ CASE
99
+ WHEN c.state = 'requested' AND c.expires_at > strftime('%Y-%m-%dT%H:%M:%fZ', 'now')
100
+ THEN c.action_url
101
+ END AS change_action_url,
102
+ c.end_outcome AS change_end_outcome,
103
+ c.to_plan_id AS change_to_plan_id,
104
+ c.to_plan_title AS change_to_plan_title,
105
+ c.to_amount AS change_to_amount,
106
+ c.pause_from AS pause_from,
107
+ c.pause_until AS pause_until,
108
+ c.effective_at AS change_effective_at,
109
+ c.requested_at AS change_requested_at
110
+ FROM core_subscription s
111
+ LEFT JOIN core_subscription_change c ON c.id = (
112
+ SELECT x.id FROM core_subscription_change x
113
+ WHERE x.subscription_id = s.id
114
+ AND (x.state IN ('requested', 'waiting')
115
+ OR (x.kind = 'pause' AND x.state = 'applied' AND s.state = 'paused'))
116
+ ORDER BY x.state IN ('requested', 'waiting') DESC, x.requested_at DESC
117
+ LIMIT 1
118
+ );
119
+
120
+ -- Guarded: migrations land out of order (docs/parallel-work.md).
121
+ UPDATE core_meta SET value = '630'
122
+ WHERE key = 'schema_version' AND CAST(value AS INTEGER) < 630;
@@ -0,0 +1,90 @@
1
+ -- Migration 0650: the family link (stage 31a step 6, ADR 0540).
2
+ --
3
+ -- A link between two People: a guardian and a dependant (a parent and a child). While it is live
4
+ -- (not ended), the visibility seam lets the guardian, signed in as a customer, read the
5
+ -- dependant's records of every object whose customer declaration opts in (`guardians`), and
6
+ -- write them where it says so (book a class for a child). Nothing else reads it to decide access.
7
+ --
8
+ -- Staff make and end links, a person only (`person.link.add` and `person.link.end`, permission
9
+ -- `people:link`). An ended link is kept, with who ended it and when, as the audit of who could act
10
+ -- for whom; it gives nothing. A dependant may have several guardians and a guardian several
11
+ -- dependants; one live link per pair. A link from a Person to themselves cannot exist.
12
+ --
13
+ -- Both people are core_person rows: an erase (a hard delete) removes their links with them by the
14
+ -- foreign keys; a merge re-points them to the survivor in its batch (person.merge).
15
+ CREATE TABLE core_person_link (
16
+ id TEXT PRIMARY KEY,
17
+ kind TEXT NOT NULL DEFAULT 'guardian' CHECK (kind IN ('guardian')),
18
+ guardian_id TEXT NOT NULL REFERENCES core_person (id) ON DELETE CASCADE,
19
+ dependant_id TEXT NOT NULL REFERENCES core_person (id) ON DELETE CASCADE,
20
+ -- Why staff made it (optional): "mother", "guardian by court order".
21
+ note TEXT,
22
+ -- The staff account (usr_…) that made it, and when.
23
+ created_by TEXT NOT NULL,
24
+ created_at TEXT NOT NULL,
25
+ -- Set when it ends; it never starts again (a new link is made instead).
26
+ ended_at TEXT,
27
+ ended_by TEXT,
28
+ end_reason TEXT,
29
+ CHECK (guardian_id != dependant_id)
30
+ );
31
+ -- One live link per pair and kind; the guardian's dependants are what the seam reads.
32
+ CREATE UNIQUE INDEX core_person_link_live_uq
33
+ ON core_person_link (guardian_id, dependant_id, kind) WHERE ended_at IS NULL;
34
+ CREATE INDEX core_person_link_dependant_idx ON core_person_link (dependant_id, ended_at);
35
+
36
+ -- Never a two-way link: while A is B's guardian, B cannot be A's (a child would act for their
37
+ -- parent). Refused for every writer, so two staff linking the same pair in opposite directions at
38
+ -- once get one, and a merge that would make a two-way link fails unless it ends one first.
39
+ CREATE TRIGGER core_person_link_no_reverse_insert
40
+ BEFORE INSERT ON core_person_link
41
+ WHEN NEW.ended_at IS NULL
42
+ BEGIN
43
+ SELECT RAISE(ABORT, 'core_person_link_reverse')
44
+ WHERE EXISTS (
45
+ SELECT 1 FROM core_person_link r
46
+ WHERE r.guardian_id = NEW.dependant_id AND r.dependant_id = NEW.guardian_id
47
+ AND r.kind = NEW.kind AND r.ended_at IS NULL
48
+ );
49
+ END;
50
+
51
+ CREATE TRIGGER core_person_link_no_reverse_update
52
+ BEFORE UPDATE OF guardian_id, dependant_id, ended_at ON core_person_link
53
+ WHEN NEW.ended_at IS NULL
54
+ BEGIN
55
+ SELECT RAISE(ABORT, 'core_person_link_reverse')
56
+ WHERE EXISTS (
57
+ SELECT 1 FROM core_person_link r
58
+ WHERE r.guardian_id = NEW.dependant_id AND r.dependant_id = NEW.guardian_id
59
+ AND r.kind = NEW.kind AND r.ended_at IS NULL AND r.id != NEW.id
60
+ );
61
+ END;
62
+
63
+ -- The guard a guardian's write carries in its own batch (ADR 0540): one row saying "this guardian
64
+ -- acts for this dependant". The trigger lets it through (and drops it: nothing is stored) only
65
+ -- while the link is live and both People are out of the Trash; otherwise the whole batch fails,
66
+ -- so a link ended a moment before cannot be written through.
67
+ CREATE TABLE core_person_link_guard (
68
+ guardian_id TEXT NOT NULL,
69
+ dependant_id TEXT NOT NULL
70
+ );
71
+
72
+ CREATE TRIGGER core_person_link_guard_check
73
+ BEFORE INSERT ON core_person_link_guard
74
+ BEGIN
75
+ SELECT CASE
76
+ WHEN NOT EXISTS (
77
+ SELECT 1 FROM core_person_link l
78
+ JOIN core_person d ON d.id = l.dependant_id AND d.deleted_at IS NULL
79
+ JOIN core_person g ON g.id = l.guardian_id AND g.deleted_at IS NULL
80
+ WHERE l.guardian_id = NEW.guardian_id AND l.dependant_id = NEW.dependant_id
81
+ AND l.kind = 'guardian' AND l.ended_at IS NULL
82
+ )
83
+ THEN RAISE(ABORT, 'core_person_link_not_live')
84
+ ELSE RAISE(IGNORE)
85
+ END;
86
+ END;
87
+
88
+ -- Guarded: migrations land out of order (docs/parallel-work.md).
89
+ UPDATE core_meta SET value = '650'
90
+ WHERE key = 'schema_version' AND CAST(value AS INTEGER) < 650;
@@ -0,0 +1,52 @@
1
+ -- Migration 0670: a guard that the record a write is for has not moved meanwhile (stage 31a
2
+ -- step 7, ADR 0550).
3
+ --
4
+ -- A booking is made only while its class is scheduled (`states.create.closed`, ADR 0507): the
5
+ -- check reads the class when the write is planned. A class cancelled between that read and the
6
+ -- booking's commit would otherwise be left with a booking its cancel never saw (the cancel moves
7
+ -- the bookings it reads, in its own batch). So a write judged against a `closed` flag queues a
8
+ -- guard on the record the flag is read through: the number of moves in its state history
9
+ -- (core_transition_history, ADR 0425) must still be what was read. A move in between adds a row,
10
+ -- and the write's batch fails whole (`core_moved_meanwhile`, answered as a conflict).
11
+ --
12
+ -- core_write_guard stores nothing, so it is made again with the new kind (SQLite cannot change a
13
+ -- CHECK in place), as migrations 0560 and 0610 did.
14
+ DROP TRIGGER core_write_guard_check;
15
+ DROP TABLE core_write_guard;
16
+
17
+ -- As migration 0610's, with kind 'unmoved': the record's state history has `expected` rows.
18
+ CREATE TABLE core_write_guard (
19
+ kind TEXT NOT NULL CHECK (kind IN ('claimed', 'claimant', 'series', 'full', 'unmoved')),
20
+ object_type TEXT NOT NULL,
21
+ record_id TEXT NOT NULL,
22
+ expected INTEGER NOT NULL
23
+ );
24
+
25
+ CREATE TRIGGER core_write_guard_check
26
+ BEFORE INSERT ON core_write_guard
27
+ BEGIN
28
+ SELECT CASE
29
+ WHEN NEW.kind = 'claimed' AND coalesce((SELECT held + taken FROM core_capacity
30
+ WHERE object_type = NEW.object_type AND record_id = NEW.record_id), 0) != NEW.expected
31
+ THEN RAISE(ABORT, 'core_recurrence_stale')
32
+ WHEN NEW.kind = 'series' AND coalesce((SELECT version FROM core_recurrence_series
33
+ WHERE object_type = NEW.object_type AND record_id = NEW.record_id), 0) != NEW.expected
34
+ THEN RAISE(ABORT, 'core_recurrence_stale')
35
+ WHEN NEW.kind = 'claimant' AND (SELECT count(*) FROM core_capacity_claim
36
+ WHERE for_type = NEW.object_type AND for_id = NEW.record_id
37
+ AND state IN ('held', 'confirmed')) != NEW.expected
38
+ THEN RAISE(ABORT, 'core_claim_live')
39
+ WHEN NEW.kind = 'full' AND NOT EXISTS (SELECT 1 FROM core_capacity
40
+ WHERE object_type = NEW.object_type AND record_id = NEW.record_id
41
+ AND places IS NOT NULL AND held + taken >= places)
42
+ THEN RAISE(ABORT, 'core_waitlist_not_full')
43
+ WHEN NEW.kind = 'unmoved' AND (SELECT count(*) FROM core_transition_history
44
+ WHERE object_type = NEW.object_type AND record_id = NEW.record_id) != NEW.expected
45
+ THEN RAISE(ABORT, 'core_moved_meanwhile')
46
+ ELSE RAISE(IGNORE)
47
+ END;
48
+ END;
49
+
50
+ -- Guarded: migrations land out of order (docs/parallel-work.md).
51
+ UPDATE core_meta SET value = '670'
52
+ WHERE key = 'schema_version' AND CAST(value AS INTEGER) < 670;