@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,27 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
GRANT_CODE_LENGTH,
|
|
4
|
+
grantFieldValue,
|
|
5
|
+
grantsFollowPerson,
|
|
6
|
+
handGrantValues,
|
|
7
|
+
newGrantCode,
|
|
8
|
+
readGrantItem,
|
|
9
|
+
validFrom
|
|
10
|
+
} from "./chunk-JX4IFWNT.js";
|
|
11
|
+
import "./chunk-KMFMD52Z.js";
|
|
12
|
+
import "./chunk-KGHA67HG.js";
|
|
13
|
+
import "./chunk-KFHKNXGH.js";
|
|
14
|
+
import "./chunk-RSEWEFAV.js";
|
|
15
|
+
import "./chunk-CIBJGB5H.js";
|
|
16
|
+
import "./chunk-U72NEGCT.js";
|
|
17
|
+
import "./chunk-RGKJKC5T.js";
|
|
18
|
+
import "./chunk-5KSXSK7Y.js";
|
|
19
|
+
export {
|
|
20
|
+
GRANT_CODE_LENGTH,
|
|
21
|
+
grantFieldValue,
|
|
22
|
+
grantsFollowPerson,
|
|
23
|
+
handGrantValues,
|
|
24
|
+
newGrantCode,
|
|
25
|
+
readGrantItem,
|
|
26
|
+
validFrom
|
|
27
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
coreInvoker,
|
|
4
|
+
coreRegistry,
|
|
5
|
+
createInvoker,
|
|
6
|
+
invoke,
|
|
7
|
+
invokeByName,
|
|
8
|
+
listOperations
|
|
9
|
+
} from "./chunk-HCG6T53D.js";
|
|
10
|
+
import "./chunk-6CM3WZG5.js";
|
|
11
|
+
import "./chunk-JX4IFWNT.js";
|
|
12
|
+
import "./chunk-5D7BDF4Y.js";
|
|
13
|
+
import "./chunk-Z7OVQ6BC.js";
|
|
14
|
+
import "./chunk-2B6YUYZV.js";
|
|
15
|
+
import "./chunk-KMFMD52Z.js";
|
|
16
|
+
import "./chunk-3OGDWKJ3.js";
|
|
17
|
+
import "./chunk-KGHA67HG.js";
|
|
18
|
+
import "./chunk-ZJSFX4RD.js";
|
|
19
|
+
import "./chunk-KFHKNXGH.js";
|
|
20
|
+
import "./chunk-RSEWEFAV.js";
|
|
21
|
+
import "./chunk-CIBJGB5H.js";
|
|
22
|
+
import "./chunk-U72NEGCT.js";
|
|
23
|
+
import "./chunk-Q6Y45DY6.js";
|
|
24
|
+
import "./chunk-RGKJKC5T.js";
|
|
25
|
+
import "./chunk-5KSXSK7Y.js";
|
|
26
|
+
export {
|
|
27
|
+
coreInvoker,
|
|
28
|
+
coreRegistry,
|
|
29
|
+
createInvoker,
|
|
30
|
+
invoke,
|
|
31
|
+
invokeByName,
|
|
32
|
+
listOperations
|
|
33
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
DEFAULT_HOLD_PERCENT,
|
|
4
|
+
UNSETTLED_RELEASES,
|
|
5
|
+
UNSETTLED_SCAN,
|
|
6
|
+
movedRecords,
|
|
7
|
+
movesFollowPerson,
|
|
8
|
+
movesOf,
|
|
9
|
+
oweLateRefund,
|
|
10
|
+
releaseUnsettledGuest,
|
|
11
|
+
startHeld,
|
|
12
|
+
unsettledGuests
|
|
13
|
+
} from "./chunk-Z7OVQ6BC.js";
|
|
14
|
+
import "./chunk-2B6YUYZV.js";
|
|
15
|
+
import "./chunk-KMFMD52Z.js";
|
|
16
|
+
import "./chunk-KGHA67HG.js";
|
|
17
|
+
import "./chunk-ZJSFX4RD.js";
|
|
18
|
+
import "./chunk-KFHKNXGH.js";
|
|
19
|
+
import "./chunk-RSEWEFAV.js";
|
|
20
|
+
import "./chunk-CIBJGB5H.js";
|
|
21
|
+
import "./chunk-U72NEGCT.js";
|
|
22
|
+
import "./chunk-Q6Y45DY6.js";
|
|
23
|
+
import "./chunk-RGKJKC5T.js";
|
|
24
|
+
import "./chunk-5KSXSK7Y.js";
|
|
25
|
+
export {
|
|
26
|
+
DEFAULT_HOLD_PERCENT,
|
|
27
|
+
UNSETTLED_RELEASES,
|
|
28
|
+
UNSETTLED_SCAN,
|
|
29
|
+
movedRecords,
|
|
30
|
+
movesFollowPerson,
|
|
31
|
+
movesOf,
|
|
32
|
+
oweLateRefund,
|
|
33
|
+
releaseUnsettledGuest,
|
|
34
|
+
startHeld,
|
|
35
|
+
unsettledGuests
|
|
36
|
+
};
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
personOperations,
|
|
18
18
|
personRestore,
|
|
19
19
|
personSchema,
|
|
20
|
+
personSetBirthday,
|
|
20
21
|
personSnapshot,
|
|
21
22
|
personUpdate,
|
|
22
23
|
personUpdateMany,
|
|
@@ -24,20 +25,18 @@ import {
|
|
|
24
25
|
phoneInputSchema,
|
|
25
26
|
socialProfileSchema,
|
|
26
27
|
updatePerson
|
|
27
|
-
} from "./chunk-
|
|
28
|
-
import "./chunk-Z3RMMB6S.js";
|
|
29
|
-
import "./chunk-6GDEDOV7.js";
|
|
30
|
-
import "./chunk-QGGJ2G6Z.js";
|
|
28
|
+
} from "./chunk-2B6YUYZV.js";
|
|
31
29
|
import {
|
|
32
30
|
TRASH_RETENTION_DAYS
|
|
33
|
-
} from "./chunk-
|
|
34
|
-
import "./chunk-TQFGGSA4.js";
|
|
31
|
+
} from "./chunk-KMFMD52Z.js";
|
|
35
32
|
import "./chunk-KGHA67HG.js";
|
|
36
|
-
import "./chunk-
|
|
37
|
-
import "./chunk-
|
|
38
|
-
import "./chunk-
|
|
39
|
-
import "./chunk-
|
|
40
|
-
import "./chunk-
|
|
33
|
+
import "./chunk-ZJSFX4RD.js";
|
|
34
|
+
import "./chunk-KFHKNXGH.js";
|
|
35
|
+
import "./chunk-RSEWEFAV.js";
|
|
36
|
+
import "./chunk-CIBJGB5H.js";
|
|
37
|
+
import "./chunk-U72NEGCT.js";
|
|
38
|
+
import "./chunk-Q6Y45DY6.js";
|
|
39
|
+
import "./chunk-RGKJKC5T.js";
|
|
41
40
|
import "./chunk-5KSXSK7Y.js";
|
|
42
41
|
export {
|
|
43
42
|
TRASH_RETENTION_DAYS,
|
|
@@ -58,6 +57,7 @@ export {
|
|
|
58
57
|
personOperations,
|
|
59
58
|
personRestore,
|
|
60
59
|
personSchema,
|
|
60
|
+
personSetBirthday,
|
|
61
61
|
personSnapshot,
|
|
62
62
|
personUpdate,
|
|
63
63
|
personUpdateMany,
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
PLANS_LOOKED_AT,
|
|
4
|
+
PLAN_ON_SALE_MEMO_MS,
|
|
5
|
+
findPlanOnSale,
|
|
6
|
+
forgetPlanOnSale,
|
|
7
|
+
hasPlanOnSale
|
|
8
|
+
} from "./chunk-5D7BDF4Y.js";
|
|
9
|
+
import "./chunk-2B6YUYZV.js";
|
|
10
|
+
import "./chunk-KMFMD52Z.js";
|
|
11
|
+
import "./chunk-KGHA67HG.js";
|
|
12
|
+
import "./chunk-ZJSFX4RD.js";
|
|
13
|
+
import "./chunk-KFHKNXGH.js";
|
|
14
|
+
import "./chunk-RSEWEFAV.js";
|
|
15
|
+
import "./chunk-CIBJGB5H.js";
|
|
16
|
+
import "./chunk-U72NEGCT.js";
|
|
17
|
+
import "./chunk-Q6Y45DY6.js";
|
|
18
|
+
import "./chunk-RGKJKC5T.js";
|
|
19
|
+
import "./chunk-5KSXSK7Y.js";
|
|
20
|
+
export {
|
|
21
|
+
PLANS_LOOKED_AT,
|
|
22
|
+
PLAN_ON_SALE_MEMO_MS,
|
|
23
|
+
findPlanOnSale,
|
|
24
|
+
forgetPlanOnSale,
|
|
25
|
+
hasPlanOnSale
|
|
26
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
-- Migration 0610: waitlists on capacity claimants (stage 31a step 5, ADR 0520).
|
|
2
|
+
--
|
|
3
|
+
-- A claimant that declares a waitlist (a booking waiting for a full class) holds no place while it
|
|
4
|
+
-- waits. Until its cut-off, a place given back while anyone waits is handed to the waitlist in the
|
|
5
|
+
-- statements that give it back: a claim of its own on the class's counter, `for_type = 'waitlist'`
|
|
6
|
+
-- and `for_id` the claimant object, held. Nobody booking directly can take it, because the counter
|
|
7
|
+
-- counts it. The host promotes the first waiter from a current read; the promotion's batch gives
|
|
8
|
+
-- one waitlist hold back and claims the waiter's place, so the counter never goes past its places
|
|
9
|
+
-- and two promotions for one hold cannot both succeed (the second finds the class full).
|
|
10
|
+
--
|
|
11
|
+
-- Nothing new is stored beyond those claims; this migration adds:
|
|
12
|
+
-- * an index for the minute cron's sweep of waitlist holds;
|
|
13
|
+
-- * a guard kind for a waiter's join: the class must be full when the join commits, so nobody
|
|
14
|
+
-- waits behind a free place. core_write_guard stores nothing, so it is made again with the
|
|
15
|
+
-- new kind (SQLite cannot change a CHECK in place).
|
|
16
|
+
CREATE INDEX core_capacity_claim_waitlist_idx ON core_capacity_claim (for_type, state, object_type, record_id)
|
|
17
|
+
WHERE for_type = 'waitlist';
|
|
18
|
+
|
|
19
|
+
DROP TRIGGER core_write_guard_check;
|
|
20
|
+
DROP TABLE core_write_guard;
|
|
21
|
+
|
|
22
|
+
-- As migration 0560's, with kind 'full': the counter has places and they are all held or taken.
|
|
23
|
+
CREATE TABLE core_write_guard (
|
|
24
|
+
kind TEXT NOT NULL CHECK (kind IN ('claimed', 'claimant', 'series', 'full')),
|
|
25
|
+
object_type TEXT NOT NULL,
|
|
26
|
+
record_id TEXT NOT NULL,
|
|
27
|
+
expected INTEGER NOT NULL
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
CREATE TRIGGER core_write_guard_check
|
|
31
|
+
BEFORE INSERT ON core_write_guard
|
|
32
|
+
BEGIN
|
|
33
|
+
SELECT CASE
|
|
34
|
+
WHEN NEW.kind = 'claimed' AND coalesce((SELECT held + taken FROM core_capacity
|
|
35
|
+
WHERE object_type = NEW.object_type AND record_id = NEW.record_id), 0) != NEW.expected
|
|
36
|
+
THEN RAISE(ABORT, 'core_recurrence_stale')
|
|
37
|
+
WHEN NEW.kind = 'series' AND coalesce((SELECT version FROM core_recurrence_series
|
|
38
|
+
WHERE object_type = NEW.object_type AND record_id = NEW.record_id), 0) != NEW.expected
|
|
39
|
+
THEN RAISE(ABORT, 'core_recurrence_stale')
|
|
40
|
+
WHEN NEW.kind = 'claimant' AND (SELECT count(*) FROM core_capacity_claim
|
|
41
|
+
WHERE for_type = NEW.object_type AND for_id = NEW.record_id
|
|
42
|
+
AND state IN ('held', 'confirmed')) != NEW.expected
|
|
43
|
+
THEN RAISE(ABORT, 'core_claim_live')
|
|
44
|
+
WHEN NEW.kind = 'full' AND NOT EXISTS (SELECT 1 FROM core_capacity
|
|
45
|
+
WHERE object_type = NEW.object_type AND record_id = NEW.record_id
|
|
46
|
+
AND places IS NOT NULL AND held + taken >= places)
|
|
47
|
+
THEN RAISE(ABORT, 'core_waitlist_not_full')
|
|
48
|
+
ELSE RAISE(IGNORE)
|
|
49
|
+
END;
|
|
50
|
+
END;
|
|
51
|
+
|
|
52
|
+
-- Guarded: migrations land out of order (docs/parallel-work.md).
|
|
53
|
+
UPDATE core_meta SET value = '610'
|
|
54
|
+
WHERE key = 'schema_version' AND CAST(value AS INTEGER) < 610;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
-- Migration 0630: plan changes and pauses of a subscription (stage 32b, ADRs 0530 and 0531).
|
|
2
|
+
--
|
|
3
|
+
-- A change the host asked the provider for: a plan change (an upgrade now, a downgrade from the
|
|
4
|
+
-- next period) or a pause (from now or a moment, until a moment). The provider runs it; this row is
|
|
5
|
+
-- what the host asked, so a verified read that shows it can be told from a change made at the
|
|
6
|
+
-- provider some other way, and so the member's terms follow the plan only from a read that shows
|
|
7
|
+
-- the change. Nothing here moves the subscription: its state is the provider's, mirrored.
|
|
8
|
+
--
|
|
9
|
+
-- requested asked of the provider (written before the call is made, after the operation's
|
|
10
|
+
-- batch claims the subscription's one open change); not yet in a verified read
|
|
11
|
+
-- waiting a downgrade the provider shows (its price is the new one), whose terms follow when
|
|
12
|
+
-- the next period starts (`effective_at`, the period end of the read that showed it)
|
|
13
|
+
-- applied the member holds the new plan (a change), or the pause is running or over
|
|
14
|
+
-- lapsed past `expires_at` and never shown by the provider (an upgrade's pending update
|
|
15
|
+
-- expires within 23 hours), or the provider refused the call outright
|
|
16
|
+
-- withdrawn closed by staff (`subscription.change.withdraw`, `subscription.unpause` of a pause
|
|
17
|
+
-- not started), or a waiting downgrade the provider no longer shows (its price put back)
|
|
18
|
+
--
|
|
19
|
+
-- One definition of "open": state requested or waiting and `expires_at` still ahead. Every reader
|
|
20
|
+
-- (the host's TypeScript and this view) uses it; a row found past it is closed as lapsed.
|
|
21
|
+
CREATE TABLE core_subscription_change (
|
|
22
|
+
-- sbc_… (ids.ts); the provider's idempotency key for the call.
|
|
23
|
+
id TEXT PRIMARY KEY NOT NULL,
|
|
24
|
+
subscription_id TEXT NOT NULL REFERENCES core_subscription (id) ON DELETE CASCADE,
|
|
25
|
+
kind TEXT NOT NULL CHECK (kind IN ('upgrade', 'downgrade', 'pause')),
|
|
26
|
+
state TEXT NOT NULL CHECK (state IN ('requested', 'waiting', 'applied', 'lapsed', 'withdrawn')),
|
|
27
|
+
-- The plan held when it was asked, and the plan asked for (a change; null for a pause).
|
|
28
|
+
from_plan_id TEXT NOT NULL,
|
|
29
|
+
from_plan_title TEXT NOT NULL,
|
|
30
|
+
from_amount INTEGER NOT NULL CHECK (from_amount > 0),
|
|
31
|
+
to_plan_id TEXT,
|
|
32
|
+
to_plan_title TEXT,
|
|
33
|
+
to_amount INTEGER CHECK (to_amount IS NULL OR to_amount > 0),
|
|
34
|
+
-- A pause's window: from (null: now) and until, as asked.
|
|
35
|
+
pause_from TEXT,
|
|
36
|
+
pause_until TEXT,
|
|
37
|
+
-- When the member's terms follow a change: the period's end for a downgrade, the moment the
|
|
38
|
+
-- provider showed it for an upgrade.
|
|
39
|
+
effective_at TEXT,
|
|
40
|
+
-- When an open change stops being trusted, never shown by the provider: a day after it was
|
|
41
|
+
-- asked (a pause: a day after it was due to start), a week after a waiting downgrade's period end.
|
|
42
|
+
expires_at TEXT NOT NULL,
|
|
43
|
+
-- What came of the host's call to the provider: sent (applied at the gatekeeper), pending (waiting
|
|
44
|
+
-- for approval), unknown (it may or may not have reached the provider: verified reads decide),
|
|
45
|
+
-- refused (it did not). Null until the call returns.
|
|
46
|
+
call_outcome TEXT CHECK (call_outcome IS NULL OR call_outcome IN ('sent', 'pending', 'unknown', 'refused')),
|
|
47
|
+
call_error TEXT,
|
|
48
|
+
-- The provider's page to confirm an upgrade's charge (3D Secure), while it waits.
|
|
49
|
+
action_url TEXT,
|
|
50
|
+
-- The call that ends or undoes it: ending a pause early, putting a withdrawn downgrade's price back.
|
|
51
|
+
end_outcome TEXT CHECK (end_outcome IS NULL OR end_outcome IN ('sent', 'pending', 'unknown', 'refused')),
|
|
52
|
+
end_error TEXT,
|
|
53
|
+
end_at TEXT,
|
|
54
|
+
reason TEXT NOT NULL,
|
|
55
|
+
-- Who asked: `staff:<user id>` or `customer:<customer id>`.
|
|
56
|
+
requested_by TEXT NOT NULL,
|
|
57
|
+
requested_at TEXT NOT NULL,
|
|
58
|
+
applied_at TEXT,
|
|
59
|
+
updated_at TEXT NOT NULL,
|
|
60
|
+
CHECK ((kind = 'pause') = (to_plan_id IS NULL)),
|
|
61
|
+
CHECK (kind <> 'pause' OR pause_until IS NOT NULL)
|
|
62
|
+
);
|
|
63
|
+
-- One open change per subscription: two asked at once, the second's whole batch fails, so the
|
|
64
|
+
-- provider is asked once.
|
|
65
|
+
CREATE UNIQUE INDEX core_subscription_change_open_uq ON core_subscription_change (subscription_id)
|
|
66
|
+
WHERE state IN ('requested', 'waiting');
|
|
67
|
+
CREATE INDEX core_subscription_change_subscription_idx
|
|
68
|
+
ON core_subscription_change (subscription_id, requested_at);
|
|
69
|
+
|
|
70
|
+
CREATE VIEW rec_subscription_change AS
|
|
71
|
+
SELECT
|
|
72
|
+
id, subscription_id, kind, state, from_plan_id, from_plan_title, from_amount, to_plan_id,
|
|
73
|
+
to_plan_title, to_amount, pause_from, pause_until, effective_at, expires_at, call_outcome,
|
|
74
|
+
end_outcome, reason, requested_at,
|
|
75
|
+
applied_at
|
|
76
|
+
FROM core_subscription_change;
|
|
77
|
+
|
|
78
|
+
-- The subscription as the seam reads it gains the change it shows: its open change (asked, or a
|
|
79
|
+
-- downgrade waiting for its period, or a pause not yet started), or the pause it is in while
|
|
80
|
+
-- paused. An upgrade asked over a day ago and never shown by the provider reads `lapsed`.
|
|
81
|
+
DROP VIEW rec_subscription;
|
|
82
|
+
CREATE VIEW rec_subscription AS
|
|
83
|
+
SELECT
|
|
84
|
+
s.id, s.payer_person_id, s.holder_person_id, s.email, s.placed_as, s.plan_object, s.plan_id,
|
|
85
|
+
s.plan_title, s.amount, s.currency, s.interval, s.tax_code IS NOT NULL AS taxed, s.state,
|
|
86
|
+
s.provider, s.provider_ref, s.trial_end, s.current_period_start, s.current_period_end,
|
|
87
|
+
s.cancel_at_period_end, s.cancel_at, s.canceled_at, s.ended_at, s.end_reason, s.action_url,
|
|
88
|
+
s.failing_since, s.created_at, s.updated_at,
|
|
89
|
+
c.id AS change_id,
|
|
90
|
+
c.kind AS change_kind,
|
|
91
|
+
CASE
|
|
92
|
+
WHEN c.state IN ('requested', 'waiting')
|
|
93
|
+
AND c.expires_at <= strftime('%Y-%m-%dT%H:%M:%fZ', 'now') THEN 'lapsed'
|
|
94
|
+
ELSE c.state
|
|
95
|
+
END AS change_state,
|
|
96
|
+
c.call_outcome AS change_call_outcome,
|
|
97
|
+
-- Only while the change is open: a lapsed or withdrawn upgrade shows no page to pay.
|
|
98
|
+
CASE
|
|
99
|
+
WHEN c.state = 'requested' AND c.expires_at > strftime('%Y-%m-%dT%H:%M:%fZ', 'now')
|
|
100
|
+
THEN c.action_url
|
|
101
|
+
END AS change_action_url,
|
|
102
|
+
c.end_outcome AS change_end_outcome,
|
|
103
|
+
c.to_plan_id AS change_to_plan_id,
|
|
104
|
+
c.to_plan_title AS change_to_plan_title,
|
|
105
|
+
c.to_amount AS change_to_amount,
|
|
106
|
+
c.pause_from AS pause_from,
|
|
107
|
+
c.pause_until AS pause_until,
|
|
108
|
+
c.effective_at AS change_effective_at,
|
|
109
|
+
c.requested_at AS change_requested_at
|
|
110
|
+
FROM core_subscription s
|
|
111
|
+
LEFT JOIN core_subscription_change c ON c.id = (
|
|
112
|
+
SELECT x.id FROM core_subscription_change x
|
|
113
|
+
WHERE x.subscription_id = s.id
|
|
114
|
+
AND (x.state IN ('requested', 'waiting')
|
|
115
|
+
OR (x.kind = 'pause' AND x.state = 'applied' AND s.state = 'paused'))
|
|
116
|
+
ORDER BY x.state IN ('requested', 'waiting') DESC, x.requested_at DESC
|
|
117
|
+
LIMIT 1
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
-- Guarded: migrations land out of order (docs/parallel-work.md).
|
|
121
|
+
UPDATE core_meta SET value = '630'
|
|
122
|
+
WHERE key = 'schema_version' AND CAST(value AS INTEGER) < 630;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
-- Migration 0650: the family link (stage 31a step 6, ADR 0540).
|
|
2
|
+
--
|
|
3
|
+
-- A link between two People: a guardian and a dependant (a parent and a child). While it is live
|
|
4
|
+
-- (not ended), the visibility seam lets the guardian, signed in as a customer, read the
|
|
5
|
+
-- dependant's records of every object whose customer declaration opts in (`guardians`), and
|
|
6
|
+
-- write them where it says so (book a class for a child). Nothing else reads it to decide access.
|
|
7
|
+
--
|
|
8
|
+
-- Staff make and end links, a person only (`person.link.add` and `person.link.end`, permission
|
|
9
|
+
-- `people:link`). An ended link is kept, with who ended it and when, as the audit of who could act
|
|
10
|
+
-- for whom; it gives nothing. A dependant may have several guardians and a guardian several
|
|
11
|
+
-- dependants; one live link per pair. A link from a Person to themselves cannot exist.
|
|
12
|
+
--
|
|
13
|
+
-- Both people are core_person rows: an erase (a hard delete) removes their links with them by the
|
|
14
|
+
-- foreign keys; a merge re-points them to the survivor in its batch (person.merge).
|
|
15
|
+
CREATE TABLE core_person_link (
|
|
16
|
+
id TEXT PRIMARY KEY,
|
|
17
|
+
kind TEXT NOT NULL DEFAULT 'guardian' CHECK (kind IN ('guardian')),
|
|
18
|
+
guardian_id TEXT NOT NULL REFERENCES core_person (id) ON DELETE CASCADE,
|
|
19
|
+
dependant_id TEXT NOT NULL REFERENCES core_person (id) ON DELETE CASCADE,
|
|
20
|
+
-- Why staff made it (optional): "mother", "guardian by court order".
|
|
21
|
+
note TEXT,
|
|
22
|
+
-- The staff account (usr_…) that made it, and when.
|
|
23
|
+
created_by TEXT NOT NULL,
|
|
24
|
+
created_at TEXT NOT NULL,
|
|
25
|
+
-- Set when it ends; it never starts again (a new link is made instead).
|
|
26
|
+
ended_at TEXT,
|
|
27
|
+
ended_by TEXT,
|
|
28
|
+
end_reason TEXT,
|
|
29
|
+
CHECK (guardian_id != dependant_id)
|
|
30
|
+
);
|
|
31
|
+
-- One live link per pair and kind; the guardian's dependants are what the seam reads.
|
|
32
|
+
CREATE UNIQUE INDEX core_person_link_live_uq
|
|
33
|
+
ON core_person_link (guardian_id, dependant_id, kind) WHERE ended_at IS NULL;
|
|
34
|
+
CREATE INDEX core_person_link_dependant_idx ON core_person_link (dependant_id, ended_at);
|
|
35
|
+
|
|
36
|
+
-- Never a two-way link: while A is B's guardian, B cannot be A's (a child would act for their
|
|
37
|
+
-- parent). Refused for every writer, so two staff linking the same pair in opposite directions at
|
|
38
|
+
-- once get one, and a merge that would make a two-way link fails unless it ends one first.
|
|
39
|
+
CREATE TRIGGER core_person_link_no_reverse_insert
|
|
40
|
+
BEFORE INSERT ON core_person_link
|
|
41
|
+
WHEN NEW.ended_at IS NULL
|
|
42
|
+
BEGIN
|
|
43
|
+
SELECT RAISE(ABORT, 'core_person_link_reverse')
|
|
44
|
+
WHERE EXISTS (
|
|
45
|
+
SELECT 1 FROM core_person_link r
|
|
46
|
+
WHERE r.guardian_id = NEW.dependant_id AND r.dependant_id = NEW.guardian_id
|
|
47
|
+
AND r.kind = NEW.kind AND r.ended_at IS NULL
|
|
48
|
+
);
|
|
49
|
+
END;
|
|
50
|
+
|
|
51
|
+
CREATE TRIGGER core_person_link_no_reverse_update
|
|
52
|
+
BEFORE UPDATE OF guardian_id, dependant_id, ended_at ON core_person_link
|
|
53
|
+
WHEN NEW.ended_at IS NULL
|
|
54
|
+
BEGIN
|
|
55
|
+
SELECT RAISE(ABORT, 'core_person_link_reverse')
|
|
56
|
+
WHERE EXISTS (
|
|
57
|
+
SELECT 1 FROM core_person_link r
|
|
58
|
+
WHERE r.guardian_id = NEW.dependant_id AND r.dependant_id = NEW.guardian_id
|
|
59
|
+
AND r.kind = NEW.kind AND r.ended_at IS NULL AND r.id != NEW.id
|
|
60
|
+
);
|
|
61
|
+
END;
|
|
62
|
+
|
|
63
|
+
-- The guard a guardian's write carries in its own batch (ADR 0540): one row saying "this guardian
|
|
64
|
+
-- acts for this dependant". The trigger lets it through (and drops it: nothing is stored) only
|
|
65
|
+
-- while the link is live and both People are out of the Trash; otherwise the whole batch fails,
|
|
66
|
+
-- so a link ended a moment before cannot be written through.
|
|
67
|
+
CREATE TABLE core_person_link_guard (
|
|
68
|
+
guardian_id TEXT NOT NULL,
|
|
69
|
+
dependant_id TEXT NOT NULL
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
CREATE TRIGGER core_person_link_guard_check
|
|
73
|
+
BEFORE INSERT ON core_person_link_guard
|
|
74
|
+
BEGIN
|
|
75
|
+
SELECT CASE
|
|
76
|
+
WHEN NOT EXISTS (
|
|
77
|
+
SELECT 1 FROM core_person_link l
|
|
78
|
+
JOIN core_person d ON d.id = l.dependant_id AND d.deleted_at IS NULL
|
|
79
|
+
JOIN core_person g ON g.id = l.guardian_id AND g.deleted_at IS NULL
|
|
80
|
+
WHERE l.guardian_id = NEW.guardian_id AND l.dependant_id = NEW.dependant_id
|
|
81
|
+
AND l.kind = 'guardian' AND l.ended_at IS NULL
|
|
82
|
+
)
|
|
83
|
+
THEN RAISE(ABORT, 'core_person_link_not_live')
|
|
84
|
+
ELSE RAISE(IGNORE)
|
|
85
|
+
END;
|
|
86
|
+
END;
|
|
87
|
+
|
|
88
|
+
-- Guarded: migrations land out of order (docs/parallel-work.md).
|
|
89
|
+
UPDATE core_meta SET value = '650'
|
|
90
|
+
WHERE key = 'schema_version' AND CAST(value AS INTEGER) < 650;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
-- Migration 0670: a guard that the record a write is for has not moved meanwhile (stage 31a
|
|
2
|
+
-- step 7, ADR 0550).
|
|
3
|
+
--
|
|
4
|
+
-- A booking is made only while its class is scheduled (`states.create.closed`, ADR 0507): the
|
|
5
|
+
-- check reads the class when the write is planned. A class cancelled between that read and the
|
|
6
|
+
-- booking's commit would otherwise be left with a booking its cancel never saw (the cancel moves
|
|
7
|
+
-- the bookings it reads, in its own batch). So a write judged against a `closed` flag queues a
|
|
8
|
+
-- guard on the record the flag is read through: the number of moves in its state history
|
|
9
|
+
-- (core_transition_history, ADR 0425) must still be what was read. A move in between adds a row,
|
|
10
|
+
-- and the write's batch fails whole (`core_moved_meanwhile`, answered as a conflict).
|
|
11
|
+
--
|
|
12
|
+
-- core_write_guard stores nothing, so it is made again with the new kind (SQLite cannot change a
|
|
13
|
+
-- CHECK in place), as migrations 0560 and 0610 did.
|
|
14
|
+
DROP TRIGGER core_write_guard_check;
|
|
15
|
+
DROP TABLE core_write_guard;
|
|
16
|
+
|
|
17
|
+
-- As migration 0610's, with kind 'unmoved': the record's state history has `expected` rows.
|
|
18
|
+
CREATE TABLE core_write_guard (
|
|
19
|
+
kind TEXT NOT NULL CHECK (kind IN ('claimed', 'claimant', 'series', 'full', 'unmoved')),
|
|
20
|
+
object_type TEXT NOT NULL,
|
|
21
|
+
record_id TEXT NOT NULL,
|
|
22
|
+
expected INTEGER NOT NULL
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
CREATE TRIGGER core_write_guard_check
|
|
26
|
+
BEFORE INSERT ON core_write_guard
|
|
27
|
+
BEGIN
|
|
28
|
+
SELECT CASE
|
|
29
|
+
WHEN NEW.kind = 'claimed' AND coalesce((SELECT held + taken FROM core_capacity
|
|
30
|
+
WHERE object_type = NEW.object_type AND record_id = NEW.record_id), 0) != NEW.expected
|
|
31
|
+
THEN RAISE(ABORT, 'core_recurrence_stale')
|
|
32
|
+
WHEN NEW.kind = 'series' AND coalesce((SELECT version FROM core_recurrence_series
|
|
33
|
+
WHERE object_type = NEW.object_type AND record_id = NEW.record_id), 0) != NEW.expected
|
|
34
|
+
THEN RAISE(ABORT, 'core_recurrence_stale')
|
|
35
|
+
WHEN NEW.kind = 'claimant' AND (SELECT count(*) FROM core_capacity_claim
|
|
36
|
+
WHERE for_type = NEW.object_type AND for_id = NEW.record_id
|
|
37
|
+
AND state IN ('held', 'confirmed')) != NEW.expected
|
|
38
|
+
THEN RAISE(ABORT, 'core_claim_live')
|
|
39
|
+
WHEN NEW.kind = 'full' AND NOT EXISTS (SELECT 1 FROM core_capacity
|
|
40
|
+
WHERE object_type = NEW.object_type AND record_id = NEW.record_id
|
|
41
|
+
AND places IS NOT NULL AND held + taken >= places)
|
|
42
|
+
THEN RAISE(ABORT, 'core_waitlist_not_full')
|
|
43
|
+
WHEN NEW.kind = 'unmoved' AND (SELECT count(*) FROM core_transition_history
|
|
44
|
+
WHERE object_type = NEW.object_type AND record_id = NEW.record_id) != NEW.expected
|
|
45
|
+
THEN RAISE(ABORT, 'core_moved_meanwhile')
|
|
46
|
+
ELSE RAISE(IGNORE)
|
|
47
|
+
END;
|
|
48
|
+
END;
|
|
49
|
+
|
|
50
|
+
-- Guarded: migrations land out of order (docs/parallel-work.md).
|
|
51
|
+
UPDATE core_meta SET value = '670'
|
|
52
|
+
WHERE key = 'schema_version' AND CAST(value AS INTEGER) < 670;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
-- Migration 0690: drop-ins (stage 31a step 8, ADR 0560): a refund the host owes, and a cap on the
|
|
2
|
+
-- unpaid places a class may have held for it.
|
|
3
|
+
--
|
|
4
|
+
-- 1. A refund owed. A record bought through `sellable.moves` (a drop-in booking) whose order was
|
|
5
|
+
-- paid, entering one of its refund states (an in-time cancel, a class the gym cancels), or paid
|
|
6
|
+
-- for after its place went back (a late payment), owes the buyer their money. The move's own
|
|
7
|
+
-- batch writes one row here: the record and its order. Nothing is asked of the payment provider
|
|
8
|
+
-- in that batch: the minute cron asks the payments gatekeeper afterwards (`order.refundDue`), as
|
|
9
|
+
-- the outbound action `payments.refund`, always reviewed and approved only by a person with
|
|
10
|
+
-- `orders:refund`.
|
|
11
|
+
--
|
|
12
|
+
-- One row per order for a refund of the whole order (a cancel), and one per payment for a payment
|
|
13
|
+
-- owed back on its own (`payment_ref` and `amount`: a second payment on a paid order, or one that
|
|
14
|
+
-- arrived after the order closed), so a duplicate payment is refunded alone and the first never.
|
|
15
|
+
-- `state`: `due` (written by the move); `asking` (the cron claimed it, in its
|
|
16
|
+
-- own statement, before it calls the gatekeeper); `asked` (refunds wait in Approvals; their ids
|
|
17
|
+
-- are `rfd_<this row's id>_<attempt>_<n>`, the provider's idempotency key); `done` (the order is
|
|
18
|
+
-- refunded); `lapsed` (every approval asked for was rejected or expired: staff are told once and
|
|
19
|
+
-- re-ask from the order); `skipped` (nothing could be asked, or the cron could not ask: `note`
|
|
20
|
+
-- says why, and staff were told).
|
|
21
|
+
CREATE TABLE core_sellable_refund_due (
|
|
22
|
+
id TEXT PRIMARY KEY,
|
|
23
|
+
order_id TEXT NOT NULL REFERENCES core_order (id) ON DELETE CASCADE,
|
|
24
|
+
-- A payment owed back on its own: its provider reference and amount (minor units). Null: the
|
|
25
|
+
-- whole order.
|
|
26
|
+
payment_ref TEXT,
|
|
27
|
+
amount INTEGER,
|
|
28
|
+
object_type TEXT NOT NULL,
|
|
29
|
+
record_id TEXT NOT NULL,
|
|
30
|
+
-- The state the record entered (or `late`, a payment after its place went back), and why in
|
|
31
|
+
-- staff's words.
|
|
32
|
+
entered TEXT NOT NULL,
|
|
33
|
+
reason TEXT NOT NULL,
|
|
34
|
+
state TEXT NOT NULL DEFAULT 'due'
|
|
35
|
+
CHECK (state IN ('due', 'asking', 'asked', 'done', 'lapsed', 'skipped')),
|
|
36
|
+
attempt INTEGER NOT NULL DEFAULT 0,
|
|
37
|
+
note TEXT,
|
|
38
|
+
created_at TEXT NOT NULL,
|
|
39
|
+
updated_at TEXT NOT NULL
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
CREATE UNIQUE INDEX core_sellable_refund_due_uq
|
|
43
|
+
ON core_sellable_refund_due (order_id, coalesce(payment_ref, ''));
|
|
44
|
+
|
|
45
|
+
-- The cron's reads: what is due, being asked, or waiting for a person, oldest first.
|
|
46
|
+
CREATE INDEX core_sellable_refund_due_state_idx ON core_sellable_refund_due (state, created_at);
|
|
47
|
+
|
|
48
|
+
-- 2. A cap on unpaid guest holds. A guest's drop-in holds a place while its order is unpaid; a class
|
|
49
|
+
-- may carry at most so many such holds at once, worked out by the host from the class's places and
|
|
50
|
+
-- the extension's setting. The trigger counts every held claim on the record but the waiting
|
|
51
|
+
-- list's; the host passes `expected` as the cap plus the signed-in members' unpaid holds it read,
|
|
52
|
+
-- so members' own drop-ins never turn visitors away. Kind 'held_cap' counts the held
|
|
53
|
+
-- claims on the record after the new one; more than `expected` fails the batch
|
|
54
|
+
-- (`core_holds_capped`). core_write_guard stores nothing, so it is made again with the new kind,
|
|
55
|
+
-- as migrations 0560, 0610 and 0670 did.
|
|
56
|
+
DROP TRIGGER core_write_guard_check;
|
|
57
|
+
DROP TABLE core_write_guard;
|
|
58
|
+
|
|
59
|
+
CREATE TABLE core_write_guard (
|
|
60
|
+
kind TEXT NOT NULL
|
|
61
|
+
CHECK (kind IN ('claimed', 'claimant', 'series', 'full', 'unmoved', 'held_cap')),
|
|
62
|
+
object_type TEXT NOT NULL,
|
|
63
|
+
record_id TEXT NOT NULL,
|
|
64
|
+
expected INTEGER NOT NULL
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
CREATE TRIGGER core_write_guard_check
|
|
68
|
+
BEFORE INSERT ON core_write_guard
|
|
69
|
+
BEGIN
|
|
70
|
+
SELECT CASE
|
|
71
|
+
WHEN NEW.kind = 'claimed' AND coalesce((SELECT held + taken FROM core_capacity
|
|
72
|
+
WHERE object_type = NEW.object_type AND record_id = NEW.record_id), 0) != NEW.expected
|
|
73
|
+
THEN RAISE(ABORT, 'core_recurrence_stale')
|
|
74
|
+
WHEN NEW.kind = 'series' AND coalesce((SELECT version FROM core_recurrence_series
|
|
75
|
+
WHERE object_type = NEW.object_type AND record_id = NEW.record_id), 0) != NEW.expected
|
|
76
|
+
THEN RAISE(ABORT, 'core_recurrence_stale')
|
|
77
|
+
WHEN NEW.kind = 'claimant' AND (SELECT count(*) FROM core_capacity_claim
|
|
78
|
+
WHERE for_type = NEW.object_type AND for_id = NEW.record_id
|
|
79
|
+
AND state IN ('held', 'confirmed')) != NEW.expected
|
|
80
|
+
THEN RAISE(ABORT, 'core_claim_live')
|
|
81
|
+
WHEN NEW.kind = 'full' AND NOT EXISTS (SELECT 1 FROM core_capacity
|
|
82
|
+
WHERE object_type = NEW.object_type AND record_id = NEW.record_id
|
|
83
|
+
AND places IS NOT NULL AND held + taken >= places)
|
|
84
|
+
THEN RAISE(ABORT, 'core_waitlist_not_full')
|
|
85
|
+
WHEN NEW.kind = 'unmoved' AND (SELECT count(*) FROM core_transition_history
|
|
86
|
+
WHERE object_type = NEW.object_type AND record_id = NEW.record_id) != NEW.expected
|
|
87
|
+
THEN RAISE(ABORT, 'core_moved_meanwhile')
|
|
88
|
+
WHEN NEW.kind = 'held_cap' AND (SELECT count(*) FROM core_capacity_claim
|
|
89
|
+
WHERE object_type = NEW.object_type AND record_id = NEW.record_id
|
|
90
|
+
AND state = 'held' AND for_type != 'waitlist') > NEW.expected
|
|
91
|
+
THEN RAISE(ABORT, 'core_holds_capped')
|
|
92
|
+
ELSE RAISE(IGNORE)
|
|
93
|
+
END;
|
|
94
|
+
END;
|
|
95
|
+
|
|
96
|
+
-- Guarded: migrations land out of order (docs/parallel-work.md).
|
|
97
|
+
UPDATE core_meta SET value = '690'
|
|
98
|
+
WHERE key = 'schema_version' AND CAST(value AS INTEGER) < 690;
|