@composable-os/cli 0.1.0-beta.11 → 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.
- package/dist/{accounts-UHYLCLEY.js → accounts-GOCNY6WI.js} +17 -13
- package/dist/app-RPRZMLU5.js +43 -0
- package/dist/app-upload-YJVEKZC6.js +198 -0
- package/dist/{blocks-5IFU25J6.js → blocks-DE4RRWPJ.js} +207 -25
- package/dist/{chunk-XIDLW3EP.js → chunk-2B6YUYZV.js} +23499 -11766
- package/dist/{run-7P4RQALH.js → chunk-2CCHB37H.js} +9 -146
- package/dist/{chunk-DU6OIFOU.js → chunk-3OGDWKJ3.js} +530 -434
- package/dist/{chunk-DHS2CV2M.js → chunk-5D7BDF4Y.js} +15 -13
- package/dist/{chunk-ZAWES2UD.js → chunk-6CM3WZG5.js} +13 -2483
- package/dist/{chunk-7D4GKZOX.js → chunk-CIBJGB5H.js} +422 -75
- package/dist/chunk-EPDTPGZJ.js +330 -0
- package/dist/{chunk-LAAL4YGR.js → chunk-HAYF4G5V.js} +66 -23
- package/dist/chunk-HCG6T53D.js +61904 -0
- package/dist/{chunk-K34UKWEI.js → chunk-JX4IFWNT.js} +64 -32
- package/dist/{chunk-6XTU2MTP.js → chunk-KFHKNXGH.js} +632 -418
- package/dist/chunk-KMFMD52Z.js +13276 -0
- package/dist/{chunk-E4WCYTCT.js → chunk-LX2TTLVY.js} +174 -55
- package/dist/{chunk-GYTEW66E.js → chunk-O3R4FS2J.js} +1 -1
- package/dist/{chunk-E64SG24J.js → chunk-Q6Y45DY6.js} +25 -2
- package/dist/{chunk-MBIKVRAC.js → chunk-QJZGYJVV.js} +823 -44
- package/dist/{chunk-PDD2ETVF.js → chunk-QQ3YSL5F.js} +172 -16
- package/dist/chunk-RGKJKC5T.js +876 -0
- package/dist/{chunk-YFTLIEWU.js → chunk-RSEWEFAV.js} +12 -2
- package/dist/{chunk-2ABSVMGB.js → chunk-SMJZIK2O.js} +1 -1
- package/dist/{chunk-LO6WGU5Y.js → chunk-U72NEGCT.js} +8089 -3464
- package/dist/{chunk-P6UWZ6QQ.js → chunk-Z4IKF23A.js} +11 -7
- package/dist/{chunk-2IVEVPMY.js → chunk-Z7OVQ6BC.js} +105 -61
- package/dist/{chunk-6UWRT4VM.js → chunk-ZJSFX4RD.js} +175 -3
- package/dist/{cli-5UNY5G5L.js → cli-OKQHHSOE.js} +17 -25
- package/dist/{cli-UYZMVQMR.js → cli-VYSD2S4Z.js} +227 -81
- package/dist/cli.js +5 -5
- package/dist/{client-repo-SE4EKG6W.js → client-repo-NNUCHQ2Y.js} +7 -5
- package/dist/create.js +5 -5
- package/dist/{fields-FTWWMD7N.js → fields-GTHE6TTS.js} +27 -3
- package/dist/gateway-DPPEQZT4.js +25 -0
- package/dist/grants-6JY4XZO7.js +27 -0
- package/dist/invoke-MRONRZ5Q.js +33 -0
- package/dist/moves-UAUCMWL5.js +36 -0
- package/dist/{order-U4KZLLSJ.js → order-RKLGT74L.js} +2 -2
- package/dist/{person-UHLVBVLR.js → person-YOZTFV4Q.js} +11 -10
- package/dist/plan-on-sale-H4F26YIN.js +26 -0
- package/dist/platform/migrations/0730_practitioners.sql +79 -0
- package/dist/platform/migrations/0750_routine_mail.sql +98 -0
- package/dist/platform/migrations/0770_clear_fixed_role_grants.sql +64 -0
- package/dist/platform/migrations/0810_recurrence_exceptions.sql +66 -0
- package/dist/platform/migrations/0811_staff_time.sql +109 -0
- package/dist/platform/migrations/0812_staff_offers.sql +112 -0
- package/dist/platform/migrations/0813_pay_periods.sql +241 -0
- package/dist/platform/migrations/0814_staff_feed.sql +47 -0
- package/dist/platform/migrations/0815_checklists.sql +237 -0
- package/dist/platform/migrations/0816_checklist_schedules.sql +121 -0
- package/dist/platform/migrations/0817_checklist_day_window.sql +35 -0
- package/dist/platform/migrations/0850_agreements.sql +271 -0
- package/dist/platform/migrations/0851_agreement_acceptances.sql +387 -0
- package/dist/platform/migrations/0853_agreement_enforcement.sql +58 -0
- package/dist/platform/migrations/0854_agreement_copy.sql +149 -0
- package/dist/platform/migrations/0855_agreement_retention.sql +279 -0
- package/dist/platform/migrations/0856_subscription_cooling_off.sql +159 -0
- package/dist/platform/migrations/0857_agreement_copy_guardian.sql +337 -0
- package/dist/platform/migrations/0858_agreement_desk.sql +175 -0
- package/dist/platform/migrations/0910_routine_messages.sql +99 -0
- package/dist/platform/migrations/0911_texts.sql +60 -0
- package/dist/platform/migrations/0913_contact_consent.sql +93 -0
- package/dist/platform/migrations/0916_contact_mailbox_index.sql +29 -0
- package/dist/platform/migrations/0930_stock_movements.sql +95 -0
- package/dist/platform/migrations/0931_stock_low.sql +25 -0
- package/dist/platform/migrations/0932_order_delivery.sql +78 -0
- package/dist/platform/migrations/0950_order_adjustments.sql +111 -0
- package/dist/platform/migrations/0951_order_price_guards.sql +33 -0
- package/dist/platform/migrations/0952_order_paid_another_way.sql +194 -0
- package/dist/platform/migrations/0953_discount_uses.sql +183 -0
- package/dist/platform/migrations/0955_folded_addresses.sql +92 -0
- package/dist/platform/migrations/0970_published_text.sql +59 -0
- package/dist/platform/migrations/0971_publish_acks.sql +68 -0
- package/dist/platform/migrations/0990_customer_email_change.sql +65 -0
- package/dist/platform/migrations/1010_intake_links.sql +148 -0
- package/dist/platform/migrations/1030_invoices.sql +747 -0
- package/dist/platform/migrations/1031_invoice_orders.sql +327 -0
- package/dist/platform/migrations/1050_inbox_conversations.sql +83 -0
- package/dist/platform/migrations/1090_staff_hours.sql +43 -0
- package/dist/platform/migrations/1091_staff_time_margins.sql +12 -0
- package/dist/platform/migrations/1092_client_guard.sql +26 -0
- package/dist/platform/migrations/1095_thing_time.sql +70 -0
- package/dist/platform/migrations/1130_devices.sql +162 -0
- package/dist/platform/migrations/1135_person_codes.sql +88 -0
- package/dist/platform/migrations/1150_finance_periods.sql +316 -0
- package/dist/platform/migrations/1151_payouts.sql +202 -0
- package/dist/platform/migrations/1153_finance_money_dates.sql +18 -0
- package/dist/platform/migrations/1170_journeys.sql +318 -0
- package/dist/platform/migrations/1171_person_birthday.sql +52 -0
- package/dist/platform/migrations/1175_person_signals.sql +29 -0
- package/dist/platform/migrations/1190_restricted_values.sql +25 -0
- package/dist/platform/migrations/1230_note_levels.sql +113 -0
- package/dist/platform/migrations/1231_person_carers.sql +33 -0
- package/dist/platform/migrations/1232_note_kinds.sql +122 -0
- package/dist/platform/migrations/1270_time_entries.sql +145 -0
- package/dist/platform/migrations/1271_leave.sql +249 -0
- package/dist/platform/migrations/1273_time_entry_reopened.sql +21 -0
- package/dist/platform/migrations/1330_accounting.sql +260 -0
- package/dist/platform/migrations/1350_customer_feed.sql +24 -0
- package/dist/platform/migrations/1390_locations.sql +77 -0
- package/dist/platform/migrations/1410_outside_copy.sql +213 -0
- package/dist/platform/migrations/1430_inbox_activities.sql +231 -0
- package/dist/platform/migrations/1450_wrong_guesses.sql +23 -0
- package/dist/platform/sdk/acknowledge.ts +100 -0
- package/dist/platform/sdk/agreements.ts +185 -0
- package/dist/platform/sdk/allowance.ts +98 -8
- package/dist/platform/sdk/automation-check.ts +120 -9
- package/dist/platform/sdk/automation.ts +78 -10
- package/dist/platform/sdk/behaviour.ts +26 -6
- package/dist/platform/sdk/calendar-entry.ts +258 -0
- package/dist/platform/sdk/capacity.ts +1 -2
- package/dist/platform/sdk/checklists.ts +118 -0
- package/dist/platform/sdk/contract.ts +489 -27
- package/dist/platform/sdk/discount.ts +408 -0
- package/dist/platform/sdk/document.ts +4 -2
- package/dist/platform/sdk/field-types.ts +5 -0
- package/dist/platform/sdk/formula/compile.ts +10 -0
- package/dist/platform/sdk/index.ts +17 -0
- package/dist/platform/sdk/intake.ts +380 -0
- package/dist/platform/sdk/journey-signals.ts +215 -0
- package/dist/platform/sdk/manifest.ts +1236 -65
- package/dist/platform/sdk/mine.ts +161 -0
- package/dist/platform/sdk/occupies.ts +192 -0
- package/dist/platform/sdk/questions.ts +681 -0
- package/dist/platform/sdk/recurring.ts +90 -9
- package/dist/platform/sdk/restricted-fields.ts +129 -0
- package/dist/platform/sdk/rich-text.ts +112 -0
- package/dist/platform/sdk/routine-mail.ts +1272 -0
- package/dist/platform/sdk/runtime.ts +25 -12
- package/dist/platform/sdk/screens.ts +91 -0
- package/dist/platform/sdk/sellable.ts +344 -0
- package/dist/platform/sdk/slug.ts +7 -2
- package/dist/platform/sdk/staffed.ts +474 -0
- package/dist/platform/sdk/states.ts +68 -26
- package/dist/platform/sdk/stock.ts +332 -0
- package/dist/platform/sdk/team.ts +83 -0
- package/dist/platform/sdk/testing.ts +70 -6
- package/dist/platform/sdk/worked-on.ts +134 -0
- package/dist/{products-2H5DR232.js → products-GCQLSZ3U.js} +2 -2
- package/dist/run-7ID64RA6.js +65 -0
- package/dist/run-FH7OGGTV.js +131 -0
- package/dist/run-OYZIAP6M.js +3363 -0
- package/dist/{run-ZCGFMEZF.js → run-QOFRRSZV.js} +41 -60
- package/dist/{run-PO3W5BFA.js → run-TJAEWR5U.js} +21 -51
- package/dist/{src-I3IJ4NKC.js → src-52VERUPK.js} +306 -4
- package/dist/src-PHRELWN5.js +40 -0
- package/dist/{visibility-TVXZ67FD.js → visibility-SZCINPP4.js} +21 -4
- package/package.json +2 -2
- package/dist/chunk-2TWV3SVB.js +0 -349
- package/dist/chunk-2XC5JLBO.js +0 -1931
- package/dist/chunk-324WJXNP.js +0 -320
- package/dist/chunk-6ELZRNUU.js +0 -116
- package/dist/chunk-6WGFA2IV.js +0 -643
- package/dist/chunk-7CQGMVDO.js +0 -63
- package/dist/chunk-7OGCMQXG.js +0 -284
- package/dist/chunk-FJIZGS5Q.js +0 -698
- package/dist/chunk-UB4I2QKR.js +0 -31575
- package/dist/chunk-WHKJGF36.js +0 -2418
- package/dist/chunk-YNUZRTPH.js +0 -182
- package/dist/chunk-ZZFWMVJO.js +0 -704
- package/dist/grants-LOW6TSWD.js +0 -32
- package/dist/invoke-6KVT6WJI.js +0 -41
- package/dist/moves-E2HKYCTK.js +0 -41
- package/dist/plan-on-sale-TJPFCNL7.js +0 -26
- package/dist/src-CRO35DYY.js +0 -46
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
-- Migration 0816: checklists on their own, without a roster (ADR 0651; a follow-on to stage 45
|
|
2
|
+
-- step 4b, ADR 0650).
|
|
3
|
+
--
|
|
4
|
+
-- A checklist template may now have a standing schedule of its own: the days of the week it is
|
|
5
|
+
-- due (in the business's time zone), a time it is due by, and who may do it: everyone on staff,
|
|
6
|
+
-- the people holding a role (a pack role too: a cleaner, a coach), or the people granted a
|
|
7
|
+
-- permission. Each due day gets one run (`object_type` 'checklist.day', `record_id`
|
|
8
|
+
-- '<checklist id>:<YYYY-MM-DD>', so the run table's own one-per-record rule makes it one a day),
|
|
9
|
+
-- open from the start of that local day to the start of the next. Anyone who may do it ticks it;
|
|
10
|
+
-- whoever ticks the last step finishes it; one not finished by the end of its day is closed by the
|
|
11
|
+
-- host as missed. Everything migration 0815 holds for a run (a closed run never changes, ticks are
|
|
12
|
+
-- insert-only, done only once every required step is ticked) holds for these too.
|
|
13
|
+
--
|
|
14
|
+
-- **Only someone allowed ticks**, for every writer: a day run copies who may do it from its
|
|
15
|
+
-- template when it is made (`doers_kind`, `doers_value`, fixed from then on), and the triggers
|
|
16
|
+
-- below refuse a tick for anyone else, a tick on someone's behalf by anyone who does not manage
|
|
17
|
+
-- checklists (an admin, or an account granted checklists:write), and a finish by anyone else.
|
|
18
|
+
|
|
19
|
+
-- The template's schedule. `days` is a JSON array of ISO weekdays (1 Monday … 7 Sunday), or null:
|
|
20
|
+
-- no schedule (a duty's checklist only, as before). `due_by` is a local time (HH:MM), or null.
|
|
21
|
+
ALTER TABLE core_checklist ADD COLUMN days TEXT
|
|
22
|
+
CHECK (days IS NULL OR (json_valid(days) AND json_type(days) = 'array'
|
|
23
|
+
AND json_array_length(days) BETWEEN 1 AND 7));
|
|
24
|
+
ALTER TABLE core_checklist ADD COLUMN due_by TEXT
|
|
25
|
+
CHECK (due_by IS NULL OR (length(due_by) = 5 AND due_by GLOB '[0-2][0-9]:[0-5][0-9]'));
|
|
26
|
+
-- Who may do it: 'staff' (every staff account that may write), 'role' (an account with the role
|
|
27
|
+
-- or pack role `doers_value`), 'grant' (an account granted the permission `doers_value`).
|
|
28
|
+
ALTER TABLE core_checklist ADD COLUMN doers_kind TEXT
|
|
29
|
+
CHECK (doers_kind IS NULL OR doers_kind IN ('staff', 'role', 'grant'));
|
|
30
|
+
ALTER TABLE core_checklist ADD COLUMN doers_value TEXT
|
|
31
|
+
CHECK (doers_value IS NULL OR length(doers_value) BETWEEN 1 AND 81);
|
|
32
|
+
|
|
33
|
+
-- A day run's copy of who may do it and when it is due by (unix seconds). Null on a record's run.
|
|
34
|
+
ALTER TABLE core_checklist_run ADD COLUMN doers_kind TEXT
|
|
35
|
+
CHECK (doers_kind IS NULL OR doers_kind IN ('staff', 'role', 'grant'));
|
|
36
|
+
ALTER TABLE core_checklist_run ADD COLUMN doers_value TEXT;
|
|
37
|
+
ALTER TABLE core_checklist_run ADD COLUMN due_at INTEGER;
|
|
38
|
+
|
|
39
|
+
-- A day run is inserted with who may do it, and a record's run without.
|
|
40
|
+
CREATE TRIGGER core_checklist_day_run_insert
|
|
41
|
+
BEFORE INSERT ON core_checklist_run
|
|
42
|
+
BEGIN
|
|
43
|
+
SELECT RAISE(ABORT, 'core_checklist_fixed')
|
|
44
|
+
WHERE (NEW.object_type = 'checklist.day') != (NEW.doers_kind IS NOT NULL)
|
|
45
|
+
OR (NEW.doers_kind = 'staff' AND NEW.doers_value IS NOT NULL)
|
|
46
|
+
OR (NEW.doers_kind IN ('role', 'grant') AND NEW.doers_value IS NULL)
|
|
47
|
+
OR (NEW.object_type != 'checklist.day' AND NEW.due_at IS NOT NULL)
|
|
48
|
+
OR (NEW.object_type = 'checklist.day' AND NEW.account_id IS NOT NULL);
|
|
49
|
+
END;
|
|
50
|
+
|
|
51
|
+
-- Who may do a day run, who manages checklists, and what of a day run never changes. Its day,
|
|
52
|
+
-- who may do it and when it is due are fixed; while open it is nobody's own (no account); it is
|
|
53
|
+
-- finished by someone who may do it, for themselves, or by someone who manages checklists for
|
|
54
|
+
-- someone who may, with why.
|
|
55
|
+
CREATE TRIGGER core_checklist_day_run_update
|
|
56
|
+
BEFORE UPDATE ON core_checklist_run
|
|
57
|
+
WHEN OLD.object_type = 'checklist.day'
|
|
58
|
+
BEGIN
|
|
59
|
+
-- A closed run never changes (as migration 0815's own trigger says, whichever fires first).
|
|
60
|
+
SELECT RAISE(ABORT, 'core_checklist_closed') WHERE OLD.state != 'open';
|
|
61
|
+
SELECT RAISE(ABORT, 'core_checklist_fixed')
|
|
62
|
+
WHERE NEW.doers_kind IS NOT OLD.doers_kind OR NEW.doers_value IS NOT OLD.doers_value
|
|
63
|
+
OR NEW.due_at IS NOT OLD.due_at OR NEW.opens IS NOT OLD.opens OR NEW.closes IS NOT OLD.closes
|
|
64
|
+
OR NEW.ended_at IS NOT NULL OR NEW.ended_by IS NOT NULL
|
|
65
|
+
OR (NEW.state = 'open' AND NEW.account_id IS NOT NULL)
|
|
66
|
+
OR NEW.state = 'cancelled';
|
|
67
|
+
SELECT RAISE(ABORT, 'core_checklist_not_allowed')
|
|
68
|
+
WHERE NEW.state = 'done' AND NOT (
|
|
69
|
+
-- Someone who may do it, finishing it themselves.
|
|
70
|
+
(NEW.account_id = NEW.closed_by AND NEW.closed_why IS NULL AND EXISTS (
|
|
71
|
+
SELECT 1 FROM core_user u WHERE u.id = NEW.closed_by AND u.kind = 'human'
|
|
72
|
+
AND u.deactivated_at IS NULL AND u.support_grant_id IS NULL
|
|
73
|
+
AND (u.pack_role IS NOT NULL OR u.role != 'viewer')
|
|
74
|
+
AND (OLD.doers_kind = 'staff'
|
|
75
|
+
OR (OLD.doers_kind = 'role' AND (u.pack_role = OLD.doers_value
|
|
76
|
+
OR (u.pack_role IS NULL AND u.role = OLD.doers_value)))
|
|
77
|
+
OR (OLD.doers_kind = 'grant' AND json_valid(u.granted_permissions) AND EXISTS (
|
|
78
|
+
SELECT 1 FROM json_each(u.granted_permissions) g WHERE g.value = OLD.doers_value)))))
|
|
79
|
+
-- Someone who manages checklists, for someone who may do it, with why.
|
|
80
|
+
OR (NEW.account_id IS NOT NEW.closed_by AND NEW.closed_why IS NOT NULL
|
|
81
|
+
AND EXISTS (SELECT 1 FROM core_user m WHERE m.id = NEW.closed_by AND m.kind = 'human'
|
|
82
|
+
AND m.deactivated_at IS NULL AND m.pack_role IS NULL
|
|
83
|
+
AND (m.role = 'admin' OR (json_valid(m.granted_permissions) AND EXISTS (
|
|
84
|
+
SELECT 1 FROM json_each(m.granted_permissions) g WHERE g.value = 'checklists:write'))))
|
|
85
|
+
AND EXISTS (SELECT 1 FROM core_user u WHERE u.id = NEW.account_id AND u.kind = 'human'
|
|
86
|
+
AND u.deactivated_at IS NULL AND u.support_grant_id IS NULL
|
|
87
|
+
AND (u.pack_role IS NOT NULL OR u.role != 'viewer')
|
|
88
|
+
AND (OLD.doers_kind = 'staff'
|
|
89
|
+
OR (OLD.doers_kind = 'role' AND (u.pack_role = OLD.doers_value
|
|
90
|
+
OR (u.pack_role IS NULL AND u.role = OLD.doers_value)))
|
|
91
|
+
OR (OLD.doers_kind = 'grant' AND json_valid(u.granted_permissions) AND EXISTS (
|
|
92
|
+
SELECT 1 FROM json_each(u.granted_permissions) g WHERE g.value = OLD.doers_value)))))
|
|
93
|
+
);
|
|
94
|
+
END;
|
|
95
|
+
|
|
96
|
+
-- A day run's tick is for someone who may do it, made by them, or for them by someone who
|
|
97
|
+
-- manages checklists.
|
|
98
|
+
CREATE TRIGGER core_checklist_day_tick_insert
|
|
99
|
+
BEFORE INSERT ON core_checklist_tick
|
|
100
|
+
WHEN EXISTS (SELECT 1 FROM core_checklist_run r WHERE r.id = NEW.run_id
|
|
101
|
+
AND r.object_type = 'checklist.day')
|
|
102
|
+
BEGIN
|
|
103
|
+
SELECT RAISE(ABORT, 'core_checklist_not_allowed')
|
|
104
|
+
WHERE NOT EXISTS (
|
|
105
|
+
SELECT 1 FROM core_checklist_run r JOIN core_user u ON u.id = NEW.ticked_for
|
|
106
|
+
WHERE r.id = NEW.run_id AND u.kind = 'human' AND u.deactivated_at IS NULL
|
|
107
|
+
AND u.support_grant_id IS NULL AND (u.pack_role IS NOT NULL OR u.role != 'viewer')
|
|
108
|
+
AND (r.doers_kind = 'staff'
|
|
109
|
+
OR (r.doers_kind = 'role' AND (u.pack_role = r.doers_value
|
|
110
|
+
OR (u.pack_role IS NULL AND u.role = r.doers_value)))
|
|
111
|
+
OR (r.doers_kind = 'grant' AND json_valid(u.granted_permissions) AND EXISTS (
|
|
112
|
+
SELECT 1 FROM json_each(u.granted_permissions) g WHERE g.value = r.doers_value))))
|
|
113
|
+
OR (NEW.on_behalf = 1 AND NOT EXISTS (
|
|
114
|
+
SELECT 1 FROM core_user m WHERE m.id = NEW.ticked_by AND m.kind = 'human'
|
|
115
|
+
AND m.deactivated_at IS NULL AND m.pack_role IS NULL
|
|
116
|
+
AND (m.role = 'admin' OR (json_valid(m.granted_permissions) AND EXISTS (
|
|
117
|
+
SELECT 1 FROM json_each(m.granted_permissions) g WHERE g.value = 'checklists:write')))));
|
|
118
|
+
END;
|
|
119
|
+
|
|
120
|
+
-- The schedules the minute cron reads: the active templates that have one.
|
|
121
|
+
CREATE INDEX core_checklist_scheduled ON core_checklist (active) WHERE days IS NOT NULL;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
-- Migration 0817: when a day's checklist may be ticked, and when it is missed (ADR 0651, amended
|
|
2
|
+
-- 2026-11-24 after the review of #383).
|
|
3
|
+
--
|
|
4
|
+
-- Migration 0816 holds who may tick or finish a day's checklist; the host alone held when. Now the
|
|
5
|
+
-- database does too, for every writer:
|
|
6
|
+
-- - a tick on a day run is made inside its day (`ticked_at` from its `opens` to before its
|
|
7
|
+
-- `closes`);
|
|
8
|
+
-- - a day run is closed as missed only once its day has ended (`closed_at` at or after its
|
|
9
|
+
-- `closes`), and by nobody: no closer, no person, no why (the minute cron's close).
|
|
10
|
+
-- The time judged is the one the writer records (`ticked_at`, `closed_at`), as every time in the
|
|
11
|
+
-- host is the caller's clock: a host bug or a script closing a run at noon, or ticking one
|
|
12
|
+
-- tomorrow, is refused; one that writes a false time is not, as for any other time it writes.
|
|
13
|
+
|
|
14
|
+
CREATE TRIGGER core_checklist_day_run_missed
|
|
15
|
+
BEFORE UPDATE ON core_checklist_run
|
|
16
|
+
WHEN OLD.object_type = 'checklist.day' AND OLD.state = 'open' AND NEW.state = 'missed'
|
|
17
|
+
BEGIN
|
|
18
|
+
SELECT RAISE(ABORT, 'core_checklist_window')
|
|
19
|
+
WHERE NEW.closed_by IS NOT NULL OR NEW.account_id IS NOT NULL OR NEW.closed_why IS NOT NULL
|
|
20
|
+
OR NEW.closed_at IS NULL OR strftime('%s', NEW.closed_at) IS NULL
|
|
21
|
+
OR CAST(strftime('%s', NEW.closed_at) AS INTEGER) < OLD.closes;
|
|
22
|
+
END;
|
|
23
|
+
|
|
24
|
+
-- An open run only: a closed one's ticks are migration 0815's to refuse, whichever fires first.
|
|
25
|
+
CREATE TRIGGER core_checklist_day_tick_window
|
|
26
|
+
BEFORE INSERT ON core_checklist_tick
|
|
27
|
+
WHEN EXISTS (SELECT 1 FROM core_checklist_run r WHERE r.id = NEW.run_id
|
|
28
|
+
AND r.object_type = 'checklist.day' AND r.state = 'open')
|
|
29
|
+
BEGIN
|
|
30
|
+
SELECT RAISE(ABORT, 'core_checklist_window')
|
|
31
|
+
WHERE strftime('%s', NEW.ticked_at) IS NULL OR EXISTS (
|
|
32
|
+
SELECT 1 FROM core_checklist_run r WHERE r.id = NEW.run_id
|
|
33
|
+
AND (CAST(strftime('%s', NEW.ticked_at) AS INTEGER) < r.opens
|
|
34
|
+
OR CAST(strftime('%s', NEW.ticked_at) AS INTEGER) >= r.closes));
|
|
35
|
+
END;
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
-- Migration 0850: agreement documents and their versions (stage 44 step 1, ADRs 0640 and 0641).
|
|
2
|
+
--
|
|
3
|
+
-- A document is something a business asks people to agree to (its terms, a waiver, health
|
|
4
|
+
-- questions, a parent's consent). Staff with `agreements:manage` (and the assistant for them)
|
|
5
|
+
-- write its working copy; a person publishes it as a numbered version, which nobody can change or
|
|
6
|
+
-- delete afterwards. A version takes effect now or at a set moment (the minute cron); the newest
|
|
7
|
+
-- in effect is current, and `agree_from` is the newest "first" or "agree again" version in effect:
|
|
8
|
+
-- acceptances of earlier versions stop counting (stage 44, step 2 on).
|
|
9
|
+
--
|
|
10
|
+
-- None of these tables is a record: no rec_* view reads them, so query.sql, dashboards, exports,
|
|
11
|
+
-- search and the assistant's bulk reads never see them. The business's text is not personal data;
|
|
12
|
+
-- nothing here names a member.
|
|
13
|
+
CREATE TABLE core_agreement_document (
|
|
14
|
+
id TEXT PRIMARY KEY,
|
|
15
|
+
-- Fixed when the document is made: only `health` changes how it works (stage 44).
|
|
16
|
+
kind TEXT NOT NULL CHECK (kind IN ('terms', 'waiver', 'health', 'guardian', 'other')),
|
|
17
|
+
-- draft: never published; live: published; retired: needed nowhere, final.
|
|
18
|
+
state TEXT NOT NULL DEFAULT 'draft' CHECK (state IN ('draft', 'live', 'retired')),
|
|
19
|
+
-- The working copy: what the editor changes, and what a publish snapshots.
|
|
20
|
+
draft_title TEXT NOT NULL,
|
|
21
|
+
draft_body TEXT,
|
|
22
|
+
draft_tick_label TEXT,
|
|
23
|
+
draft_questions TEXT,
|
|
24
|
+
draft_how TEXT NOT NULL DEFAULT 'typed' CHECK (draft_how IN ('typed', 'drawn')),
|
|
25
|
+
draft_who TEXT NOT NULL DEFAULT 'participant' CHECK (draft_who IN ('participant', 'payer')),
|
|
26
|
+
draft_for TEXT NOT NULL DEFAULT 'everyone' CHECK (draft_for IN ('everyone', 'dependants')),
|
|
27
|
+
draft_ask_again_months INTEGER CHECK (draft_ask_again_months BETWEEN 1 AND 120),
|
|
28
|
+
-- Bumped by every save of the working copy: a publish names the one it was made from.
|
|
29
|
+
draft_rev INTEGER NOT NULL DEFAULT 0,
|
|
30
|
+
draft_updated_at TEXT NOT NULL,
|
|
31
|
+
draft_updated_by TEXT NOT NULL,
|
|
32
|
+
-- The actor of the last save (human, assistant, mcp, …): the editor says when someone else,
|
|
33
|
+
-- the assistant above all, changed the copy a person is looking at.
|
|
34
|
+
draft_updated_via TEXT NOT NULL DEFAULT 'human',
|
|
35
|
+
-- The version in effect now (empty until the first takes effect), and the version number from
|
|
36
|
+
-- which acceptances count (0 until then).
|
|
37
|
+
current_version_id TEXT,
|
|
38
|
+
agree_from INTEGER NOT NULL DEFAULT 0,
|
|
39
|
+
created_at TEXT NOT NULL,
|
|
40
|
+
created_by TEXT NOT NULL,
|
|
41
|
+
retired_at TEXT,
|
|
42
|
+
retired_by TEXT
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
-- Published wording, kept for good. Acceptances (step 2) will point at it.
|
|
46
|
+
CREATE TABLE core_agreement_version (
|
|
47
|
+
id TEXT PRIMARY KEY,
|
|
48
|
+
document_id TEXT NOT NULL REFERENCES core_agreement_document (id),
|
|
49
|
+
number INTEGER NOT NULL CHECK (number >= 1),
|
|
50
|
+
title TEXT NOT NULL,
|
|
51
|
+
body TEXT NOT NULL,
|
|
52
|
+
tick_label TEXT NOT NULL,
|
|
53
|
+
questions TEXT,
|
|
54
|
+
how TEXT NOT NULL CHECK (how IN ('typed', 'drawn')),
|
|
55
|
+
who TEXT NOT NULL CHECK (who IN ('participant', 'payer')),
|
|
56
|
+
for_whom TEXT NOT NULL CHECK (for_whom IN ('everyone', 'dependants')),
|
|
57
|
+
ask_again_months INTEGER,
|
|
58
|
+
change TEXT NOT NULL CHECK (change IN ('first', 'small', 'agree_again')),
|
|
59
|
+
effective_from TEXT NOT NULL,
|
|
60
|
+
published_at TEXT NOT NULL,
|
|
61
|
+
-- The staff user (a person: the operation is human-only) who published it.
|
|
62
|
+
published_by TEXT NOT NULL,
|
|
63
|
+
-- The working copy's draft_rev it was made from.
|
|
64
|
+
draft_rev INTEGER NOT NULL,
|
|
65
|
+
-- SHA-256 (hex) of the canonical JSON of what a person is shown.
|
|
66
|
+
hash TEXT NOT NULL CHECK (length(hash) = 64),
|
|
67
|
+
CHECK ((number = 1) = (change = 'first')),
|
|
68
|
+
UNIQUE (document_id, number)
|
|
69
|
+
);
|
|
70
|
+
CREATE INDEX core_agreement_version_due_idx ON core_agreement_version (effective_from);
|
|
71
|
+
|
|
72
|
+
-- Nobody changes or deletes a published version: not an operation, not host code, not a
|
|
73
|
+
-- migration's later statement. Refused in the database.
|
|
74
|
+
--
|
|
75
|
+
-- D1 runs with recursive triggers off, so the rows an INSERT OR REPLACE deletes fire no delete
|
|
76
|
+
-- trigger: every table here also refuses an insert whose key already exists (a REPLACE is an
|
|
77
|
+
-- insert), so a REPLACE cannot get round the delete triggers.
|
|
78
|
+
CREATE TRIGGER core_agreement_version_no_update
|
|
79
|
+
BEFORE UPDATE ON core_agreement_version
|
|
80
|
+
BEGIN
|
|
81
|
+
SELECT RAISE(ABORT, 'core_agreement_version_immutable');
|
|
82
|
+
END;
|
|
83
|
+
|
|
84
|
+
CREATE TRIGGER core_agreement_version_no_delete
|
|
85
|
+
BEFORE DELETE ON core_agreement_version
|
|
86
|
+
BEGIN
|
|
87
|
+
SELECT RAISE(ABORT, 'core_agreement_version_immutable');
|
|
88
|
+
END;
|
|
89
|
+
|
|
90
|
+
-- A version is made only from the working copy as it is at commit (the person reviewed that
|
|
91
|
+
-- one, by its rev), of a document that is not retired, numbered next, and holding exactly the
|
|
92
|
+
-- copy's content, field by field. SQLite has no SHA-256, so the hash itself is the host's: every
|
|
93
|
+
-- read of a version recomputes it from the stored content (`intact`, ADR 0640).
|
|
94
|
+
CREATE TRIGGER core_agreement_version_from_draft
|
|
95
|
+
BEFORE INSERT ON core_agreement_version
|
|
96
|
+
BEGIN
|
|
97
|
+
SELECT CASE
|
|
98
|
+
WHEN EXISTS (SELECT 1 FROM core_agreement_version v WHERE v.id = NEW.id)
|
|
99
|
+
THEN RAISE(ABORT, 'core_agreement_version_immutable')
|
|
100
|
+
WHEN NOT EXISTS (
|
|
101
|
+
SELECT 1 FROM core_agreement_document d
|
|
102
|
+
WHERE d.id = NEW.document_id AND d.draft_rev = NEW.draft_rev AND d.state != 'retired'
|
|
103
|
+
AND d.draft_title = NEW.title
|
|
104
|
+
AND d.draft_body IS NEW.body
|
|
105
|
+
AND d.draft_tick_label IS NEW.tick_label
|
|
106
|
+
AND d.draft_questions IS NEW.questions
|
|
107
|
+
AND d.draft_how = NEW.how
|
|
108
|
+
AND d.draft_who = NEW.who
|
|
109
|
+
AND d.draft_for = NEW.for_whom
|
|
110
|
+
AND d.draft_ask_again_months IS NEW.ask_again_months
|
|
111
|
+
)
|
|
112
|
+
THEN RAISE(ABORT, 'core_agreement_draft_changed')
|
|
113
|
+
WHEN NEW.number != 1 + COALESCE(
|
|
114
|
+
(SELECT MAX(v.number) FROM core_agreement_version v WHERE v.document_id = NEW.document_id), 0)
|
|
115
|
+
THEN RAISE(ABORT, 'core_agreement_draft_changed')
|
|
116
|
+
END;
|
|
117
|
+
END;
|
|
118
|
+
|
|
119
|
+
-- A new document starts as a draft with nothing in effect, and never over an existing id.
|
|
120
|
+
CREATE TRIGGER core_agreement_document_new
|
|
121
|
+
BEFORE INSERT ON core_agreement_document
|
|
122
|
+
BEGIN
|
|
123
|
+
SELECT CASE
|
|
124
|
+
WHEN EXISTS (SELECT 1 FROM core_agreement_document d WHERE d.id = NEW.id)
|
|
125
|
+
THEN RAISE(ABORT, 'core_agreement_version_immutable')
|
|
126
|
+
WHEN NEW.state != 'draft' OR NEW.current_version_id IS NOT NULL OR NEW.agree_from != 0
|
|
127
|
+
OR NEW.draft_rev != 0
|
|
128
|
+
THEN RAISE(ABORT, 'core_agreement_document_new')
|
|
129
|
+
END;
|
|
130
|
+
END;
|
|
131
|
+
|
|
132
|
+
-- The working copy's rev moves by exactly one per save: of two saves of the same rev, the second
|
|
133
|
+
-- is refused (compare-and-set).
|
|
134
|
+
CREATE TRIGGER core_agreement_document_draft_rev
|
|
135
|
+
BEFORE UPDATE OF draft_rev ON core_agreement_document
|
|
136
|
+
WHEN NEW.draft_rev != OLD.draft_rev + 1
|
|
137
|
+
BEGIN
|
|
138
|
+
SELECT RAISE(ABORT, 'core_agreement_draft_changed');
|
|
139
|
+
END;
|
|
140
|
+
|
|
141
|
+
-- Any change to the working copy moves its rev by one, raw writes included: so the editor's "someone
|
|
142
|
+
-- else changed it" always sees it, and a reviewed rev never covers different content.
|
|
143
|
+
CREATE TRIGGER core_agreement_document_draft_changes
|
|
144
|
+
BEFORE UPDATE OF draft_title, draft_body, draft_tick_label, draft_questions, draft_how, draft_who,
|
|
145
|
+
draft_for, draft_ask_again_months, draft_updated_at, draft_updated_by, draft_updated_via
|
|
146
|
+
ON core_agreement_document
|
|
147
|
+
WHEN (NEW.draft_title IS NOT OLD.draft_title OR NEW.draft_body IS NOT OLD.draft_body
|
|
148
|
+
OR NEW.draft_tick_label IS NOT OLD.draft_tick_label
|
|
149
|
+
OR NEW.draft_questions IS NOT OLD.draft_questions OR NEW.draft_how IS NOT OLD.draft_how
|
|
150
|
+
OR NEW.draft_who IS NOT OLD.draft_who OR NEW.draft_for IS NOT OLD.draft_for
|
|
151
|
+
OR NEW.draft_ask_again_months IS NOT OLD.draft_ask_again_months
|
|
152
|
+
OR NEW.draft_updated_at IS NOT OLD.draft_updated_at
|
|
153
|
+
OR NEW.draft_updated_by IS NOT OLD.draft_updated_by
|
|
154
|
+
OR NEW.draft_updated_via IS NOT OLD.draft_updated_via)
|
|
155
|
+
AND NEW.draft_rev IS NOT OLD.draft_rev + 1
|
|
156
|
+
BEGIN
|
|
157
|
+
SELECT RAISE(ABORT, 'core_agreement_draft_changed');
|
|
158
|
+
END;
|
|
159
|
+
|
|
160
|
+
-- A document keeps its id (an UPDATE OR REPLACE of the id would rewrite another document).
|
|
161
|
+
CREATE TRIGGER core_agreement_document_id
|
|
162
|
+
BEFORE UPDATE OF id ON core_agreement_document
|
|
163
|
+
WHEN NEW.id IS NOT OLD.id
|
|
164
|
+
BEGIN
|
|
165
|
+
SELECT RAISE(ABORT, 'core_agreement_document_fixed');
|
|
166
|
+
END;
|
|
167
|
+
|
|
168
|
+
-- The kind is fixed; the state only moves forward (draft to live or retired, live to retired).
|
|
169
|
+
CREATE TRIGGER core_agreement_document_kind_state
|
|
170
|
+
BEFORE UPDATE OF kind, state ON core_agreement_document
|
|
171
|
+
WHEN NEW.kind != OLD.kind OR (OLD.state = 'live' AND NEW.state = 'draft')
|
|
172
|
+
BEGIN
|
|
173
|
+
SELECT RAISE(ABORT, 'core_agreement_document_fixed');
|
|
174
|
+
END;
|
|
175
|
+
|
|
176
|
+
-- A document's current version is one of its own, only ever a newer one, never back to none;
|
|
177
|
+
-- and agree_from never goes back.
|
|
178
|
+
CREATE TRIGGER core_agreement_document_current
|
|
179
|
+
BEFORE UPDATE OF current_version_id, agree_from ON core_agreement_document
|
|
180
|
+
BEGIN
|
|
181
|
+
SELECT CASE
|
|
182
|
+
WHEN NEW.agree_from < OLD.agree_from
|
|
183
|
+
THEN RAISE(ABORT, 'core_agreement_agree_from_back')
|
|
184
|
+
WHEN NEW.current_version_id IS OLD.current_version_id
|
|
185
|
+
THEN NULL
|
|
186
|
+
WHEN NEW.current_version_id IS NULL
|
|
187
|
+
THEN RAISE(ABORT, 'core_agreement_agree_from_back')
|
|
188
|
+
WHEN NOT EXISTS (
|
|
189
|
+
SELECT 1 FROM core_agreement_version v
|
|
190
|
+
WHERE v.id = NEW.current_version_id AND v.document_id = NEW.id
|
|
191
|
+
AND v.number > COALESCE(
|
|
192
|
+
(SELECT o.number FROM core_agreement_version o WHERE o.id = OLD.current_version_id), 0)
|
|
193
|
+
)
|
|
194
|
+
THEN RAISE(ABORT, 'core_agreement_agree_from_back')
|
|
195
|
+
END;
|
|
196
|
+
END;
|
|
197
|
+
|
|
198
|
+
-- A retired document stays retired, and its working copy stays as it was.
|
|
199
|
+
CREATE TRIGGER core_agreement_document_retired
|
|
200
|
+
BEFORE UPDATE ON core_agreement_document
|
|
201
|
+
WHEN OLD.state = 'retired'
|
|
202
|
+
BEGIN
|
|
203
|
+
SELECT RAISE(ABORT, 'core_agreement_retired');
|
|
204
|
+
END;
|
|
205
|
+
|
|
206
|
+
-- Documents are the business's text, kept with their versions: never deleted.
|
|
207
|
+
CREATE TRIGGER core_agreement_document_no_delete
|
|
208
|
+
BEFORE DELETE ON core_agreement_document
|
|
209
|
+
BEGIN
|
|
210
|
+
SELECT RAISE(ABORT, 'core_agreement_version_immutable');
|
|
211
|
+
END;
|
|
212
|
+
|
|
213
|
+
-- Where a document is needed: an agreement point an installed object declares (ADR 0641).
|
|
214
|
+
CREATE TABLE core_agreement_point (
|
|
215
|
+
document_id TEXT NOT NULL REFERENCES core_agreement_document (id),
|
|
216
|
+
point TEXT NOT NULL,
|
|
217
|
+
attached_at TEXT NOT NULL,
|
|
218
|
+
attached_by TEXT NOT NULL,
|
|
219
|
+
PRIMARY KEY (document_id, point)
|
|
220
|
+
);
|
|
221
|
+
CREATE INDEX core_agreement_point_point_idx ON core_agreement_point (point);
|
|
222
|
+
|
|
223
|
+
-- Only a live document is attached.
|
|
224
|
+
CREATE TRIGGER core_agreement_point_live
|
|
225
|
+
BEFORE INSERT ON core_agreement_point
|
|
226
|
+
BEGIN
|
|
227
|
+
SELECT RAISE(ABORT, 'core_agreement_not_live')
|
|
228
|
+
WHERE NOT EXISTS (
|
|
229
|
+
SELECT 1 FROM core_agreement_document d WHERE d.id = NEW.document_id AND d.state = 'live'
|
|
230
|
+
);
|
|
231
|
+
END;
|
|
232
|
+
|
|
233
|
+
-- An attachment is added or removed, never rewritten (moving one to a never-published document
|
|
234
|
+
-- would get past the trigger above).
|
|
235
|
+
CREATE TRIGGER core_agreement_point_no_update
|
|
236
|
+
BEFORE UPDATE ON core_agreement_point
|
|
237
|
+
BEGIN
|
|
238
|
+
SELECT RAISE(ABORT, 'core_agreement_not_live');
|
|
239
|
+
END;
|
|
240
|
+
|
|
241
|
+
-- One counter the host bumps in the batch of every change to what is due (every publish, a
|
|
242
|
+
-- version the cron makes current, attach, detach, retire). Step 2's guard reads it.
|
|
243
|
+
CREATE TABLE core_agreement_rev (
|
|
244
|
+
id INTEGER PRIMARY KEY CHECK (id = 1),
|
|
245
|
+
rev INTEGER NOT NULL DEFAULT 0
|
|
246
|
+
);
|
|
247
|
+
INSERT INTO core_agreement_rev (id, rev) VALUES (1, 0);
|
|
248
|
+
|
|
249
|
+
CREATE TRIGGER core_agreement_rev_forward
|
|
250
|
+
BEFORE UPDATE ON core_agreement_rev
|
|
251
|
+
WHEN NEW.rev <= OLD.rev OR NEW.id != OLD.id
|
|
252
|
+
BEGIN
|
|
253
|
+
SELECT RAISE(ABORT, 'core_agreement_rev_back');
|
|
254
|
+
END;
|
|
255
|
+
|
|
256
|
+
-- Its one row is the one above: no other insert (a REPLACE included, which would reset it).
|
|
257
|
+
CREATE TRIGGER core_agreement_rev_no_insert
|
|
258
|
+
BEFORE INSERT ON core_agreement_rev
|
|
259
|
+
BEGIN
|
|
260
|
+
SELECT RAISE(ABORT, 'core_agreement_rev_back');
|
|
261
|
+
END;
|
|
262
|
+
|
|
263
|
+
CREATE TRIGGER core_agreement_rev_no_delete
|
|
264
|
+
BEFORE DELETE ON core_agreement_rev
|
|
265
|
+
BEGIN
|
|
266
|
+
SELECT RAISE(ABORT, 'core_agreement_rev_back');
|
|
267
|
+
END;
|
|
268
|
+
|
|
269
|
+
-- Guarded: migrations land out of order (docs/parallel-work.md).
|
|
270
|
+
UPDATE core_meta SET value = '850'
|
|
271
|
+
WHERE key = 'schema_version' AND CAST(value AS INTEGER) < 850;
|