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

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 (173) hide show
  1. package/dist/{accounts-X4CKM3HL.js → accounts-GOCNY6WI.js} +17 -14
  2. package/dist/app-RPRZMLU5.js +43 -0
  3. package/dist/app-upload-YJVEKZC6.js +198 -0
  4. package/dist/{blocks-YWDHEBOK.js → blocks-DE4RRWPJ.js} +207 -25
  5. package/dist/{chunk-VY64DMQO.js → chunk-2B6YUYZV.js} +23576 -11674
  6. package/dist/{run-RT2HVWMK.js → chunk-2CCHB37H.js} +9 -146
  7. package/dist/{chunk-DU6OIFOU.js → chunk-3OGDWKJ3.js} +530 -434
  8. package/dist/chunk-5D7BDF4Y.js +141 -0
  9. package/dist/{chunk-WO6D3XP3.js → chunk-6CM3WZG5.js} +13 -2470
  10. package/dist/chunk-CIBJGB5H.js +962 -0
  11. package/dist/chunk-EPDTPGZJ.js +330 -0
  12. package/dist/{chunk-LLULPZAJ.js → chunk-HAYF4G5V.js} +66 -23
  13. package/dist/chunk-HCG6T53D.js +61904 -0
  14. package/dist/chunk-JX4IFWNT.js +330 -0
  15. package/dist/{chunk-A4NTSYWV.js → chunk-KFHKNXGH.js} +786 -386
  16. package/dist/chunk-KMFMD52Z.js +13276 -0
  17. package/dist/{chunk-E4WCYTCT.js → chunk-LX2TTLVY.js} +174 -55
  18. package/dist/{chunk-GYTEW66E.js → chunk-O3R4FS2J.js} +1 -1
  19. package/dist/{chunk-LJFLENFC.js → chunk-Q6Y45DY6.js} +25 -2
  20. package/dist/{chunk-Y7JZFSTQ.js → chunk-QJZGYJVV.js} +823 -44
  21. package/dist/{chunk-6VXHPKGG.js → chunk-QQ3YSL5F.js} +172 -16
  22. package/dist/chunk-RGKJKC5T.js +876 -0
  23. package/dist/{chunk-IFG4FRW5.js → chunk-RSEWEFAV.js} +12 -2
  24. package/dist/{chunk-2ABSVMGB.js → chunk-SMJZIK2O.js} +1 -1
  25. package/dist/{chunk-CP6BXI6F.js → chunk-U72NEGCT.js} +8818 -3829
  26. package/dist/{chunk-WC5LHBBA.js → chunk-Z4IKF23A.js} +11 -7
  27. package/dist/chunk-Z7OVQ6BC.js +713 -0
  28. package/dist/{chunk-6UWRT4VM.js → chunk-ZJSFX4RD.js} +175 -3
  29. package/dist/{cli-2DFENR62.js → cli-OKQHHSOE.js} +17 -23
  30. package/dist/{cli-YIOVSKOD.js → cli-VYSD2S4Z.js} +231 -82
  31. package/dist/cli.js +5 -5
  32. package/dist/{client-repo-PRU3VCQQ.js → client-repo-NNUCHQ2Y.js} +7 -5
  33. package/dist/create.js +5 -5
  34. package/dist/{fields-2NC7LSYE.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-PUWD65BC.js → order-RKLGT74L.js} +2 -2
  40. package/dist/{person-WIQQ7ITU.js → person-YOZTFV4Q.js} +11 -11
  41. package/dist/plan-on-sale-H4F26YIN.js +26 -0
  42. package/dist/platform/migrations/0610_waitlists.sql +54 -0
  43. package/dist/platform/migrations/0630_subscription_changes.sql +122 -0
  44. package/dist/platform/migrations/0650_person_links.sql +90 -0
  45. package/dist/platform/migrations/0670_unmoved_guard.sql +52 -0
  46. package/dist/platform/migrations/0690_sellable_refund_due.sql +98 -0
  47. package/dist/platform/migrations/0730_practitioners.sql +79 -0
  48. package/dist/platform/migrations/0750_routine_mail.sql +98 -0
  49. package/dist/platform/migrations/0770_clear_fixed_role_grants.sql +64 -0
  50. package/dist/platform/migrations/0810_recurrence_exceptions.sql +66 -0
  51. package/dist/platform/migrations/0811_staff_time.sql +109 -0
  52. package/dist/platform/migrations/0812_staff_offers.sql +112 -0
  53. package/dist/platform/migrations/0813_pay_periods.sql +241 -0
  54. package/dist/platform/migrations/0814_staff_feed.sql +47 -0
  55. package/dist/platform/migrations/0815_checklists.sql +237 -0
  56. package/dist/platform/migrations/0816_checklist_schedules.sql +121 -0
  57. package/dist/platform/migrations/0817_checklist_day_window.sql +35 -0
  58. package/dist/platform/migrations/0850_agreements.sql +271 -0
  59. package/dist/platform/migrations/0851_agreement_acceptances.sql +387 -0
  60. package/dist/platform/migrations/0853_agreement_enforcement.sql +58 -0
  61. package/dist/platform/migrations/0854_agreement_copy.sql +149 -0
  62. package/dist/platform/migrations/0855_agreement_retention.sql +279 -0
  63. package/dist/platform/migrations/0856_subscription_cooling_off.sql +159 -0
  64. package/dist/platform/migrations/0857_agreement_copy_guardian.sql +337 -0
  65. package/dist/platform/migrations/0858_agreement_desk.sql +175 -0
  66. package/dist/platform/migrations/0910_routine_messages.sql +99 -0
  67. package/dist/platform/migrations/0911_texts.sql +60 -0
  68. package/dist/platform/migrations/0913_contact_consent.sql +93 -0
  69. package/dist/platform/migrations/0916_contact_mailbox_index.sql +29 -0
  70. package/dist/platform/migrations/0930_stock_movements.sql +95 -0
  71. package/dist/platform/migrations/0931_stock_low.sql +25 -0
  72. package/dist/platform/migrations/0932_order_delivery.sql +78 -0
  73. package/dist/platform/migrations/0950_order_adjustments.sql +111 -0
  74. package/dist/platform/migrations/0951_order_price_guards.sql +33 -0
  75. package/dist/platform/migrations/0952_order_paid_another_way.sql +194 -0
  76. package/dist/platform/migrations/0953_discount_uses.sql +183 -0
  77. package/dist/platform/migrations/0955_folded_addresses.sql +92 -0
  78. package/dist/platform/migrations/0970_published_text.sql +59 -0
  79. package/dist/platform/migrations/0971_publish_acks.sql +68 -0
  80. package/dist/platform/migrations/0990_customer_email_change.sql +65 -0
  81. package/dist/platform/migrations/1010_intake_links.sql +148 -0
  82. package/dist/platform/migrations/1030_invoices.sql +747 -0
  83. package/dist/platform/migrations/1031_invoice_orders.sql +327 -0
  84. package/dist/platform/migrations/1050_inbox_conversations.sql +83 -0
  85. package/dist/platform/migrations/1090_staff_hours.sql +43 -0
  86. package/dist/platform/migrations/1091_staff_time_margins.sql +12 -0
  87. package/dist/platform/migrations/1092_client_guard.sql +26 -0
  88. package/dist/platform/migrations/1095_thing_time.sql +70 -0
  89. package/dist/platform/migrations/1130_devices.sql +162 -0
  90. package/dist/platform/migrations/1135_person_codes.sql +88 -0
  91. package/dist/platform/migrations/1150_finance_periods.sql +316 -0
  92. package/dist/platform/migrations/1151_payouts.sql +202 -0
  93. package/dist/platform/migrations/1153_finance_money_dates.sql +18 -0
  94. package/dist/platform/migrations/1170_journeys.sql +318 -0
  95. package/dist/platform/migrations/1171_person_birthday.sql +52 -0
  96. package/dist/platform/migrations/1175_person_signals.sql +29 -0
  97. package/dist/platform/migrations/1190_restricted_values.sql +25 -0
  98. package/dist/platform/migrations/1230_note_levels.sql +113 -0
  99. package/dist/platform/migrations/1231_person_carers.sql +33 -0
  100. package/dist/platform/migrations/1232_note_kinds.sql +122 -0
  101. package/dist/platform/migrations/1270_time_entries.sql +145 -0
  102. package/dist/platform/migrations/1271_leave.sql +249 -0
  103. package/dist/platform/migrations/1273_time_entry_reopened.sql +21 -0
  104. package/dist/platform/migrations/1330_accounting.sql +260 -0
  105. package/dist/platform/migrations/1350_customer_feed.sql +24 -0
  106. package/dist/platform/migrations/1390_locations.sql +77 -0
  107. package/dist/platform/migrations/1410_outside_copy.sql +213 -0
  108. package/dist/platform/migrations/1430_inbox_activities.sql +231 -0
  109. package/dist/platform/migrations/1450_wrong_guesses.sql +23 -0
  110. package/dist/platform/sdk/acknowledge.ts +100 -0
  111. package/dist/platform/sdk/agreements.ts +185 -0
  112. package/dist/platform/sdk/allowance.ts +98 -8
  113. package/dist/platform/sdk/automation-check.ts +120 -9
  114. package/dist/platform/sdk/automation.ts +78 -10
  115. package/dist/platform/sdk/behaviour.ts +26 -6
  116. package/dist/platform/sdk/calendar-entry.ts +258 -0
  117. package/dist/platform/sdk/capacity.ts +103 -2
  118. package/dist/platform/sdk/checklists.ts +118 -0
  119. package/dist/platform/sdk/contract.ts +514 -27
  120. package/dist/platform/sdk/discount.ts +408 -0
  121. package/dist/platform/sdk/document.ts +4 -2
  122. package/dist/platform/sdk/field-types.ts +5 -0
  123. package/dist/platform/sdk/formula/compile.ts +10 -0
  124. package/dist/platform/sdk/index.ts +17 -0
  125. package/dist/platform/sdk/intake.ts +380 -0
  126. package/dist/platform/sdk/journey-signals.ts +215 -0
  127. package/dist/platform/sdk/manifest.ts +1313 -66
  128. package/dist/platform/sdk/mine.ts +161 -0
  129. package/dist/platform/sdk/occupies.ts +192 -0
  130. package/dist/platform/sdk/questions.ts +681 -0
  131. package/dist/platform/sdk/recurring.ts +90 -9
  132. package/dist/platform/sdk/restricted-fields.ts +129 -0
  133. package/dist/platform/sdk/rich-text.ts +112 -0
  134. package/dist/platform/sdk/routine-mail.ts +1272 -0
  135. package/dist/platform/sdk/runtime.ts +25 -12
  136. package/dist/platform/sdk/screens.ts +91 -0
  137. package/dist/platform/sdk/sellable.ts +595 -1
  138. package/dist/platform/sdk/slug.ts +7 -2
  139. package/dist/platform/sdk/staffed.ts +474 -0
  140. package/dist/platform/sdk/states.ts +220 -64
  141. package/dist/platform/sdk/stock.ts +332 -0
  142. package/dist/platform/sdk/team.ts +83 -0
  143. package/dist/platform/sdk/testing.ts +70 -6
  144. package/dist/platform/sdk/worked-on.ts +134 -0
  145. package/dist/{products-2H5DR232.js → products-GCQLSZ3U.js} +2 -2
  146. package/dist/run-7ID64RA6.js +65 -0
  147. package/dist/run-FH7OGGTV.js +131 -0
  148. package/dist/run-OYZIAP6M.js +3363 -0
  149. package/dist/{run-Y7T4TVOL.js → run-QOFRRSZV.js} +41 -60
  150. package/dist/{run-PZUCSDDL.js → run-TJAEWR5U.js} +21 -51
  151. package/dist/{src-XTOD7EXW.js → src-52VERUPK.js} +312 -4
  152. package/dist/src-PHRELWN5.js +40 -0
  153. package/dist/visibility-SZCINPP4.js +58 -0
  154. package/package.json +2 -2
  155. package/dist/chunk-6GDEDOV7.js +0 -157
  156. package/dist/chunk-6UPUF4ML.js +0 -29998
  157. package/dist/chunk-7CQGMVDO.js +0 -63
  158. package/dist/chunk-GYSGVT6R.js +0 -284
  159. package/dist/chunk-JJHHNV46.js +0 -227
  160. package/dist/chunk-K6T42YCH.js +0 -704
  161. package/dist/chunk-M7A6FR2Z.js +0 -2586
  162. package/dist/chunk-O2UIZHND.js +0 -249
  163. package/dist/chunk-Q4N55M2Z.js +0 -552
  164. package/dist/chunk-QGGJ2G6Z.js +0 -349
  165. package/dist/chunk-R4W5XAUD.js +0 -837
  166. package/dist/chunk-TQFGGSA4.js +0 -748
  167. package/dist/chunk-YJJHF65I.js +0 -759
  168. package/dist/chunk-Z3RMMB6S.js +0 -668
  169. package/dist/grants-QXMKYMGB.js +0 -32
  170. package/dist/invoke-I3NNNXVL.js +0 -39
  171. package/dist/plan-on-sale-NB774CQL.js +0 -26
  172. package/dist/src-GYS6NBQB.js +0 -44
  173. package/dist/visibility-DLGHU4YN.js +0 -33
@@ -0,0 +1,162 @@
1
+ -- Migration 1130: the enrolled device (stage 51 step 1, built with stage 44 step 6; ADR 0780).
2
+ -- Nothing here touches core_write_guard.
3
+ --
4
+ -- An enrolled device is a tablet (or another browser) a human admin enrolled as the business's
5
+ -- own, for one use:
6
+ -- signing stage 44's desk signing: alone it may only show "Enter code" and claim a session a
7
+ -- person on the staff started (migration 0858);
8
+ -- role a device role a pack declares (stage 51's check-in tablet; step 2 builds the calls);
9
+ -- till stage 50's till: its credential only names the device on a staff member's calls.
10
+ -- One use per device; an admin changes it (`device.setUse`) or revokes it (`device.revoke`).
11
+ --
12
+ -- Enrolment: the admin's `device.enrol` makes the row with a single-use enrolment code (10
13
+ -- characters, 10 minutes), kept as its HMAC; typing it at the desk origin's /enrol
14
+ -- (`device.claim`) sets the device credential (256 random bits in a cookie), kept as its HMAC.
15
+ -- Every credential, code and token is an HMAC under an env secret (DESK_SECRET), never in the
16
+ -- clear. The credential rotates at least daily, and on every signing claim; the one rotated away
17
+ -- is accepted for 60 seconds after (the grace window), and presented later it revokes the device
18
+ -- as a clone. A device with no call for 30 days lapses.
19
+ --
20
+ -- The browser (user agent) and the network address at the claim and at each rotation describe
21
+ -- the business's own tablet and premises, not a member's device (stage 44, decision 3): a change
22
+ -- is flagged on the devices list (`flags`).
23
+ --
24
+ -- This table is not a record: no rec_* view reads it.
25
+
26
+ CREATE TABLE core_device (
27
+ id TEXT PRIMARY KEY,
28
+ name TEXT NOT NULL CHECK (length(name) BETWEEN 1 AND 80),
29
+ use TEXT NOT NULL CHECK (use IN ('signing', 'role', 'till')),
30
+ -- The device role (`<pack>.<role>`) a device of use `role` holds; none for any other use.
31
+ role TEXT CHECK (role IS NULL OR length(role) BETWEEN 3 AND 80),
32
+ enrolled_by TEXT NOT NULL,
33
+ enrolled_at TEXT NOT NULL,
34
+ -- The enrolment code until it is used or runs out.
35
+ enrol_code_hash TEXT CHECK (enrol_code_hash IS NULL OR length(enrol_code_hash) = 64),
36
+ enrol_expires_at TEXT NOT NULL,
37
+ claimed_at TEXT,
38
+ -- The credential, the next one the host has issued (`pending`: the current one stays good until
39
+ -- the device presents the next, so an answer lost on the way never locks it out), the one
40
+ -- rotated away (accepted until `rotated_at` + 60 seconds) and when.
41
+ credential_hash TEXT CHECK (credential_hash IS NULL OR length(credential_hash) = 64),
42
+ pending_credential_hash TEXT
43
+ CHECK (pending_credential_hash IS NULL OR length(pending_credential_hash) = 64),
44
+ previous_credential_hash TEXT
45
+ CHECK (previous_credential_hash IS NULL OR length(previous_credential_hash) = 64),
46
+ rotated_at TEXT,
47
+ last_seen_at TEXT,
48
+ claim_user_agent TEXT CHECK (claim_user_agent IS NULL OR length(claim_user_agent) <= 400),
49
+ claim_address TEXT CHECK (claim_address IS NULL OR length(claim_address) <= 64),
50
+ last_user_agent TEXT CHECK (last_user_agent IS NULL OR length(last_user_agent) <= 400),
51
+ last_address TEXT CHECK (last_address IS NULL OR length(last_address) <= 64),
52
+ -- What changed since the claim: a JSON list of { kind: browser | network, at }, newest last.
53
+ flags TEXT NOT NULL DEFAULT '[]' CHECK (json_valid(flags) AND json_type(flags) = 'array'),
54
+ -- Wrong desk codes typed on it: five in a minute lock it for five minutes.
55
+ bad_codes INTEGER NOT NULL DEFAULT 0 CHECK (bad_codes >= 0),
56
+ bad_codes_since TEXT,
57
+ locked_until TEXT,
58
+ revoked_at TEXT,
59
+ revoked_by TEXT,
60
+ revoke_reason TEXT CHECK (revoke_reason IN ('admin', 'clone', 'lapsed')),
61
+ CHECK ((use = 'role') = (role IS NOT NULL)),
62
+ CHECK ((revoked_at IS NULL) = (revoke_reason IS NULL)),
63
+ CHECK (claimed_at IS NOT NULL OR credential_hash IS NULL),
64
+ CHECK (claimed_at IS NULL OR enrol_code_hash IS NULL)
65
+ );
66
+ CREATE INDEX core_device_credential_idx ON core_device (credential_hash)
67
+ WHERE credential_hash IS NOT NULL;
68
+ CREATE INDEX core_device_previous_idx ON core_device (previous_credential_hash)
69
+ WHERE previous_credential_hash IS NOT NULL;
70
+ CREATE INDEX core_device_pending_idx ON core_device (pending_credential_hash)
71
+ WHERE pending_credential_hash IS NOT NULL;
72
+ CREATE INDEX core_device_enrol_idx ON core_device (enrol_code_hash)
73
+ WHERE enrol_code_hash IS NOT NULL;
74
+ CREATE INDEX core_device_list_idx ON core_device (revoked_at, enrolled_at);
75
+
76
+ -- What may be inserted: a new device, not yet claimed or revoked, with its enrolment code.
77
+ CREATE TRIGGER core_device_new
78
+ BEFORE INSERT ON core_device
79
+ BEGIN
80
+ SELECT CASE
81
+ WHEN EXISTS (SELECT 1 FROM core_device d WHERE d.id = NEW.id)
82
+ THEN RAISE(ABORT, 'core_device_fixed')
83
+ WHEN NEW.claimed_at IS NOT NULL OR NEW.credential_hash IS NOT NULL
84
+ OR NEW.previous_credential_hash IS NOT NULL OR NEW.pending_credential_hash IS NOT NULL
85
+ OR NEW.revoked_at IS NOT NULL
86
+ OR NEW.enrol_code_hash IS NULL
87
+ THEN RAISE(ABORT, 'core_device_fixed')
88
+ END;
89
+ END;
90
+
91
+ -- Who enrolled it and when never change; it is claimed once; a revoked device stays revoked and
92
+ -- holds no credential or code again.
93
+ CREATE TRIGGER core_device_no_update
94
+ BEFORE UPDATE ON core_device
95
+ BEGIN
96
+ SELECT CASE
97
+ WHEN NEW.id IS NOT OLD.id OR NEW.enrolled_by IS NOT OLD.enrolled_by
98
+ OR NEW.enrolled_at IS NOT OLD.enrolled_at OR NEW.enrol_expires_at IS NOT OLD.enrol_expires_at
99
+ THEN RAISE(ABORT, 'core_device_fixed')
100
+ WHEN OLD.claimed_at IS NOT NULL AND NEW.claimed_at IS NOT OLD.claimed_at
101
+ THEN RAISE(ABORT, 'core_device_fixed')
102
+ WHEN NEW.enrol_code_hash IS NOT NULL AND NEW.enrol_code_hash IS NOT OLD.enrol_code_hash
103
+ THEN RAISE(ABORT, 'core_device_fixed')
104
+ WHEN OLD.revoked_at IS NOT NULL AND (NEW.revoked_at IS NOT OLD.revoked_at
105
+ OR NEW.revoke_reason IS NOT OLD.revoke_reason OR NEW.revoked_by IS NOT OLD.revoked_by
106
+ OR NEW.credential_hash IS NOT NULL OR NEW.previous_credential_hash IS NOT NULL
107
+ OR NEW.pending_credential_hash IS NOT NULL OR NEW.enrol_code_hash IS NOT NULL)
108
+ THEN RAISE(ABORT, 'core_device_fixed')
109
+ END;
110
+ END;
111
+
112
+ -- A device is evidence for the desk acceptances made on it: it is never deleted.
113
+ CREATE TRIGGER core_device_no_delete
114
+ BEFORE DELETE ON core_device
115
+ BEGIN
116
+ SELECT RAISE(ABORT, 'core_device_fixed');
117
+ END;
118
+
119
+ -- Revoked (by an admin, as a clone, or lapsed): every open signing session on it ends in the same
120
+ -- statement, whatever wrote the revocation.
121
+ CREATE TRIGGER core_device_revoked_ends_sessions
122
+ AFTER UPDATE OF revoked_at ON core_device
123
+ WHEN OLD.revoked_at IS NULL AND NEW.revoked_at IS NOT NULL
124
+ BEGIN
125
+ UPDATE core_agreement_desk_session
126
+ SET ended_at = NEW.revoked_at, end_reason = 'revoked', code_hash = NULL, token_hash = NULL
127
+ WHERE ended_at IS NULL AND (device_id = NEW.id OR claimed_device_id = NEW.id);
128
+ END;
129
+
130
+ -- Its use changed: a signing session open on it ends, in the same statement.
131
+ CREATE TRIGGER core_device_use_changed_ends_sessions
132
+ AFTER UPDATE OF use, role ON core_device
133
+ WHEN NEW.use IS NOT OLD.use OR NEW.role IS NOT OLD.role
134
+ BEGIN
135
+ UPDATE core_agreement_desk_session
136
+ SET ended_at = strftime('%Y-%m-%dT%H:%M:%fZ', 'now'), end_reason = 'device_changed',
137
+ code_hash = NULL, token_hash = NULL
138
+ WHERE ended_at IS NULL AND (device_id = NEW.id OR claimed_device_id = NEW.id);
139
+ END;
140
+
141
+ -- An enrolment claim's guard (after the review of PR #390): the claim's batch carries one row
142
+ -- here, and fails unless the device now holds the credential this claim set. Of two browsers
143
+ -- claiming one code at once, the one that lost is refused. Stores nothing.
144
+ CREATE TABLE core_device_guard (
145
+ device_id TEXT NOT NULL,
146
+ credential_hash TEXT NOT NULL
147
+ );
148
+
149
+ CREATE TRIGGER core_device_guard_check
150
+ BEFORE INSERT ON core_device_guard
151
+ BEGIN
152
+ SELECT CASE
153
+ WHEN NOT EXISTS (SELECT 1 FROM core_device d WHERE d.id = NEW.device_id
154
+ AND d.credential_hash = NEW.credential_hash AND d.revoked_at IS NULL)
155
+ THEN RAISE(ABORT, 'core_device_claim_lost')
156
+ ELSE RAISE(IGNORE)
157
+ END;
158
+ END;
159
+
160
+ -- Guarded: migrations land out of order (docs/parallel-work.md).
161
+ UPDATE core_meta SET value = '1130'
162
+ WHERE key = 'schema_version' AND CAST(value AS INTEGER) < 1130;
@@ -0,0 +1,88 @@
1
+ -- Migration 1135: a person's code and PIN (stage 51 step 3, ADR 0783).
2
+ --
3
+ -- What identifies a Person at a check-in tablet, kept in the host and never shown to the device:
4
+ --
5
+ -- - core_person_code: an `app` code or a `card`.
6
+ -- - An app code is a secret for a rotating 30-second code (RFC 6238, 8 digits), made for one
7
+ -- sign-in: a native app's device session or a browser's customer session. Its row goes when
8
+ -- that sign-in ends (the foreign keys), so a code never outlives the sign-in that showed it.
9
+ -- The secret is kept encrypted under a key derived from the host's auth secret (the host must
10
+ -- check a rotating code, so a hash would not do). `guardian_id` is set for a dependant's code
11
+ -- shown on a guardian's app: it identifies the dependant only while that link is live.
12
+ -- - A card is a fixed long code the business gives a member (a card or key tag), kept only as an
13
+ -- HMAC under that key, with a label and who issued it. Revoked, it identifies no one; one live
14
+ -- card per code.
15
+ -- - core_person_pin: a 4-digit PIN the member set in their app, kept as a slow hash (PBKDF2 over
16
+ -- the PIN keyed by the same derived key, with a salt of its own). Wrong tries are counted per
17
+ -- Person over a day; ten disable it until the member sets it again.
18
+ -- - core_identify_lockout: per device and entry (`name` for name and PIN, `code` for codes), the
19
+ -- failed tries in the current minute and when entry is locked until. No Person, nothing typed.
20
+ -- The device id is text with no foreign key: the enrolled device is stage 51 step 1's.
21
+ --
22
+ -- Nothing here is in a rec_* view, search, an export or an embedding. Erasing a Person deletes
23
+ -- their codes, cards and PIN, and the dependant codes they hold (people-codes/people.ts; the
24
+ -- foreign keys would too). A merge moves cards to the survivor, deletes the app codes of the
25
+ -- merged Person and those shown on their app (the next `me.code` makes them again), and keeps the
26
+ -- survivor's PIN.
27
+ CREATE TABLE core_person_code (
28
+ -- pc_… (ids.ts).
29
+ id TEXT PRIMARY KEY NOT NULL,
30
+ person_id TEXT NOT NULL REFERENCES core_person (id) ON DELETE CASCADE,
31
+ kind TEXT NOT NULL CHECK (kind IN ('app', 'card')),
32
+ -- A card: the HMAC of its normalised code, its label, who issued it.
33
+ code_hmac TEXT,
34
+ label TEXT,
35
+ issued_by TEXT,
36
+ -- An app code: its secret, encrypted (AES-GCM, base64url iv.ciphertext), and the sign-in.
37
+ secret_enc TEXT,
38
+ device_session_id TEXT REFERENCES core_device_session (id) ON DELETE CASCADE,
39
+ customer_session_id TEXT REFERENCES core_customer_session (id) ON DELETE CASCADE,
40
+ -- A dependant's app code, shown on this guardian's sign-in; null: the Person's own.
41
+ guardian_id TEXT REFERENCES core_person (id) ON DELETE CASCADE,
42
+ created_at TEXT NOT NULL,
43
+ last_used_at TEXT,
44
+ revoked_at TEXT,
45
+ revoked_by TEXT,
46
+ CHECK (kind != 'card' OR (code_hmac IS NOT NULL AND label IS NOT NULL AND issued_by IS NOT NULL
47
+ AND secret_enc IS NULL AND device_session_id IS NULL AND customer_session_id IS NULL
48
+ AND guardian_id IS NULL)),
49
+ CHECK (kind != 'app' OR (secret_enc IS NOT NULL AND code_hmac IS NULL
50
+ AND ((device_session_id IS NULL) != (customer_session_id IS NULL)))),
51
+ CHECK (guardian_id IS NULL OR guardian_id != person_id)
52
+ );
53
+ CREATE INDEX core_person_code_person ON core_person_code (person_id);
54
+ CREATE INDEX core_person_code_guardian ON core_person_code (guardian_id) WHERE guardian_id IS NOT NULL;
55
+ -- One live card per code.
56
+ CREATE UNIQUE INDEX core_person_code_card_uq ON core_person_code (code_hmac)
57
+ WHERE kind = 'card' AND revoked_at IS NULL;
58
+ -- One app code per Person per sign-in.
59
+ CREATE UNIQUE INDEX core_person_code_device_uq ON core_person_code (device_session_id, person_id)
60
+ WHERE device_session_id IS NOT NULL;
61
+ CREATE UNIQUE INDEX core_person_code_session_uq ON core_person_code (customer_session_id, person_id)
62
+ WHERE customer_session_id IS NOT NULL;
63
+
64
+ CREATE TABLE core_person_pin (
65
+ person_id TEXT PRIMARY KEY NOT NULL REFERENCES core_person (id) ON DELETE CASCADE,
66
+ -- PBKDF2-SHA256, base64url; its salt, base64url; its iterations.
67
+ hash TEXT NOT NULL,
68
+ salt TEXT NOT NULL,
69
+ iterations INTEGER NOT NULL,
70
+ set_at TEXT NOT NULL,
71
+ -- Wrong tries since `failed_since` (a day's window), and when ten disabled it.
72
+ failed_count INTEGER NOT NULL DEFAULT 0 CHECK (failed_count >= 0),
73
+ failed_since TEXT,
74
+ disabled_at TEXT
75
+ );
76
+
77
+ CREATE TABLE core_identify_lockout (
78
+ device_id TEXT NOT NULL,
79
+ entry TEXT NOT NULL CHECK (entry IN ('name', 'code')),
80
+ window_started_at TEXT NOT NULL,
81
+ failures INTEGER NOT NULL CHECK (failures >= 0),
82
+ locked_until TEXT,
83
+ PRIMARY KEY (device_id, entry)
84
+ );
85
+
86
+ -- Guarded: migrations land out of order (docs/parallel-work.md).
87
+ UPDATE core_meta SET value = '1135'
88
+ WHERE key = 'schema_version' AND CAST(value AS INTEGER) < 1135;
@@ -0,0 +1,316 @@
1
+ -- Migration 1150: finance periods, the close and the book entries (stage 52 step 1, ADRs 0790 and
2
+ -- 0791). The business closes each calendar month (local, in the organisation's zone): one batch
3
+ -- writes a version of the period `closing`, its book entries and their lines, its report rows and
4
+ -- every source it counted, then `closed`. A closed version never changes; reopening it (a
5
+ -- person, with why) keeps it as it was, and closing again writes the next version.
6
+ --
7
+ -- The close never refuses a money event: nothing here guards an order, a payment or a refund.
8
+ -- What arrives later for a closed month is counted in the first open month, in a `late` entry
9
+ -- naming the month it belongs to; `core_finance_counted` keeps every source a close counted, so a
10
+ -- source is counted once across every period.
11
+ --
12
+ -- All of it is the business's figures: core tables in no rec_* view, so no dashboard, query.sql,
13
+ -- export.csv or the assistant's record reads reach them. They are read only through the finance
14
+ -- operations, by an account holding `finance:read`.
15
+ --
16
+ -- D1 runs with recursive triggers off, so the rows an INSERT OR REPLACE or an UPDATE OR REPLACE
17
+ -- deletes fire no delete trigger: each table's BEFORE INSERT also refuses replacing a row it
18
+ -- protects, and its BEFORE UPDATE refuses every change it does not allow (a replace is one).
19
+
20
+ -- One version of one month (ADR 0790). `month` is `YYYY-MM`; the dates are local in `zone` (the
21
+ -- organisation's when it was closed, kept whatever the zone is since); `starts` and `ends` are
22
+ -- the instants of its first and last days' local midnights (half-open), unix seconds.
23
+ CREATE TABLE core_finance_period (
24
+ id TEXT PRIMARY KEY,
25
+ month TEXT NOT NULL CHECK (month GLOB '[0-9][0-9][0-9][0-9]-[0-1][0-9]'),
26
+ start_date TEXT NOT NULL,
27
+ end_date TEXT NOT NULL,
28
+ zone TEXT NOT NULL,
29
+ starts INTEGER NOT NULL,
30
+ ends INTEGER NOT NULL,
31
+ version INTEGER NOT NULL CHECK (version >= 1),
32
+ state TEXT NOT NULL CHECK (state IN ('closing', 'closed', 'reopened')),
33
+ closed_by TEXT NOT NULL,
34
+ closed_at TEXT NOT NULL,
35
+ -- How many entries, lines and report rows the version holds (checked when it is closed).
36
+ entry_count INTEGER NOT NULL CHECK (entry_count >= 0),
37
+ line_count INTEGER NOT NULL CHECK (line_count >= 0),
38
+ row_count INTEGER NOT NULL CHECK (row_count >= 0),
39
+ reopened_by TEXT,
40
+ reopened_at TEXT,
41
+ reopen_reason TEXT CHECK (reopen_reason IS NULL OR length(reopen_reason) BETWEEN 1 AND 500),
42
+ CHECK (end_date >= start_date),
43
+ CHECK (ends > starts),
44
+ CHECK ((state = 'reopened') = (reopened_by IS NOT NULL AND reopened_at IS NOT NULL
45
+ AND reopen_reason IS NOT NULL)),
46
+ UNIQUE (month, version)
47
+ );
48
+
49
+ -- At most one version of a month is closed (or being closed) at a time.
50
+ CREATE UNIQUE INDEX core_finance_period_held ON core_finance_period (month)
51
+ WHERE state IN ('closing', 'closed');
52
+ CREATE INDEX core_finance_period_state ON core_finance_period (state, month);
53
+
54
+ -- One book entry of a version (ADR 0791): a day summary, a payout, what is held for customers at
55
+ -- the month's end, or something that arrived late for a closed month. `entry_key` is the same in
56
+ -- every version (`day:2026-04-03`, `payout:<id>`, `held:2026-04`, `late:2026-04@2026-05-06`);
57
+ -- `fingerprint` is a hash of its lines, so a reader sees whether a later version changed it.
58
+ -- An entry carries no names.
59
+ CREATE TABLE core_finance_entry (
60
+ period_id TEXT NOT NULL,
61
+ entry_key TEXT NOT NULL,
62
+ n INTEGER NOT NULL CHECK (n >= 1),
63
+ kind TEXT NOT NULL CHECK (kind IN ('day', 'payout', 'held', 'late')),
64
+ date TEXT NOT NULL CHECK (date GLOB '[0-9][0-9][0-9][0-9]-[0-1][0-9]-[0-3][0-9]'),
65
+ belongs_to TEXT CHECK (belongs_to IS NULL OR belongs_to GLOB '[0-9][0-9][0-9][0-9]-[0-1][0-9]'),
66
+ fingerprint TEXT NOT NULL,
67
+ CHECK ((kind = 'late') = (belongs_to IS NOT NULL)),
68
+ PRIMARY KEY (period_id, entry_key)
69
+ ) WITHOUT ROWID;
70
+
71
+ CREATE UNIQUE INDEX core_finance_entry_n ON core_finance_entry (period_id, n);
72
+
73
+ -- One line of an entry: a heading in the host's words (never an account code), a side and an
74
+ -- amount in minor units; the tax code and country where it is tax, the method where it is money in
75
+ -- or out, the category where it is a sale. An entry's debits equal its credits.
76
+ CREATE TABLE core_finance_entry_line (
77
+ period_id TEXT NOT NULL,
78
+ entry_key TEXT NOT NULL,
79
+ n INTEGER NOT NULL CHECK (n >= 1),
80
+ heading TEXT NOT NULL,
81
+ side TEXT NOT NULL CHECK (side IN ('debit', 'credit')),
82
+ amount INTEGER NOT NULL CHECK (amount > 0),
83
+ tax_code TEXT,
84
+ tax_country TEXT,
85
+ method TEXT,
86
+ category TEXT,
87
+ PRIMARY KEY (period_id, entry_key, n)
88
+ ) WITHOUT ROWID;
89
+
90
+ -- A report's rows as they were closed (ADR 0790): `data` is the row (amounts, dates, order ids),
91
+ -- never a name. Rows that name who owes or who was refunded keep the person apart, so an erase
92
+ -- replaces the name with "Erased person" and clears the email, in every version, and changes
93
+ -- nothing else.
94
+ CREATE TABLE core_finance_row (
95
+ period_id TEXT NOT NULL,
96
+ report TEXT NOT NULL CHECK (report IN ('sales', 'tax', 'refunds', 'payouts', 'owed', 'held',
97
+ 'unearned', 'members')),
98
+ n INTEGER NOT NULL CHECK (n >= 1),
99
+ person_id TEXT,
100
+ name TEXT,
101
+ email TEXT,
102
+ data TEXT NOT NULL CHECK (json_valid(data)),
103
+ PRIMARY KEY (period_id, report, n)
104
+ ) WITHOUT ROWID;
105
+
106
+ CREATE INDEX core_finance_row_person ON core_finance_row (person_id) WHERE person_id IS NOT NULL;
107
+
108
+ -- Every source a version counted (a payment, a refund, a payout, …), by kind and id. A source
109
+ -- counted in one month's closed version is never counted in another's; a reopened month closed
110
+ -- again counts its own again.
111
+ CREATE TABLE core_finance_counted (
112
+ source_kind TEXT NOT NULL,
113
+ source_id TEXT NOT NULL,
114
+ period_id TEXT NOT NULL,
115
+ month TEXT NOT NULL,
116
+ PRIMARY KEY (source_kind, source_id, period_id)
117
+ ) WITHOUT ROWID;
118
+
119
+ CREATE INDEX core_finance_counted_period ON core_finance_counted (period_id);
120
+
121
+ -- The close's guard (ADR 0790): the close reads what its figures came from, then guards each value
122
+ -- in its own batch; a write in between fails the close whole (`core_finance_changed`, answered
123
+ -- `finance_changed`). Nothing is stored.
124
+ CREATE TABLE core_finance_guard (
125
+ expected INTEGER NOT NULL,
126
+ actual INTEGER NOT NULL
127
+ );
128
+
129
+ CREATE TRIGGER core_finance_guard_check
130
+ BEFORE INSERT ON core_finance_guard
131
+ BEGIN
132
+ SELECT CASE
133
+ WHEN NEW.actual != NEW.expected THEN RAISE(ABORT, 'core_finance_changed')
134
+ ELSE RAISE(IGNORE)
135
+ END;
136
+ END;
137
+
138
+ -- A version is made `closing`, with a number no other version of its month holds and instants
139
+ -- that overlap no other month's closed version; never replaced.
140
+ CREATE TRIGGER core_finance_period_insert
141
+ BEFORE INSERT ON core_finance_period
142
+ BEGIN
143
+ SELECT RAISE(ABORT, 'core_finance_period_fixed')
144
+ WHERE NEW.state != 'closing' OR NEW.reopened_by IS NOT NULL
145
+ OR EXISTS (SELECT 1 FROM core_finance_period p WHERE p.id = NEW.id);
146
+ -- Two closes of one month at once: the second finds the first's version (it is held).
147
+ SELECT RAISE(ABORT, 'core_finance_period_held')
148
+ WHERE EXISTS (SELECT 1 FROM core_finance_period p
149
+ WHERE p.month = NEW.month AND (p.version = NEW.version OR p.state IN ('closing', 'closed')));
150
+ SELECT RAISE(ABORT, 'core_finance_period_overlap')
151
+ WHERE EXISTS (SELECT 1 FROM core_finance_period p WHERE p.month != NEW.month
152
+ AND p.state IN ('closing', 'closed') AND p.starts < NEW.ends AND p.ends > NEW.starts);
153
+ -- In order, for every writer (the review of PR #337): no later month is closed, and the month
154
+ -- before is closed, unless this is the first month. The first month is the earliest month with
155
+ -- a version, fixed by the first close: a month before it never gets one.
156
+ SELECT RAISE(ABORT, 'core_finance_period_order')
157
+ WHERE EXISTS (SELECT 1 FROM core_finance_period p WHERE p.month > NEW.month
158
+ AND p.state IN ('closing', 'closed'))
159
+ OR NOT (
160
+ EXISTS (SELECT 1 FROM core_finance_period p
161
+ WHERE p.month = strftime('%Y-%m', NEW.month || '-01', '-1 month') AND p.state = 'closed')
162
+ OR (NOT EXISTS (SELECT 1 FROM core_finance_period p WHERE p.month < NEW.month)
163
+ AND (EXISTS (SELECT 1 FROM core_finance_period p WHERE p.month = NEW.month)
164
+ OR NOT EXISTS (SELECT 1 FROM core_finance_period p WHERE p.month > NEW.month))));
165
+ END;
166
+
167
+ -- Only `closing` to `closed` (with its counts), and `closed` to `reopened` with who, when and why
168
+ -- while no later month is closed; nothing else ever changes. A reopened version takes one change:
169
+ -- an erase of the person its reason names (ADR 0320) makes the reason "[erased]".
170
+ CREATE TRIGGER core_finance_period_update
171
+ BEFORE UPDATE ON core_finance_period
172
+ BEGIN
173
+ SELECT RAISE(ABORT, 'core_finance_period_fixed')
174
+ WHERE NEW.id IS NOT OLD.id OR NEW.month IS NOT OLD.month
175
+ OR NEW.start_date IS NOT OLD.start_date OR NEW.end_date IS NOT OLD.end_date
176
+ OR NEW.zone IS NOT OLD.zone OR NEW.starts IS NOT OLD.starts OR NEW.ends IS NOT OLD.ends
177
+ OR NEW.version IS NOT OLD.version OR NEW.closed_by IS NOT OLD.closed_by
178
+ OR NEW.closed_at IS NOT OLD.closed_at
179
+ OR NOT ((OLD.state = 'closing' AND NEW.state = 'closed' AND NEW.reopened_by IS NULL)
180
+ OR (OLD.state = 'closed' AND NEW.state = 'reopened' AND NEW.entry_count IS OLD.entry_count
181
+ AND NEW.line_count IS OLD.line_count AND NEW.row_count IS OLD.row_count)
182
+ OR (OLD.state = 'reopened' AND NEW.state = 'reopened' AND NEW.entry_count IS OLD.entry_count
183
+ AND NEW.line_count IS OLD.line_count AND NEW.row_count IS OLD.row_count
184
+ AND NEW.reopened_by IS OLD.reopened_by AND NEW.reopened_at IS OLD.reopened_at
185
+ AND NEW.reopen_reason = '[erased]'));
186
+ SELECT RAISE(ABORT, 'core_finance_period_order')
187
+ WHERE OLD.state = 'closed' AND NEW.state = 'reopened'
188
+ AND EXISTS (SELECT 1 FROM core_finance_period p WHERE p.month > OLD.month
189
+ AND p.state IN ('closing', 'closed'));
190
+ -- Closed with exactly what was written into it.
191
+ SELECT RAISE(ABORT, 'core_finance_period_fixed')
192
+ WHERE OLD.state = 'closing' AND (
193
+ NEW.entry_count != (SELECT count(*) FROM core_finance_entry e WHERE e.period_id = NEW.id)
194
+ OR NEW.line_count != (SELECT count(*) FROM core_finance_entry_line l WHERE l.period_id = NEW.id)
195
+ OR NEW.row_count != (SELECT count(*) FROM core_finance_row r WHERE r.period_id = NEW.id));
196
+ END;
197
+
198
+ CREATE TRIGGER core_finance_period_delete
199
+ BEFORE DELETE ON core_finance_period
200
+ BEGIN
201
+ SELECT RAISE(ABORT, 'core_finance_period_fixed');
202
+ END;
203
+
204
+ -- Entries, lines, rows and counted sources are written only into a version being closed (in its
205
+ -- own batch), and never replaced, changed or removed.
206
+ CREATE TRIGGER core_finance_entry_insert
207
+ BEFORE INSERT ON core_finance_entry
208
+ BEGIN
209
+ SELECT RAISE(ABORT, 'core_finance_period_fixed')
210
+ WHERE NOT EXISTS (SELECT 1 FROM core_finance_period p WHERE p.id = NEW.period_id
211
+ AND p.state = 'closing')
212
+ OR EXISTS (SELECT 1 FROM core_finance_entry e WHERE e.period_id = NEW.period_id
213
+ AND (e.entry_key = NEW.entry_key OR e.n = NEW.n));
214
+ END;
215
+
216
+ CREATE TRIGGER core_finance_entry_update
217
+ BEFORE UPDATE ON core_finance_entry
218
+ BEGIN
219
+ SELECT RAISE(ABORT, 'core_finance_period_fixed');
220
+ END;
221
+
222
+ CREATE TRIGGER core_finance_entry_delete
223
+ BEFORE DELETE ON core_finance_entry
224
+ BEGIN
225
+ SELECT RAISE(ABORT, 'core_finance_period_fixed');
226
+ END;
227
+
228
+ CREATE TRIGGER core_finance_entry_line_insert
229
+ BEFORE INSERT ON core_finance_entry_line
230
+ BEGIN
231
+ SELECT RAISE(ABORT, 'core_finance_period_fixed')
232
+ WHERE NOT EXISTS (SELECT 1 FROM core_finance_period p WHERE p.id = NEW.period_id
233
+ AND p.state = 'closing')
234
+ OR NOT EXISTS (SELECT 1 FROM core_finance_entry e WHERE e.period_id = NEW.period_id
235
+ AND e.entry_key = NEW.entry_key)
236
+ OR EXISTS (SELECT 1 FROM core_finance_entry_line l WHERE l.period_id = NEW.period_id
237
+ AND l.entry_key = NEW.entry_key AND l.n = NEW.n);
238
+ END;
239
+
240
+ CREATE TRIGGER core_finance_entry_line_update
241
+ BEFORE UPDATE ON core_finance_entry_line
242
+ BEGIN
243
+ SELECT RAISE(ABORT, 'core_finance_period_fixed');
244
+ END;
245
+
246
+ CREATE TRIGGER core_finance_entry_line_delete
247
+ BEFORE DELETE ON core_finance_entry_line
248
+ BEGIN
249
+ SELECT RAISE(ABORT, 'core_finance_period_fixed');
250
+ END;
251
+
252
+ CREATE TRIGGER core_finance_row_insert
253
+ BEFORE INSERT ON core_finance_row
254
+ BEGIN
255
+ SELECT RAISE(ABORT, 'core_finance_period_fixed')
256
+ WHERE NOT EXISTS (SELECT 1 FROM core_finance_period p WHERE p.id = NEW.period_id
257
+ AND p.state = 'closing')
258
+ OR EXISTS (SELECT 1 FROM core_finance_row r WHERE r.period_id = NEW.period_id
259
+ AND r.report = NEW.report AND r.n = NEW.n);
260
+ END;
261
+
262
+ -- The one change a closed row takes: an erase of its person (ADR 0320), whose name becomes
263
+ -- "Erased person" and whose email is cleared. Its amounts, dates and order ids stay.
264
+ CREATE TRIGGER core_finance_row_update
265
+ BEFORE UPDATE ON core_finance_row
266
+ BEGIN
267
+ SELECT RAISE(ABORT, 'core_finance_period_fixed')
268
+ WHERE NEW.period_id IS NOT OLD.period_id OR NEW.report IS NOT OLD.report OR NEW.n IS NOT OLD.n
269
+ OR NEW.person_id IS NOT OLD.person_id OR NEW.data IS NOT OLD.data
270
+ OR OLD.person_id IS NULL
271
+ OR NEW.name IS NOT 'Erased person' OR NEW.email IS NOT NULL;
272
+ END;
273
+
274
+ CREATE TRIGGER core_finance_row_delete
275
+ BEFORE DELETE ON core_finance_row
276
+ BEGIN
277
+ SELECT RAISE(ABORT, 'core_finance_period_fixed');
278
+ END;
279
+
280
+ CREATE TRIGGER core_finance_counted_insert
281
+ BEFORE INSERT ON core_finance_counted
282
+ BEGIN
283
+ SELECT RAISE(ABORT, 'core_finance_period_fixed')
284
+ WHERE NOT EXISTS (SELECT 1 FROM core_finance_period p WHERE p.id = NEW.period_id
285
+ AND p.state = 'closing' AND p.month = NEW.month)
286
+ OR EXISTS (SELECT 1 FROM core_finance_counted c WHERE c.source_kind = NEW.source_kind
287
+ AND c.source_id = NEW.source_id AND c.period_id = NEW.period_id);
288
+ -- Counted once: never in two months' closed versions.
289
+ SELECT RAISE(ABORT, 'core_finance_counted_twice')
290
+ WHERE EXISTS (SELECT 1 FROM core_finance_counted c
291
+ JOIN core_finance_period p ON p.id = c.period_id
292
+ WHERE c.source_kind = NEW.source_kind AND c.source_id = NEW.source_id
293
+ AND c.month != NEW.month AND p.state = 'closed');
294
+ END;
295
+
296
+ CREATE TRIGGER core_finance_counted_update
297
+ BEFORE UPDATE ON core_finance_counted
298
+ BEGIN
299
+ SELECT RAISE(ABORT, 'core_finance_period_fixed');
300
+ END;
301
+
302
+ CREATE TRIGGER core_finance_counted_delete
303
+ BEFORE DELETE ON core_finance_counted
304
+ BEGIN
305
+ SELECT RAISE(ABORT, 'core_finance_period_fixed');
306
+ END;
307
+
308
+ -- The month finance starts counting from, until an admin picks an earlier one (ADR 0790): the
309
+ -- month this migration ran, read in the organisation's zone. Kept as the instant.
310
+ INSERT OR IGNORE INTO core_settings (key, value, updated_at)
311
+ VALUES ('finance_installed_at', json_quote(strftime('%Y-%m-%dT%H:%M:%fZ', 'now')),
312
+ strftime('%Y-%m-%dT%H:%M:%fZ', 'now'));
313
+
314
+ -- Guarded: migrations land out of order (docs/parallel-work.md).
315
+ UPDATE core_meta SET value = '1150'
316
+ WHERE key = 'schema_version' AND CAST(value AS INTEGER) < 1150;