@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.
- package/dist/{accounts-X4CKM3HL.js → accounts-GOCNY6WI.js} +17 -14
- package/dist/app-RPRZMLU5.js +43 -0
- package/dist/app-upload-YJVEKZC6.js +198 -0
- package/dist/{blocks-YWDHEBOK.js → blocks-DE4RRWPJ.js} +207 -25
- package/dist/{chunk-VY64DMQO.js → chunk-2B6YUYZV.js} +23576 -11674
- package/dist/{run-RT2HVWMK.js → chunk-2CCHB37H.js} +9 -146
- package/dist/{chunk-DU6OIFOU.js → chunk-3OGDWKJ3.js} +530 -434
- package/dist/chunk-5D7BDF4Y.js +141 -0
- package/dist/{chunk-WO6D3XP3.js → chunk-6CM3WZG5.js} +13 -2470
- package/dist/chunk-CIBJGB5H.js +962 -0
- package/dist/chunk-EPDTPGZJ.js +330 -0
- package/dist/{chunk-LLULPZAJ.js → chunk-HAYF4G5V.js} +66 -23
- package/dist/chunk-HCG6T53D.js +61904 -0
- package/dist/chunk-JX4IFWNT.js +330 -0
- package/dist/{chunk-A4NTSYWV.js → chunk-KFHKNXGH.js} +786 -386
- 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-LJFLENFC.js → chunk-Q6Y45DY6.js} +25 -2
- package/dist/{chunk-Y7JZFSTQ.js → chunk-QJZGYJVV.js} +823 -44
- package/dist/{chunk-6VXHPKGG.js → chunk-QQ3YSL5F.js} +172 -16
- package/dist/chunk-RGKJKC5T.js +876 -0
- package/dist/{chunk-IFG4FRW5.js → chunk-RSEWEFAV.js} +12 -2
- package/dist/{chunk-2ABSVMGB.js → chunk-SMJZIK2O.js} +1 -1
- package/dist/{chunk-CP6BXI6F.js → chunk-U72NEGCT.js} +8818 -3829
- package/dist/{chunk-WC5LHBBA.js → chunk-Z4IKF23A.js} +11 -7
- package/dist/chunk-Z7OVQ6BC.js +713 -0
- package/dist/{chunk-6UWRT4VM.js → chunk-ZJSFX4RD.js} +175 -3
- package/dist/{cli-2DFENR62.js → cli-OKQHHSOE.js} +17 -23
- package/dist/{cli-YIOVSKOD.js → cli-VYSD2S4Z.js} +231 -82
- package/dist/cli.js +5 -5
- package/dist/{client-repo-PRU3VCQQ.js → client-repo-NNUCHQ2Y.js} +7 -5
- package/dist/create.js +5 -5
- package/dist/{fields-2NC7LSYE.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-PUWD65BC.js → order-RKLGT74L.js} +2 -2
- package/dist/{person-WIQQ7ITU.js → person-YOZTFV4Q.js} +11 -11
- package/dist/plan-on-sale-H4F26YIN.js +26 -0
- package/dist/platform/migrations/0610_waitlists.sql +54 -0
- package/dist/platform/migrations/0630_subscription_changes.sql +122 -0
- package/dist/platform/migrations/0650_person_links.sql +90 -0
- package/dist/platform/migrations/0670_unmoved_guard.sql +52 -0
- package/dist/platform/migrations/0690_sellable_refund_due.sql +98 -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 +103 -2
- package/dist/platform/sdk/checklists.ts +118 -0
- package/dist/platform/sdk/contract.ts +514 -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 +1313 -66
- 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 +595 -1
- package/dist/platform/sdk/slug.ts +7 -2
- package/dist/platform/sdk/staffed.ts +474 -0
- package/dist/platform/sdk/states.ts +220 -64
- 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-Y7T4TVOL.js → run-QOFRRSZV.js} +41 -60
- package/dist/{run-PZUCSDDL.js → run-TJAEWR5U.js} +21 -51
- package/dist/{src-XTOD7EXW.js → src-52VERUPK.js} +312 -4
- package/dist/src-PHRELWN5.js +40 -0
- package/dist/visibility-SZCINPP4.js +58 -0
- package/package.json +2 -2
- package/dist/chunk-6GDEDOV7.js +0 -157
- package/dist/chunk-6UPUF4ML.js +0 -29998
- package/dist/chunk-7CQGMVDO.js +0 -63
- package/dist/chunk-GYSGVT6R.js +0 -284
- package/dist/chunk-JJHHNV46.js +0 -227
- package/dist/chunk-K6T42YCH.js +0 -704
- package/dist/chunk-M7A6FR2Z.js +0 -2586
- package/dist/chunk-O2UIZHND.js +0 -249
- package/dist/chunk-Q4N55M2Z.js +0 -552
- package/dist/chunk-QGGJ2G6Z.js +0 -349
- package/dist/chunk-R4W5XAUD.js +0 -837
- package/dist/chunk-TQFGGSA4.js +0 -748
- package/dist/chunk-YJJHF65I.js +0 -759
- package/dist/chunk-Z3RMMB6S.js +0 -668
- package/dist/grants-QXMKYMGB.js +0 -32
- package/dist/invoke-I3NNNXVL.js +0 -39
- package/dist/plan-on-sale-NB774CQL.js +0 -26
- package/dist/src-GYS6NBQB.js +0 -44
- package/dist/visibility-DLGHU4YN.js +0 -33
|
@@ -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;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
-- Migration 0812: offers and takes of shifts, and what the roster's notices and its uncovered
|
|
2
|
+
-- shifts read (stage 45 step 3, ADRs 0623 and 0624).
|
|
3
|
+
--
|
|
4
|
+
-- An offer is a shift (a record of an object that declares `staffed`) its person asks someone
|
|
5
|
+
-- else to take, or an uncovered shift a rosterer offers to everyone eligible. Exactly one take
|
|
6
|
+
-- wins: an offer moves out of `open` once, and the database refuses every later move, so of
|
|
7
|
+
-- twenty takes at once one commits and the rest fail whole (D1 runs one batch at a time). That
|
|
8
|
+
-- is the take's guard: the take's statement updates the offer by its id alone, and the trigger
|
|
9
|
+
-- below fails the batch when the offer is no longer open. No core_write_guard kind is needed.
|
|
10
|
+
--
|
|
11
|
+
-- D1 runs with recursive triggers off, so an INSERT OR REPLACE deletes the rows it replaces
|
|
12
|
+
-- without firing a delete or update trigger. An offer is therefore never replaced: a BEFORE
|
|
13
|
+
-- INSERT trigger refuses an id that exists, and a second open offer of one shift, before any
|
|
14
|
+
-- REPLACE could delete the first.
|
|
15
|
+
CREATE TABLE core_staff_offer (
|
|
16
|
+
id TEXT PRIMARY KEY,
|
|
17
|
+
-- The shift: its object's registry name and its record.
|
|
18
|
+
object_type TEXT NOT NULL,
|
|
19
|
+
record_id TEXT NOT NULL,
|
|
20
|
+
-- The shift's person when offered (core_user.id); null for an uncovered shift a rosterer offers.
|
|
21
|
+
from_account TEXT,
|
|
22
|
+
-- Who made it: the shift's person, or a rosterer.
|
|
23
|
+
made_by TEXT NOT NULL,
|
|
24
|
+
-- One named person it is offered to; null for everyone eligible.
|
|
25
|
+
to_account TEXT,
|
|
26
|
+
-- The shift's start (unix seconds), kept current while open: offers lapse in order of it.
|
|
27
|
+
starts INTEGER NOT NULL,
|
|
28
|
+
-- The shift's kind of work (its object and record), kept current while open: a taker's list
|
|
29
|
+
-- reads only offers of the kinds they are qualified for (the take checks again).
|
|
30
|
+
kind_object TEXT,
|
|
31
|
+
kind_record TEXT,
|
|
32
|
+
state TEXT NOT NULL CHECK (state IN ('open', 'taken', 'withdrawn', 'cancelled', 'lapsed')),
|
|
33
|
+
made_at TEXT NOT NULL,
|
|
34
|
+
taken_by TEXT,
|
|
35
|
+
taken_at TEXT,
|
|
36
|
+
-- When and by whom it left `open` (the host's user for a lapse or a cancel), and why.
|
|
37
|
+
ended_at TEXT,
|
|
38
|
+
ended_by TEXT,
|
|
39
|
+
why TEXT CHECK (why IS NULL OR length(why) <= 200),
|
|
40
|
+
CHECK (state != 'taken' OR (taken_by IS NOT NULL AND taken_at IS NOT NULL)),
|
|
41
|
+
CHECK (state = 'open' OR ended_at IS NOT NULL),
|
|
42
|
+
CHECK (from_account IS NULL OR to_account IS NULL OR to_account != from_account),
|
|
43
|
+
CHECK (from_account IS NULL OR taken_by IS NULL OR taken_by != from_account)
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
-- One open offer per shift; the open offers are read through it (the minute cron's lapse).
|
|
47
|
+
CREATE UNIQUE INDEX core_staff_offer_open ON core_staff_offer (object_type, record_id)
|
|
48
|
+
WHERE state = 'open';
|
|
49
|
+
-- The open offers in order of their shift's start: the minute cron lapses the nearest first, and
|
|
50
|
+
-- takers' lists read the soonest, however many far ones are open.
|
|
51
|
+
CREATE INDEX core_staff_offer_due ON core_staff_offer (starts) WHERE state = 'open';
|
|
52
|
+
-- A person's open offers, from them and to them (theirs to see; cancelled when they leave).
|
|
53
|
+
CREATE INDEX core_staff_offer_from ON core_staff_offer (from_account) WHERE state = 'open';
|
|
54
|
+
CREATE INDEX core_staff_offer_to ON core_staff_offer (to_account) WHERE state = 'open';
|
|
55
|
+
|
|
56
|
+
CREATE TRIGGER core_staff_offer_insert
|
|
57
|
+
BEFORE INSERT ON core_staff_offer
|
|
58
|
+
BEGIN
|
|
59
|
+
SELECT RAISE(ABORT, 'core_staff_offer_replaced')
|
|
60
|
+
WHERE EXISTS (SELECT 1 FROM core_staff_offer WHERE id = NEW.id);
|
|
61
|
+
SELECT RAISE(ABORT, 'core_staff_offer_closed') WHERE NEW.state != 'open';
|
|
62
|
+
SELECT RAISE(ABORT, 'core_staff_offer_open')
|
|
63
|
+
WHERE EXISTS (
|
|
64
|
+
SELECT 1 FROM core_staff_offer
|
|
65
|
+
WHERE object_type = NEW.object_type AND record_id = NEW.record_id AND state = 'open'
|
|
66
|
+
);
|
|
67
|
+
END;
|
|
68
|
+
|
|
69
|
+
-- An offer leaves `open` once (taken, withdrawn, cancelled or lapsed), and what it offers never
|
|
70
|
+
-- changes. The take's race is decided here.
|
|
71
|
+
CREATE TRIGGER core_staff_offer_update
|
|
72
|
+
BEFORE UPDATE ON core_staff_offer
|
|
73
|
+
BEGIN
|
|
74
|
+
SELECT RAISE(ABORT, 'core_staff_offer_closed') WHERE OLD.state != 'open';
|
|
75
|
+
SELECT RAISE(ABORT, 'core_staff_offer_fixed')
|
|
76
|
+
WHERE NEW.id != OLD.id OR NEW.object_type != OLD.object_type OR NEW.record_id != OLD.record_id
|
|
77
|
+
OR NEW.from_account IS NOT OLD.from_account OR NEW.to_account IS NOT OLD.to_account
|
|
78
|
+
OR NEW.made_by != OLD.made_by OR NEW.made_at != OLD.made_at;
|
|
79
|
+
END;
|
|
80
|
+
|
|
81
|
+
-- A batch planned from a read of what it changes (a leaver's future shifts and patterns, ADR 0624)
|
|
82
|
+
-- carries how many rows it expects a statement to change, or how many rows of a kind it read; the
|
|
83
|
+
-- batch fails whole when that is no longer so (`core_staff_changed`), so what it records and marks
|
|
84
|
+
-- is exactly what it changed. Nothing is stored.
|
|
85
|
+
CREATE TABLE core_staff_guard (
|
|
86
|
+
expected INTEGER NOT NULL,
|
|
87
|
+
actual INTEGER NOT NULL
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
CREATE TRIGGER core_staff_guard_check
|
|
91
|
+
BEFORE INSERT ON core_staff_guard
|
|
92
|
+
BEGIN
|
|
93
|
+
SELECT CASE
|
|
94
|
+
WHEN NEW.actual != NEW.expected THEN RAISE(ABORT, 'core_staff_changed')
|
|
95
|
+
ELSE RAISE(IGNORE)
|
|
96
|
+
END;
|
|
97
|
+
END;
|
|
98
|
+
|
|
99
|
+
-- Who is qualified for one kind of work (the offer's eligible people), read by the kind.
|
|
100
|
+
CREATE INDEX core_staff_qualification_kind
|
|
101
|
+
ON core_staff_qualification (kind_object, kind_record);
|
|
102
|
+
|
|
103
|
+
-- The roster's daily work (the uncovered notice): the local date each last ran, so it runs once a
|
|
104
|
+
-- day whatever the minute cron does.
|
|
105
|
+
CREATE TABLE core_staff_run (
|
|
106
|
+
name TEXT PRIMARY KEY,
|
|
107
|
+
last_date TEXT NOT NULL
|
|
108
|
+
) WITHOUT ROWID;
|
|
109
|
+
|
|
110
|
+
-- Guarded: migrations land out of order (docs/parallel-work.md).
|
|
111
|
+
UPDATE core_meta SET value = '812'
|
|
112
|
+
WHERE key = 'schema_version' AND CAST(value AS INTEGER) < 812;
|