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

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 (166) hide show
  1. package/dist/{accounts-UHYLCLEY.js → accounts-GOCNY6WI.js} +17 -13
  2. package/dist/app-OSPZHKOI.js +43 -0
  3. package/dist/app-upload-LH4PXKI4.js +198 -0
  4. package/dist/{blocks-5IFU25J6.js → blocks-6DZIP47W.js} +207 -25
  5. package/dist/{chunk-XIDLW3EP.js → chunk-2B6YUYZV.js} +23499 -11766
  6. package/dist/{run-7P4RQALH.js → chunk-2CCHB37H.js} +9 -146
  7. package/dist/{chunk-DU6OIFOU.js → chunk-3OGDWKJ3.js} +530 -434
  8. package/dist/{chunk-DHS2CV2M.js → chunk-5D7BDF4Y.js} +15 -13
  9. package/dist/{chunk-MBIKVRAC.js → chunk-5YDYQM6V.js} +830 -47
  10. package/dist/{chunk-ZAWES2UD.js → chunk-6CM3WZG5.js} +13 -2483
  11. package/dist/{chunk-7D4GKZOX.js → chunk-CIBJGB5H.js} +422 -75
  12. package/dist/chunk-EPDTPGZJ.js +330 -0
  13. package/dist/{chunk-LAAL4YGR.js → chunk-HAYF4G5V.js} +66 -23
  14. package/dist/chunk-HCG6T53D.js +61904 -0
  15. package/dist/{chunk-K34UKWEI.js → chunk-JX4IFWNT.js} +64 -32
  16. package/dist/{chunk-6XTU2MTP.js → chunk-KFHKNXGH.js} +632 -418
  17. package/dist/chunk-KMFMD52Z.js +13276 -0
  18. package/dist/{chunk-E4WCYTCT.js → chunk-LX2TTLVY.js} +174 -55
  19. package/dist/{chunk-PDD2ETVF.js → chunk-O37YUZ52.js} +172 -16
  20. package/dist/{chunk-GYTEW66E.js → chunk-O3R4FS2J.js} +1 -1
  21. package/dist/{chunk-E64SG24J.js → chunk-Q6Y45DY6.js} +25 -2
  22. package/dist/chunk-RGKJKC5T.js +876 -0
  23. package/dist/{chunk-YFTLIEWU.js → chunk-RSEWEFAV.js} +12 -2
  24. package/dist/{chunk-2ABSVMGB.js → chunk-SMJZIK2O.js} +1 -1
  25. package/dist/{chunk-LO6WGU5Y.js → chunk-U72NEGCT.js} +8089 -3464
  26. package/dist/{chunk-P6UWZ6QQ.js → chunk-Z4IKF23A.js} +11 -7
  27. package/dist/{chunk-2IVEVPMY.js → chunk-Z7OVQ6BC.js} +105 -61
  28. package/dist/{chunk-6UWRT4VM.js → chunk-ZJSFX4RD.js} +175 -3
  29. package/dist/{cli-5UNY5G5L.js → cli-OKQHHSOE.js} +17 -25
  30. package/dist/{cli-UYZMVQMR.js → cli-VYSD2S4Z.js} +227 -81
  31. package/dist/cli.js +5 -5
  32. package/dist/{client-repo-SE4EKG6W.js → client-repo-MPCPTXLF.js} +7 -5
  33. package/dist/create.js +5 -5
  34. package/dist/{fields-FTWWMD7N.js → fields-GTHE6TTS.js} +27 -3
  35. package/dist/gateway-DPPEQZT4.js +25 -0
  36. package/dist/grants-6JY4XZO7.js +27 -0
  37. package/dist/invoke-MRONRZ5Q.js +33 -0
  38. package/dist/moves-UAUCMWL5.js +36 -0
  39. package/dist/{order-U4KZLLSJ.js → order-RKLGT74L.js} +2 -2
  40. package/dist/{person-UHLVBVLR.js → person-YOZTFV4Q.js} +11 -10
  41. package/dist/plan-on-sale-H4F26YIN.js +26 -0
  42. package/dist/platform/migrations/0730_practitioners.sql +79 -0
  43. package/dist/platform/migrations/0750_routine_mail.sql +98 -0
  44. package/dist/platform/migrations/0770_clear_fixed_role_grants.sql +64 -0
  45. package/dist/platform/migrations/0810_recurrence_exceptions.sql +66 -0
  46. package/dist/platform/migrations/0811_staff_time.sql +109 -0
  47. package/dist/platform/migrations/0812_staff_offers.sql +112 -0
  48. package/dist/platform/migrations/0813_pay_periods.sql +241 -0
  49. package/dist/platform/migrations/0814_staff_feed.sql +47 -0
  50. package/dist/platform/migrations/0815_checklists.sql +237 -0
  51. package/dist/platform/migrations/0816_checklist_schedules.sql +121 -0
  52. package/dist/platform/migrations/0817_checklist_day_window.sql +35 -0
  53. package/dist/platform/migrations/0850_agreements.sql +271 -0
  54. package/dist/platform/migrations/0851_agreement_acceptances.sql +387 -0
  55. package/dist/platform/migrations/0853_agreement_enforcement.sql +58 -0
  56. package/dist/platform/migrations/0854_agreement_copy.sql +149 -0
  57. package/dist/platform/migrations/0855_agreement_retention.sql +279 -0
  58. package/dist/platform/migrations/0856_subscription_cooling_off.sql +159 -0
  59. package/dist/platform/migrations/0857_agreement_copy_guardian.sql +337 -0
  60. package/dist/platform/migrations/0858_agreement_desk.sql +175 -0
  61. package/dist/platform/migrations/0910_routine_messages.sql +99 -0
  62. package/dist/platform/migrations/0911_texts.sql +60 -0
  63. package/dist/platform/migrations/0913_contact_consent.sql +93 -0
  64. package/dist/platform/migrations/0916_contact_mailbox_index.sql +29 -0
  65. package/dist/platform/migrations/0930_stock_movements.sql +95 -0
  66. package/dist/platform/migrations/0931_stock_low.sql +25 -0
  67. package/dist/platform/migrations/0932_order_delivery.sql +78 -0
  68. package/dist/platform/migrations/0950_order_adjustments.sql +111 -0
  69. package/dist/platform/migrations/0951_order_price_guards.sql +33 -0
  70. package/dist/platform/migrations/0952_order_paid_another_way.sql +194 -0
  71. package/dist/platform/migrations/0953_discount_uses.sql +183 -0
  72. package/dist/platform/migrations/0955_folded_addresses.sql +92 -0
  73. package/dist/platform/migrations/0970_published_text.sql +59 -0
  74. package/dist/platform/migrations/0971_publish_acks.sql +68 -0
  75. package/dist/platform/migrations/0990_customer_email_change.sql +65 -0
  76. package/dist/platform/migrations/1010_intake_links.sql +148 -0
  77. package/dist/platform/migrations/1030_invoices.sql +747 -0
  78. package/dist/platform/migrations/1031_invoice_orders.sql +327 -0
  79. package/dist/platform/migrations/1050_inbox_conversations.sql +83 -0
  80. package/dist/platform/migrations/1090_staff_hours.sql +43 -0
  81. package/dist/platform/migrations/1091_staff_time_margins.sql +12 -0
  82. package/dist/platform/migrations/1092_client_guard.sql +26 -0
  83. package/dist/platform/migrations/1095_thing_time.sql +70 -0
  84. package/dist/platform/migrations/1130_devices.sql +162 -0
  85. package/dist/platform/migrations/1135_person_codes.sql +88 -0
  86. package/dist/platform/migrations/1150_finance_periods.sql +316 -0
  87. package/dist/platform/migrations/1151_payouts.sql +202 -0
  88. package/dist/platform/migrations/1153_finance_money_dates.sql +18 -0
  89. package/dist/platform/migrations/1170_journeys.sql +318 -0
  90. package/dist/platform/migrations/1171_person_birthday.sql +52 -0
  91. package/dist/platform/migrations/1175_person_signals.sql +29 -0
  92. package/dist/platform/migrations/1190_restricted_values.sql +25 -0
  93. package/dist/platform/migrations/1230_note_levels.sql +113 -0
  94. package/dist/platform/migrations/1231_person_carers.sql +33 -0
  95. package/dist/platform/migrations/1232_note_kinds.sql +122 -0
  96. package/dist/platform/migrations/1270_time_entries.sql +145 -0
  97. package/dist/platform/migrations/1271_leave.sql +249 -0
  98. package/dist/platform/migrations/1273_time_entry_reopened.sql +21 -0
  99. package/dist/platform/migrations/1330_accounting.sql +260 -0
  100. package/dist/platform/migrations/1350_customer_feed.sql +24 -0
  101. package/dist/platform/migrations/1390_locations.sql +77 -0
  102. package/dist/platform/migrations/1410_outside_copy.sql +213 -0
  103. package/dist/platform/migrations/1430_inbox_activities.sql +231 -0
  104. package/dist/platform/migrations/1450_wrong_guesses.sql +23 -0
  105. package/dist/platform/sdk/acknowledge.ts +100 -0
  106. package/dist/platform/sdk/agreements.ts +185 -0
  107. package/dist/platform/sdk/allowance.ts +98 -8
  108. package/dist/platform/sdk/automation-check.ts +120 -9
  109. package/dist/platform/sdk/automation.ts +78 -10
  110. package/dist/platform/sdk/behaviour.ts +26 -6
  111. package/dist/platform/sdk/calendar-entry.ts +258 -0
  112. package/dist/platform/sdk/capacity.ts +1 -2
  113. package/dist/platform/sdk/checklists.ts +118 -0
  114. package/dist/platform/sdk/contract.ts +489 -27
  115. package/dist/platform/sdk/discount.ts +408 -0
  116. package/dist/platform/sdk/document.ts +4 -2
  117. package/dist/platform/sdk/field-types.ts +5 -0
  118. package/dist/platform/sdk/formula/compile.ts +10 -0
  119. package/dist/platform/sdk/index.ts +17 -0
  120. package/dist/platform/sdk/intake.ts +380 -0
  121. package/dist/platform/sdk/journey-signals.ts +215 -0
  122. package/dist/platform/sdk/manifest.ts +1236 -65
  123. package/dist/platform/sdk/mine.ts +161 -0
  124. package/dist/platform/sdk/occupies.ts +192 -0
  125. package/dist/platform/sdk/questions.ts +681 -0
  126. package/dist/platform/sdk/recurring.ts +90 -9
  127. package/dist/platform/sdk/restricted-fields.ts +129 -0
  128. package/dist/platform/sdk/rich-text.ts +112 -0
  129. package/dist/platform/sdk/routine-mail.ts +1272 -0
  130. package/dist/platform/sdk/runtime.ts +25 -12
  131. package/dist/platform/sdk/screens.ts +91 -0
  132. package/dist/platform/sdk/sellable.ts +344 -0
  133. package/dist/platform/sdk/slug.ts +7 -2
  134. package/dist/platform/sdk/staffed.ts +474 -0
  135. package/dist/platform/sdk/states.ts +68 -26
  136. package/dist/platform/sdk/stock.ts +332 -0
  137. package/dist/platform/sdk/team.ts +83 -0
  138. package/dist/platform/sdk/testing.ts +70 -6
  139. package/dist/platform/sdk/worked-on.ts +134 -0
  140. package/dist/{products-2H5DR232.js → products-GCQLSZ3U.js} +2 -2
  141. package/dist/run-7ID64RA6.js +65 -0
  142. package/dist/run-FH7OGGTV.js +131 -0
  143. package/dist/run-OYZIAP6M.js +3363 -0
  144. package/dist/{run-ZCGFMEZF.js → run-QOFRRSZV.js} +41 -60
  145. package/dist/{run-PO3W5BFA.js → run-TJAEWR5U.js} +21 -51
  146. package/dist/{src-I3IJ4NKC.js → src-52VERUPK.js} +306 -4
  147. package/dist/src-PHRELWN5.js +40 -0
  148. package/dist/{visibility-TVXZ67FD.js → visibility-SZCINPP4.js} +21 -4
  149. package/package.json +2 -2
  150. package/dist/chunk-2TWV3SVB.js +0 -349
  151. package/dist/chunk-2XC5JLBO.js +0 -1931
  152. package/dist/chunk-324WJXNP.js +0 -320
  153. package/dist/chunk-6ELZRNUU.js +0 -116
  154. package/dist/chunk-6WGFA2IV.js +0 -643
  155. package/dist/chunk-7CQGMVDO.js +0 -63
  156. package/dist/chunk-7OGCMQXG.js +0 -284
  157. package/dist/chunk-FJIZGS5Q.js +0 -698
  158. package/dist/chunk-UB4I2QKR.js +0 -31575
  159. package/dist/chunk-WHKJGF36.js +0 -2418
  160. package/dist/chunk-YNUZRTPH.js +0 -182
  161. package/dist/chunk-ZZFWMVJO.js +0 -704
  162. package/dist/grants-LOW6TSWD.js +0 -32
  163. package/dist/invoke-6KVT6WJI.js +0 -41
  164. package/dist/moves-E2HKYCTK.js +0 -41
  165. package/dist/plan-on-sale-TJPFCNL7.js +0 -26
  166. package/dist/src-CRO35DYY.js +0 -46
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ coreInvoker,
4
+ coreRegistry,
5
+ createInvoker,
6
+ invoke,
7
+ invokeByName,
8
+ listOperations
9
+ } from "./chunk-HCG6T53D.js";
10
+ import "./chunk-6CM3WZG5.js";
11
+ import "./chunk-JX4IFWNT.js";
12
+ import "./chunk-5D7BDF4Y.js";
13
+ import "./chunk-Z7OVQ6BC.js";
14
+ import "./chunk-2B6YUYZV.js";
15
+ import "./chunk-KMFMD52Z.js";
16
+ import "./chunk-3OGDWKJ3.js";
17
+ import "./chunk-KGHA67HG.js";
18
+ import "./chunk-ZJSFX4RD.js";
19
+ import "./chunk-KFHKNXGH.js";
20
+ import "./chunk-RSEWEFAV.js";
21
+ import "./chunk-CIBJGB5H.js";
22
+ import "./chunk-U72NEGCT.js";
23
+ import "./chunk-Q6Y45DY6.js";
24
+ import "./chunk-RGKJKC5T.js";
25
+ import "./chunk-5KSXSK7Y.js";
26
+ export {
27
+ coreInvoker,
28
+ coreRegistry,
29
+ createInvoker,
30
+ invoke,
31
+ invokeByName,
32
+ listOperations
33
+ };
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ DEFAULT_HOLD_PERCENT,
4
+ UNSETTLED_RELEASES,
5
+ UNSETTLED_SCAN,
6
+ movedRecords,
7
+ movesFollowPerson,
8
+ movesOf,
9
+ oweLateRefund,
10
+ releaseUnsettledGuest,
11
+ startHeld,
12
+ unsettledGuests
13
+ } from "./chunk-Z7OVQ6BC.js";
14
+ import "./chunk-2B6YUYZV.js";
15
+ import "./chunk-KMFMD52Z.js";
16
+ import "./chunk-KGHA67HG.js";
17
+ import "./chunk-ZJSFX4RD.js";
18
+ import "./chunk-KFHKNXGH.js";
19
+ import "./chunk-RSEWEFAV.js";
20
+ import "./chunk-CIBJGB5H.js";
21
+ import "./chunk-U72NEGCT.js";
22
+ import "./chunk-Q6Y45DY6.js";
23
+ import "./chunk-RGKJKC5T.js";
24
+ import "./chunk-5KSXSK7Y.js";
25
+ export {
26
+ DEFAULT_HOLD_PERCENT,
27
+ UNSETTLED_RELEASES,
28
+ UNSETTLED_SCAN,
29
+ movedRecords,
30
+ movesFollowPerson,
31
+ movesOf,
32
+ oweLateRefund,
33
+ releaseUnsettledGuest,
34
+ startHeld,
35
+ unsettledGuests
36
+ };
@@ -6,8 +6,8 @@ import {
6
6
  ORDER_STATES,
7
7
  orderLineObject,
8
8
  orderObject
9
- } from "./chunk-7D4GKZOX.js";
10
- import "./chunk-LO6WGU5Y.js";
9
+ } from "./chunk-CIBJGB5H.js";
10
+ import "./chunk-U72NEGCT.js";
11
11
  import "./chunk-5KSXSK7Y.js";
12
12
  export {
13
13
  BASE_OBJECTS,
@@ -17,6 +17,7 @@ import {
17
17
  personOperations,
18
18
  personRestore,
19
19
  personSchema,
20
+ personSetBirthday,
20
21
  personSnapshot,
21
22
  personUpdate,
22
23
  personUpdateMany,
@@ -24,19 +25,18 @@ import {
24
25
  phoneInputSchema,
25
26
  socialProfileSchema,
26
27
  updatePerson
27
- } from "./chunk-XIDLW3EP.js";
28
- import "./chunk-FJIZGS5Q.js";
29
- import "./chunk-2TWV3SVB.js";
28
+ } from "./chunk-2B6YUYZV.js";
30
29
  import {
31
30
  TRASH_RETENTION_DAYS
32
- } from "./chunk-ZZFWMVJO.js";
33
- import "./chunk-2XC5JLBO.js";
31
+ } from "./chunk-KMFMD52Z.js";
34
32
  import "./chunk-KGHA67HG.js";
35
- import "./chunk-6UWRT4VM.js";
36
- import "./chunk-6XTU2MTP.js";
37
- import "./chunk-YFTLIEWU.js";
38
- import "./chunk-7D4GKZOX.js";
39
- import "./chunk-LO6WGU5Y.js";
33
+ import "./chunk-ZJSFX4RD.js";
34
+ import "./chunk-KFHKNXGH.js";
35
+ import "./chunk-RSEWEFAV.js";
36
+ import "./chunk-CIBJGB5H.js";
37
+ import "./chunk-U72NEGCT.js";
38
+ import "./chunk-Q6Y45DY6.js";
39
+ import "./chunk-RGKJKC5T.js";
40
40
  import "./chunk-5KSXSK7Y.js";
41
41
  export {
42
42
  TRASH_RETENTION_DAYS,
@@ -57,6 +57,7 @@ export {
57
57
  personOperations,
58
58
  personRestore,
59
59
  personSchema,
60
+ personSetBirthday,
60
61
  personSnapshot,
61
62
  personUpdate,
62
63
  personUpdateMany,
@@ -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-5D7BDF4Y.js";
9
+ import "./chunk-2B6YUYZV.js";
10
+ import "./chunk-KMFMD52Z.js";
11
+ import "./chunk-KGHA67HG.js";
12
+ import "./chunk-ZJSFX4RD.js";
13
+ import "./chunk-KFHKNXGH.js";
14
+ import "./chunk-RSEWEFAV.js";
15
+ import "./chunk-CIBJGB5H.js";
16
+ import "./chunk-U72NEGCT.js";
17
+ import "./chunk-Q6Y45DY6.js";
18
+ import "./chunk-RGKJKC5T.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,79 @@
1
+ -- Migration 0730: practitioner accounts (stage 43 step 3, ADR 0581).
2
+ --
3
+ -- A practitioner is an outside person the business invites (a physiotherapist, a dietitian): a
4
+ -- fourth kind of caller beside staff, customers and the public. They sign in through a third
5
+ -- Better Auth configuration (packages/auth/src/practitioner-auth.ts) with its own tables, cookie
6
+ -- and key, so a practitioner session is never in core_session or core_customer_session, and a
7
+ -- staff or customer session is never in core_practitioner_session. A practitioner is never a
8
+ -- core_user and never a core_customer, and holds no role.
9
+ --
10
+ -- One address may hold a staff account, a customer account and a practitioner account at once
11
+ -- (decision 16): the three tables are apart and nothing joins them.
12
+ --
13
+ -- Column names are snake_case; packages/auth maps Better Auth's camelCase fields onto them. No
14
+ -- table here stores a client address: the session has no column for it, as a customer's has none.
15
+
16
+ CREATE TABLE core_practitioner (
17
+ -- prc_… (ids.ts).
18
+ id TEXT PRIMARY KEY NOT NULL,
19
+ -- The practitioner's own Person in the host: their name and contact, as staff see them. One
20
+ -- account per Person. Erasing the Person deletes the account and, through it, its sessions
21
+ -- (as for a customer account, migration 0401); stage 43 step 5 keeps the row for authored work.
22
+ person_id TEXT NOT NULL REFERENCES core_person (id) ON DELETE CASCADE,
23
+ -- The sign-in address, lower-cased and trimmed. One practitioner account per address.
24
+ email TEXT NOT NULL UNIQUE CHECK (email = lower(trim(email)) AND email <> ''),
25
+ -- Always 1: Better Auth reads it, and treats an unverified user as one with access to revoke.
26
+ -- A practitioner account has no password and no other way in: the emailed code is the only one,
27
+ -- and it proves the address at every sign-in.
28
+ email_verified INTEGER NOT NULL DEFAULT 1 CHECK (email_verified = 1),
29
+ -- The name the invite gave, which the practitioner sees as theirs.
30
+ name TEXT NOT NULL CHECK (length(trim(name)) BETWEEN 1 AND 200),
31
+ -- A label ("Physiotherapist"); nothing is limited by it.
32
+ discipline TEXT NOT NULL CHECK (length(trim(discipline)) BETWEEN 1 AND 80),
33
+ -- The outside business they work for, an Organisation in the host. Optional.
34
+ practice_id TEXT REFERENCES core_organisation (id) ON DELETE SET NULL,
35
+ -- 'invited' until the first sign-in, then 'active'. 'ended': cannot sign in, every session is
36
+ -- deleted in the batch that ends it, and a session left anyway resolves to no one.
37
+ status TEXT NOT NULL DEFAULT 'invited' CHECK (status IN ('invited', 'active', 'ended')),
38
+ invited_by TEXT NOT NULL,
39
+ invited_at TEXT NOT NULL,
40
+ activated_at TEXT,
41
+ ended_at TEXT,
42
+ ended_by TEXT,
43
+ ended_reason TEXT CHECK (ended_reason IS NULL OR length(ended_reason) <= 500),
44
+ last_sign_in_at TEXT,
45
+ created_at DATE NOT NULL,
46
+ updated_at DATE NOT NULL,
47
+ CHECK ((status = 'ended') = (ended_at IS NOT NULL)),
48
+ CHECK (status <> 'active' OR activated_at IS NOT NULL),
49
+ CHECK (status <> 'invited' OR activated_at IS NULL)
50
+ );
51
+ CREATE UNIQUE INDEX core_practitioner_person_uq ON core_practitioner (person_id);
52
+ CREATE INDEX core_practitioner_status_idx ON core_practitioner (status, invited_at);
53
+
54
+ CREATE TABLE core_practitioner_session (
55
+ id TEXT PRIMARY KEY NOT NULL,
56
+ practitioner_id TEXT NOT NULL REFERENCES core_practitioner (id) ON DELETE CASCADE,
57
+ token TEXT NOT NULL UNIQUE,
58
+ expires_at DATE NOT NULL,
59
+ created_at DATE NOT NULL,
60
+ updated_at DATE NOT NULL
61
+ );
62
+ CREATE INDEX core_practitioner_session_practitioner_idx
63
+ ON core_practitioner_session (practitioner_id);
64
+
65
+ -- One-time sign-in codes, stored hashed. The identifier names the address the code was sent to.
66
+ CREATE TABLE core_practitioner_verification (
67
+ id TEXT PRIMARY KEY NOT NULL,
68
+ identifier TEXT NOT NULL,
69
+ value TEXT NOT NULL,
70
+ expires_at DATE NOT NULL,
71
+ created_at DATE NOT NULL,
72
+ updated_at DATE NOT NULL
73
+ );
74
+ CREATE INDEX core_practitioner_verification_identifier_idx
75
+ ON core_practitioner_verification (identifier);
76
+
77
+ -- Guarded: migrations land out of order (docs/parallel-work.md).
78
+ UPDATE core_meta SET value = '730'
79
+ WHERE key = 'schema_version' AND CAST(value AS INTEGER) < 730;
@@ -0,0 +1,98 @@
1
+ -- Migration 0750: routine mail (ADR 0590). One row per routine email the host was asked to send:
2
+ -- a kind a shipped pack declares (a booking's confirmation, a class reminder), about one record,
3
+ -- to one recipient the host chose from that record. The row is the audit of what was sent on its
4
+ -- own, and what the integration host reads to send it: `callAsHost` with purpose `routine-mail`
5
+ -- takes only a row's id and composes the email from the row, so nothing a caller passes becomes
6
+ -- the message or the recipient.
7
+ --
8
+ -- `routine`: 1 when it may go without a person (the pack turned on, the kind on, every value
9
+ -- checked, nothing about it an AI wrote that no person approved), 0 when it is not: `ordinary`
10
+ -- 1 while the pack's routine email is not turned on (decided as before routine mail, by the
11
+ -- policy), else held for a person (`held_reason`). The daily caps are counted when the
12
+ -- integration host claims a row (`claimed_at`), in one statement, so concurrent runs cannot race
13
+ -- past them: per mailbox (`recipient_key`, plus-tags and case folded) and for the organisation.
14
+ -- `status`: `off` (the kind is turned off: nothing sent, nothing queued); `ready` (to send);
15
+ -- `sending` (the integration host took it); `sent`; `waiting` (in Approvals for a person, with
16
+ -- `pending_action_id`); `denied` (the deploy floor refused it); `failed` (`error`).
17
+ --
18
+ -- `subject`, `body` and `calendar` are what is sent, kept until it is decided and then cleared
19
+ -- (the kind, the record and the recipient stay, for the admin's count and the audit). A person's
20
+ -- erase deletes their rows.
21
+ CREATE TABLE core_routine_mail (
22
+ id TEXT PRIMARY KEY,
23
+ -- `<extension>.<kind>`, and the kind's message.
24
+ kind TEXT NOT NULL,
25
+ message TEXT NOT NULL,
26
+ extension_id TEXT NOT NULL,
27
+ record_object TEXT NOT NULL,
28
+ record_id TEXT NOT NULL,
29
+ recipient TEXT NOT NULL,
30
+ -- How the host chose the recipient: `person` (the record's customer), `guardian` (a live
31
+ -- guardian of that person, ADR 0540) or `order` (a paid order's own address, ADR 0560).
32
+ recipient_rule TEXT NOT NULL CHECK (recipient_rule IN ('person', 'guardian', 'order')),
33
+ recipient_person_id TEXT,
34
+ -- The mailbox the recipient most likely reaches (ADR 0459's key), for the per-address cap.
35
+ recipient_key TEXT NOT NULL,
36
+ -- The Person the record is about (a child's booking: the child), so their erase removes the
37
+ -- rows about them, those sent to their guardians included.
38
+ about_person_id TEXT,
39
+ automation_id TEXT NOT NULL,
40
+ run_id TEXT NOT NULL,
41
+ -- The run's trigger type, and who made the change that started it (JSON `{ actor, userId,
42
+ -- approved }`, or null for a schedule or a moment).
43
+ trigger_type TEXT NOT NULL,
44
+ triggered_by TEXT,
45
+ -- The run its chain of retries began with, the kind, message, record and recipient: a retried
46
+ -- step finds the row it made and sends nothing twice.
47
+ idempotency_key TEXT NOT NULL UNIQUE,
48
+ routine INTEGER NOT NULL CHECK (routine IN (0, 1)),
49
+ ordinary INTEGER NOT NULL DEFAULT 0 CHECK (ordinary IN (0, 1)),
50
+ claimed_at TEXT,
51
+ held_reason TEXT,
52
+ status TEXT NOT NULL
53
+ CHECK (status IN ('off', 'ready', 'sending', 'sent', 'waiting', 'denied', 'failed')),
54
+ connection_id TEXT,
55
+ subject TEXT,
56
+ body TEXT,
57
+ calendar TEXT,
58
+ related TEXT,
59
+ -- The values the email showed and who stood behind each (JSON `[{o, r, f, h}]`): approving a
60
+ -- held email marks exactly these, as they were when it was prepared.
61
+ sources TEXT,
62
+ pending_action_id TEXT,
63
+ error TEXT,
64
+ created_at TEXT NOT NULL,
65
+ updated_at TEXT NOT NULL
66
+ );
67
+
68
+ -- The daily cap per recipient, and the admin's counts per kind.
69
+ CREATE INDEX core_routine_mail_recipient_idx ON core_routine_mail (recipient_key, claimed_at);
70
+ CREATE INDEX core_routine_mail_claimed_idx ON core_routine_mail (claimed_at)
71
+ WHERE claimed_at IS NOT NULL;
72
+ CREATE INDEX core_routine_mail_about_idx ON core_routine_mail (about_person_id)
73
+ WHERE about_person_id IS NOT NULL;
74
+ CREATE INDEX core_routine_mail_record_idx ON core_routine_mail (record_object, record_id);
75
+ CREATE INDEX core_routine_mail_kind_idx ON core_routine_mail (kind, created_at);
76
+ CREATE INDEX core_routine_mail_created_idx ON core_routine_mail (created_at);
77
+ CREATE INDEX core_routine_mail_person_idx ON core_routine_mail (recipient_person_id)
78
+ WHERE recipient_person_id IS NOT NULL;
79
+
80
+ -- Who stands behind each value (ADR 0590, the review's default deny): one row per record field,
81
+ -- written by the host in the batch of every write it records (the pipeline), with a SHA-256 of the
82
+ -- value written, so a mark never applies to a different value. `standing`: `person` (a human staff
83
+ -- account's own write, or a write a human approved), `customer` (the customer's own write),
84
+ -- `public` (an unauthenticated buyer), `default` (a declared default), `host` (the host's own
85
+ -- write with no source a person stands behind), `ai` (an AI's write, or one only the adjudicator
86
+ -- approved). A copy (a series' class, a title taken from a class type, a moved booking) carries
87
+ -- the weakest mark of its sources. `$created` is the record's creation.
88
+ CREATE TABLE core_value_mark (
89
+ object_type TEXT NOT NULL,
90
+ record_id TEXT NOT NULL,
91
+ field TEXT NOT NULL,
92
+ value_hash TEXT NOT NULL,
93
+ standing TEXT NOT NULL
94
+ CHECK (standing IN ('person', 'customer', 'public', 'default', 'host', 'ai')),
95
+ by_id TEXT,
96
+ at TEXT NOT NULL,
97
+ PRIMARY KEY (object_type, record_id, field)
98
+ ) WITHOUT ROWID;
@@ -0,0 +1,64 @@
1
+ -- Migration 0770 (issue #258, ADR 0600): before ADR 0600 a permission granted to an account that
2
+ -- holds a pack role counted for nothing (ADR 0449), yet `user.setPermissions`, `user.setPackRole`
3
+ -- and the invites kept such grants stored. ADR 0600 makes a pack role's grants count, so a stored,
4
+ -- inert grant would come alive on upgrade with no admin's act (a viewer once granted
5
+ -- `memberships:passes`, later made a coach, would give passes again). This clears them: they
6
+ -- counted for nothing until now, so nothing anyone relied on is lost. An admin re-ticks what they
7
+ -- want on Settings > Users.
8
+ --
9
+ -- One audit row says how many accounts and pending invites were cleared (written only when there
10
+ -- were any), and each account's change is recorded on it as a change to the user, the list before
11
+ -- and after, as `user.setPermissions` records one.
12
+ INSERT INTO core_audit
13
+ (id, at, operation, risk, actor, user_id, origin, input, result, gate_decision, outcome, error,
14
+ pending_action_id)
15
+ SELECT
16
+ 'aud_migration0770',
17
+ strftime('%Y-%m-%dT%H:%M:%fZ', 'now'),
18
+ 'migration.clearFixedRoleGrants',
19
+ 'write',
20
+ 'automation',
21
+ NULL,
22
+ json('{"surface":"system"}'),
23
+ json('{"migration":770}'),
24
+ json_object(
25
+ 'accounts', (SELECT count(*) FROM core_user
26
+ WHERE pack_role IS NOT NULL AND granted_permissions IS NOT NULL),
27
+ 'invites', (SELECT count(*) FROM core_user_invite
28
+ WHERE pack_role IS NOT NULL AND granted_permissions IS NOT NULL),
29
+ 'note', 'Permissions stored on accounts with a fixed role counted for nothing before ADR 0600 and were cleared; re-tick any you want on Settings > Users.'
30
+ ),
31
+ 'auto',
32
+ 'ok',
33
+ NULL,
34
+ NULL
35
+ WHERE EXISTS (SELECT 1 FROM core_user WHERE pack_role IS NOT NULL AND granted_permissions IS NOT NULL)
36
+ OR EXISTS (SELECT 1 FROM core_user_invite
37
+ WHERE pack_role IS NOT NULL AND granted_permissions IS NOT NULL);
38
+
39
+ INSERT INTO core_audit_changes (audit_id, object_type, record_id, action, diff, at)
40
+ SELECT
41
+ 'aud_migration0770',
42
+ 'user',
43
+ id,
44
+ 'update',
45
+ json_object(
46
+ 'permissions',
47
+ json_object(
48
+ 'before',
49
+ CASE WHEN json_valid(granted_permissions) THEN json(granted_permissions) ELSE json('[]') END,
50
+ 'after',
51
+ json('[]')
52
+ )
53
+ ),
54
+ strftime('%Y-%m-%dT%H:%M:%fZ', 'now')
55
+ FROM core_user
56
+ WHERE pack_role IS NOT NULL AND granted_permissions IS NOT NULL;
57
+
58
+ UPDATE core_user
59
+ SET granted_permissions = NULL, updated_at = strftime('%Y-%m-%dT%H:%M:%fZ', 'now')
60
+ WHERE pack_role IS NOT NULL AND granted_permissions IS NOT NULL;
61
+
62
+ UPDATE core_user_invite
63
+ SET granted_permissions = NULL
64
+ WHERE pack_role IS NOT NULL AND granted_permissions IS NOT NULL;
@@ -0,0 +1,66 @@
1
+ -- Migration 0810: field-level exceptions in the `recurring` behaviour (stage 45 step 1, ADR 0620,
2
+ -- amending ADR 0500).
3
+ --
4
+ -- A record a series made, one of whose copied fields someone other than the host changed (a coach
5
+ -- swapped on one class), keeps that field as its own: one row here per record and field, with who
6
+ -- set it and when. The series never writes that field of that record again, and still writes the
7
+ -- others (a new room, new places). Removing the row (`recurring.follow`, or setting the field by
8
+ -- hand back to the series' value) makes the field follow the series again.
9
+ --
10
+ -- A record whose time, zone or state was changed by hand is still detached whole
11
+ -- (core_recurrence_occurrence.edited_at, migration 0560), as before. Nothing here changes a record
12
+ -- that is already detached: every occurrence with edited_at set stays detached whole, exactly as
13
+ -- it was read before this migration; a person makes one follow again with `recurring.follow`.
14
+ CREATE TABLE core_recurrence_exception (
15
+ -- The generated record (the same pair as core_recurrence_occurrence's object_type, record_id).
16
+ object_type TEXT NOT NULL,
17
+ record_id TEXT NOT NULL,
18
+ -- The generated object's field the record keeps as its own (a `copy` target).
19
+ field TEXT NOT NULL,
20
+ -- The staff account whose write made it the record's own, and when (ISO instant). Changed
21
+ -- again by hand, both are the latest write's.
22
+ set_by TEXT NOT NULL,
23
+ set_at TEXT NOT NULL,
24
+ PRIMARY KEY (object_type, record_id, field)
25
+ ) WITHOUT ROWID;
26
+
27
+ -- Each occurrence's version: bumped by a write by hand to its record (an exception set or cleared,
28
+ -- the record detached, `recurring.follow`) and by a change of its series. Existing rows start at 0.
29
+ ALTER TABLE core_recurrence_occurrence ADD COLUMN version INTEGER NOT NULL DEFAULT 0;
30
+
31
+ -- Guards for a batch planned from a read of occurrences (as core_write_guard is for series and
32
+ -- places, migration 0560; a table of its own so that one, which other builds rebuild, is not
33
+ -- touched). A statement inserts what it read; the trigger compares it with what is there now, in
34
+ -- the batch, and either drops the row (still true) or fails the whole batch. Nothing is stored.
35
+ -- kind 'occurrence': one record's occurrence version is still `expected` (a hand edit: a series
36
+ -- change that touched it meanwhile fails the edit)
37
+ -- kind 'occurrences': the sum of a series' occurrence versions from `from_date` on is still
38
+ -- `expected` (a series change: a hand edit of one of them meanwhile fails it)
39
+ -- Edits of different records of one series do not contend, and neither contends with a run.
40
+ CREATE TABLE core_recurrence_guard (
41
+ kind TEXT NOT NULL CHECK (kind IN ('occurrence', 'occurrences')),
42
+ object_type TEXT NOT NULL,
43
+ record_id TEXT NOT NULL,
44
+ from_date TEXT,
45
+ expected INTEGER NOT NULL
46
+ );
47
+
48
+ CREATE TRIGGER core_recurrence_guard_check
49
+ BEFORE INSERT ON core_recurrence_guard
50
+ BEGIN
51
+ SELECT CASE
52
+ -- A missing occurrence (its date removed by a series change meanwhile) is stale too.
53
+ WHEN NEW.kind = 'occurrence' AND coalesce((SELECT version FROM core_recurrence_occurrence
54
+ WHERE object_type = NEW.object_type AND record_id = NEW.record_id), -1) != NEW.expected
55
+ THEN RAISE(ABORT, 'core_recurrence_stale')
56
+ WHEN NEW.kind = 'occurrences' AND coalesce((SELECT sum(version) FROM core_recurrence_occurrence
57
+ WHERE series_object = NEW.object_type AND series_id = NEW.record_id
58
+ AND local_date >= NEW.from_date), 0) != NEW.expected
59
+ THEN RAISE(ABORT, 'core_recurrence_stale')
60
+ ELSE RAISE(IGNORE)
61
+ END;
62
+ END;
63
+
64
+ -- Guarded: migrations land out of order (docs/parallel-work.md).
65
+ UPDATE core_meta SET value = '810'
66
+ WHERE key = 'schema_version' AND CAST(value AS INTEGER) < 810;
@@ -0,0 +1,109 @@
1
+ -- Migration 0811: the `staffed` behaviour's time claim, and what its warnings read (stage 45
2
+ -- step 2, ADRs 0621 and 0622).
3
+ --
4
+ -- A record of an object that declares `staffed` is a shift: a time someone works. Every live,
5
+ -- covered shift whose person has a staff account holds one claim here: the account, the record,
6
+ -- and the shift's own time as whole unix seconds, half-open (06:00 to 07:00 and 07:00 to 08:00 do
7
+ -- not clash). The database refuses a claim that overlaps another of the same account's, so one
8
+ -- person is never on two overlapping shifts, whoever writes and however many write at once: D1
9
+ -- runs one batch at a time, so of two batches that would double-book one person, the second
10
+ -- fails whole.
11
+ --
12
+ -- The claims are kept by triggers the schema reconciler builds on each staffed object's own table
13
+ -- (and on the table holding the account, a class's coach profile), so every statement that writes
14
+ -- a shift writes its claim in the same statement: a create, an edit, a move, a cancel, the Trash
15
+ -- and a restore, an erase, a merge, a series' generation and changes. No migration touches an
16
+ -- x_* table. D1 runs with recursive triggers off, so the rows an INSERT OR REPLACE or an UPDATE OR
17
+ -- REPLACE deletes fire no delete trigger: the checks below are BEFORE INSERT and BEFORE UPDATE on
18
+ -- every column (a REPLACE and an upsert are inserts first, and an id update is an update), and
19
+ -- each leaves out only the row's own key, which such a statement replaces. A claim left behind by
20
+ -- a row a REPLACE deleted can only refuse more, never let a double-booking through.
21
+ CREATE TABLE core_staff_time (
22
+ -- The shift: its object's registry name and its record.
23
+ object_type TEXT NOT NULL,
24
+ record_id TEXT NOT NULL,
25
+ -- The staff account working it (core_user.id).
26
+ account_id TEXT NOT NULL,
27
+ -- Its own time, unix seconds; preparation and pack-down never count here (pay only).
28
+ starts INTEGER NOT NULL,
29
+ ends INTEGER NOT NULL,
30
+ PRIMARY KEY (object_type, record_id),
31
+ CHECK (ends > starts)
32
+ ) WITHOUT ROWID;
33
+
34
+ -- By account and end: an overlap check reads only the claims that end after the new one starts
35
+ -- (an account's past shifts are never read), however long its history.
36
+ CREATE INDEX core_staff_time_account ON core_staff_time (account_id, ends, starts);
37
+
38
+ CREATE TRIGGER core_staff_time_insert
39
+ BEFORE INSERT ON core_staff_time
40
+ BEGIN
41
+ SELECT RAISE(ABORT, 'core_staff_double_booked')
42
+ WHERE EXISTS (
43
+ SELECT 1 FROM core_staff_time c
44
+ WHERE c.account_id = NEW.account_id
45
+ AND NOT (c.object_type = NEW.object_type AND c.record_id = NEW.record_id)
46
+ AND c.ends > NEW.starts AND c.starts < NEW.ends
47
+ );
48
+ END;
49
+
50
+ CREATE TRIGGER core_staff_time_update
51
+ BEFORE UPDATE ON core_staff_time
52
+ BEGIN
53
+ SELECT RAISE(ABORT, 'core_staff_double_booked')
54
+ WHERE EXISTS (
55
+ SELECT 1 FROM core_staff_time c
56
+ WHERE c.account_id = NEW.account_id
57
+ AND NOT (c.object_type = OLD.object_type AND c.record_id = OLD.record_id)
58
+ AND NOT (c.object_type = NEW.object_type AND c.record_id = NEW.record_id)
59
+ AND c.ends > NEW.starts AND c.starts < NEW.ends
60
+ );
61
+ END;
62
+
63
+ -- Who may do which kind of work (ADR 0622): an account, and a kind record (a class type, a duty).
64
+ -- Nobody is qualified by default; a shift whose person is not qualified for its kind is made with
65
+ -- a `not_qualified` warning. Set by a rosterer (stage 45 step 3, `staffing.qualify`). About staff
66
+ -- accounts: in no rec_* view, so no member's SQL, export or the assistant's record reads see it.
67
+ CREATE TABLE core_staff_qualification (
68
+ account_id TEXT NOT NULL,
69
+ kind_object TEXT NOT NULL,
70
+ kind_record TEXT NOT NULL,
71
+ set_by TEXT NOT NULL,
72
+ set_at TEXT NOT NULL,
73
+ PRIMARY KEY (account_id, kind_object, kind_record)
74
+ ) WITHOUT ROWID;
75
+
76
+ -- When someone said they cannot work (ADR 0622): one-off (leave, or other) as a range of instants,
77
+ -- with the zone it was given in; or regular (every Wednesday afternoon) as weekdays and a local
78
+ -- start and end time in a zone, from a date and until one (empty: ongoing), checked by wall clock
79
+ -- on the fly, so 13:00 is 13:00 on both sides of a clock change. An end at or before the start is
80
+ -- the next day's (an overnight rule). Made by the person or a rosterer (step 3, `staffing.away`);
81
+ -- read for the `unavailable` warning. Personal: in no rec_* view.
82
+ CREATE TABLE core_staff_away (
83
+ id TEXT PRIMARY KEY,
84
+ account_id TEXT NOT NULL,
85
+ kind TEXT NOT NULL CHECK (kind IN ('leave', 'regular', 'other')),
86
+ note TEXT CHECK (note IS NULL OR length(note) <= 500),
87
+ starts_at TEXT,
88
+ ends_at TEXT,
89
+ -- Weekdays as a comma list of mon … sun.
90
+ weekdays TEXT,
91
+ start_time TEXT CHECK (start_time IS NULL OR start_time GLOB '[0-2][0-9]:[0-5][0-9]'),
92
+ end_time TEXT CHECK (end_time IS NULL OR end_time GLOB '[0-2][0-9]:[0-5][0-9]'),
93
+ from_date TEXT,
94
+ until_date TEXT,
95
+ zone TEXT NOT NULL,
96
+ set_by TEXT NOT NULL,
97
+ set_at TEXT NOT NULL,
98
+ CHECK (kind != 'regular' OR (weekdays IS NOT NULL AND start_time IS NOT NULL
99
+ AND end_time IS NOT NULL AND from_date IS NOT NULL AND starts_at IS NULL AND ends_at IS NULL)),
100
+ CHECK (kind = 'regular' OR (starts_at IS NOT NULL AND ends_at IS NOT NULL AND ends_at > starts_at
101
+ AND weekdays IS NULL AND start_time IS NULL AND end_time IS NULL)),
102
+ CHECK (until_date IS NULL OR from_date IS NULL OR until_date >= from_date)
103
+ );
104
+
105
+ CREATE INDEX core_staff_away_account ON core_staff_away (account_id);
106
+
107
+ -- Guarded: migrations land out of order (docs/parallel-work.md).
108
+ UPDATE core_meta SET value = '811'
109
+ WHERE key = 'schema_version' AND CAST(value AS INTEGER) < 811;