@composable-os/cli 0.0.0-stage → 0.1.0-beta.11
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/LICENSE +109 -0
- package/README.md +24 -2
- package/dist/accounts-UHYLCLEY.js +45 -0
- package/dist/blocks-5IFU25J6.js +233 -0
- package/dist/chunk-2ABSVMGB.js +13 -0
- package/dist/chunk-2IVEVPMY.js +669 -0
- package/dist/chunk-2TWV3SVB.js +349 -0
- package/dist/chunk-2XC5JLBO.js +1931 -0
- package/dist/chunk-324WJXNP.js +320 -0
- package/dist/chunk-5KSXSK7Y.js +47 -0
- package/dist/chunk-6ELZRNUU.js +116 -0
- package/dist/chunk-6UWRT4VM.js +220 -0
- package/dist/chunk-6WGFA2IV.js +643 -0
- package/dist/chunk-6XTU2MTP.js +11278 -0
- package/dist/chunk-7CQGMVDO.js +63 -0
- package/dist/chunk-7D4GKZOX.js +615 -0
- package/dist/chunk-7OGCMQXG.js +284 -0
- package/dist/chunk-DHS2CV2M.js +139 -0
- package/dist/chunk-DU6OIFOU.js +2358 -0
- package/dist/chunk-E4WCYTCT.js +347 -0
- package/dist/chunk-E64SG24J.js +88 -0
- package/dist/chunk-FJIZGS5Q.js +698 -0
- package/dist/chunk-GYTEW66E.js +50 -0
- package/dist/chunk-HDIOVFAZ.js +544 -0
- package/dist/chunk-K34UKWEI.js +298 -0
- package/dist/chunk-KGHA67HG.js +765 -0
- package/dist/chunk-LAAL4YGR.js +365 -0
- package/dist/chunk-LO6WGU5Y.js +26189 -0
- package/dist/chunk-MBIKVRAC.js +1425 -0
- package/dist/chunk-P6UWZ6QQ.js +426 -0
- package/dist/chunk-PDD2ETVF.js +1302 -0
- package/dist/chunk-UB4I2QKR.js +31575 -0
- package/dist/chunk-WHKJGF36.js +2418 -0
- package/dist/chunk-XIDLW3EP.js +15471 -0
- package/dist/chunk-YFTLIEWU.js +504 -0
- package/dist/chunk-YNUZRTPH.js +182 -0
- package/dist/chunk-ZAWES2UD.js +9364 -0
- package/dist/chunk-ZZFWMVJO.js +704 -0
- package/dist/cli-5UNY5G5L.js +136 -0
- package/dist/cli-UYZMVQMR.js +24534 -0
- package/dist/cli.js +25 -0
- package/dist/client-repo-SE4EKG6W.js +55 -0
- package/dist/create.js +25 -0
- package/dist/fields-FTWWMD7N.js +50 -0
- package/dist/grants-LOW6TSWD.js +32 -0
- package/dist/invoke-6KVT6WJI.js +41 -0
- package/dist/moves-E2HKYCTK.js +41 -0
- package/dist/order-U4KZLLSJ.js +19 -0
- package/dist/person-UHLVBVLR.js +67 -0
- package/dist/plan-on-sale-TJPFCNL7.js +26 -0
- package/dist/platform/migrations/0001_init.sql +59 -0
- package/dist/platform/migrations/0002_users_settings.sql +34 -0
- package/dist/platform/migrations/0003_people_organisations.sql +225 -0
- package/dist/platform/migrations/0004_activities_tasks.sql +88 -0
- package/dist/platform/migrations/0005_views_audit.sql +79 -0
- package/dist/platform/migrations/0006_search.sql +223 -0
- package/dist/platform/migrations/0007_crm_views.sql +141 -0
- package/dist/platform/migrations/0008_audit_redaction.sql +116 -0
- package/dist/platform/migrations/0010_approval_queue.sql +90 -0
- package/dist/platform/migrations/0011_connected_apps.sql +36 -0
- package/dist/platform/migrations/0020_extensions.sql +373 -0
- package/dist/platform/migrations/0030_extension_proposals.sql +29 -0
- package/dist/platform/migrations/0050_live_row_indexes.sql +32 -0
- package/dist/platform/migrations/0060_audit_read_counts.sql +31 -0
- package/dist/platform/migrations/0061_audit_retention.sql +95 -0
- package/dist/platform/migrations/0062_run_history_retention.sql +6 -0
- package/dist/platform/migrations/0063_pending_action_compaction.sql +18 -0
- package/dist/platform/migrations/0064_drop_rate_limit.sql +6 -0
- package/dist/platform/migrations/0065_storage_stats.sql +13 -0
- package/dist/platform/migrations/0070_drop_proposals_ext_idx.sql +9 -0
- package/dist/platform/migrations/0080_views_dashboards.sql +46 -0
- package/dist/platform/migrations/0100_stage_history.sql +54 -0
- package/dist/platform/migrations/0110_integrations.sql +103 -0
- package/dist/platform/migrations/0111_email_calendar_sync.sql +137 -0
- package/dist/platform/migrations/0112_sync_item_occurred_at.sql +8 -0
- package/dist/platform/migrations/0130_automations.sql +113 -0
- package/dist/platform/migrations/0131_notifications.sql +29 -0
- package/dist/platform/migrations/0132_automation_runtime.sql +14 -0
- package/dist/platform/migrations/0150_ai_summaries_embeddings.sql +48 -0
- package/dist/platform/migrations/0160_releases.sql +41 -0
- package/dist/platform/migrations/0161_setup_wizard.sql +30 -0
- package/dist/platform/migrations/0170_automation_connections.sql +32 -0
- package/dist/platform/migrations/0171_automation_outbox.sql +23 -0
- package/dist/platform/migrations/0172_notification_delivery.sql +46 -0
- package/dist/platform/migrations/0200_assistant_conversations.sql +25 -0
- package/dist/platform/migrations/0205_policy_adjudicator.sql +61 -0
- package/dist/platform/migrations/0210_daily_digest.sql +33 -0
- package/dist/platform/migrations/0220_entitlements.sql +13 -0
- package/dist/platform/migrations/0221_support_grants.sql +33 -0
- package/dist/platform/migrations/0250_judge.sql +11 -0
- package/dist/platform/migrations/0251_adjudication_judgement.sql +8 -0
- package/dist/platform/migrations/0252_judge_usage.sql +14 -0
- package/dist/platform/migrations/0255_summary_checks.sql +9 -0
- package/dist/platform/migrations/0256_outbound_check.sql +9 -0
- package/dist/platform/migrations/0260_ai_usage.sql +20 -0
- package/dist/platform/migrations/0270_assistant_conversation_refs.sql +29 -0
- package/dist/platform/migrations/0310_assignment_rules.sql +54 -0
- package/dist/platform/migrations/0320_duplicates.sql +41 -0
- package/dist/platform/migrations/0330_erase_completeness.sql +54 -0
- package/dist/platform/migrations/0350_assistant_thread.sql +38 -0
- package/dist/platform/migrations/0351_assistant_model_roles.sql +26 -0
- package/dist/platform/migrations/0352_assistant_memory.sql +74 -0
- package/dist/platform/migrations/0358_ai_cache_observation.sql +24 -0
- package/dist/platform/migrations/0359_ai_compaction_decision.sql +25 -0
- package/dist/platform/migrations/0360_ai_cache_estimate.sql +35 -0
- package/dist/platform/migrations/0361_voice_preferences.sql +27 -0
- package/dist/platform/migrations/0362_voice_usage.sql +17 -0
- package/dist/platform/migrations/0365_routines.sql +38 -0
- package/dist/platform/migrations/0370_approval_execution.sql +20 -0
- package/dist/platform/migrations/0371_agent_jobs.sql +65 -0
- package/dist/platform/migrations/0380_rec_views.sql +94 -0
- package/dist/platform/migrations/0400_customer_audit_actor.sql +142 -0
- package/dist/platform/migrations/0401_customer_accounts.sql +61 -0
- package/dist/platform/migrations/0402_erase_requests.sql +34 -0
- package/dist/platform/migrations/0410_idempotency_keys.sql +45 -0
- package/dist/platform/migrations/0411_device_sessions.sql +33 -0
- package/dist/platform/migrations/0420_transition_history.sql +100 -0
- package/dist/platform/migrations/0421_orders.sql +134 -0
- package/dist/platform/migrations/0422_order_payments.sql +109 -0
- package/dist/platform/migrations/0440_capacity.sql +100 -0
- package/dist/platform/migrations/0441_capacity_views.sql +40 -0
- package/dist/platform/migrations/0450_order_grants.sql +21 -0
- package/dist/platform/migrations/0451_pack_roles.sql +18 -0
- package/dist/platform/migrations/0460_content.sql +59 -0
- package/dist/platform/migrations/0461_media.sql +52 -0
- package/dist/platform/migrations/0470_publish_versions.sql +36 -0
- package/dist/platform/migrations/0471_permission_grants.sql +18 -0
- package/dist/platform/migrations/0490_staff_invites.sql +40 -0
- package/dist/platform/migrations/0491_sign_in_mail_kind.sql +10 -0
- package/dist/platform/migrations/0492_email_confirmation_and_sign_in_confirm.sql +30 -0
- package/dist/platform/migrations/0500_published_media_field.sql +25 -0
- package/dist/platform/migrations/0501_import_keys.sql +23 -0
- package/dist/platform/migrations/0510_video_and_file_media.sql +109 -0
- package/dist/platform/migrations/0516_order_tax.sql +63 -0
- package/dist/platform/migrations/0520_publish_requests.sql +20 -0
- package/dist/platform/migrations/0530_subscriptions.sql +173 -0
- package/dist/platform/migrations/0531_subscription_trials.sql +56 -0
- package/dist/platform/migrations/0532_subscription_offers.sql +80 -0
- package/dist/platform/migrations/0533_allowances.sql +262 -0
- package/dist/platform/migrations/0560_recurring.sql +75 -0
- package/dist/platform/migrations/0580_subscription_grants.sql +21 -0
- package/dist/platform/migrations/0581_once_per_person.sql +34 -0
- package/dist/platform/migrations/0600_tool_actions_ran_at_queue.sql +22 -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/sdk/allowance.ts +522 -0
- package/dist/platform/sdk/automation-check.ts +534 -0
- package/dist/platform/sdk/automation.ts +743 -0
- package/dist/platform/sdk/behaviour.ts +215 -0
- package/dist/platform/sdk/capacity.ts +303 -0
- package/dist/platform/sdk/contract.ts +909 -0
- package/dist/platform/sdk/document.ts +935 -0
- package/dist/platform/sdk/field-types.ts +111 -0
- package/dist/platform/sdk/formula/ast.ts +72 -0
- package/dist/platform/sdk/formula/compile.ts +454 -0
- package/dist/platform/sdk/formula/index.ts +4 -0
- package/dist/platform/sdk/formula/parser.ts +417 -0
- package/dist/platform/sdk/index.ts +36 -0
- package/dist/platform/sdk/manifest.ts +1785 -0
- package/dist/platform/sdk/media.ts +108 -0
- package/dist/platform/sdk/permissions.ts +60 -0
- package/dist/platform/sdk/recurring.ts +321 -0
- package/dist/platform/sdk/renamed.ts +63 -0
- package/dist/platform/sdk/rich-text-fixture.ts +68 -0
- package/dist/platform/sdk/rich-text.ts +221 -0
- package/dist/platform/sdk/runtime.ts +410 -0
- package/dist/platform/sdk/sellable.ts +1138 -0
- package/dist/platform/sdk/slug.ts +25 -0
- package/dist/platform/sdk/states.ts +598 -0
- package/dist/platform/sdk/testing.ts +847 -0
- package/dist/platform/sdk/unique.ts +81 -0
- package/dist/products-2H5DR232.js +11 -0
- package/dist/run-7P4RQALH.js +648 -0
- package/dist/run-PO3W5BFA.js +508 -0
- package/dist/run-ZCGFMEZF.js +309 -0
- package/dist/src-CRO35DYY.js +46 -0
- package/dist/src-I3IJ4NKC.js +354 -0
- package/dist/token-MOJUA2U6.js +70 -0
- package/dist/token-util-TENRN4V7.js +6 -0
- package/dist/visibility-TVXZ67FD.js +41 -0
- package/package.json +33 -4
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
-- Migration 0359: compaction planner decisions for review (stage 17 W2, ADR 0341).
|
|
2
|
+
--
|
|
3
|
+
-- One row per planner run (at the end of a turn, and when the idle alarm fires): the planner's
|
|
4
|
+
-- input verbatim (sizes, prices, the lifetime estimate and its confidence, the person's usage
|
|
5
|
+
-- profile, the rails), its result (both expected costs, the decision and the rule that made it),
|
|
6
|
+
-- and later the actual cost of the turns that followed, so predicted and real cost can be
|
|
7
|
+
-- compared. Sizes, prices and times only; never message content. Kept 180 days.
|
|
8
|
+
CREATE TABLE core_ai_compaction_decision (
|
|
9
|
+
id TEXT PRIMARY KEY NOT NULL,
|
|
10
|
+
at TEXT NOT NULL,
|
|
11
|
+
provider TEXT NOT NULL,
|
|
12
|
+
model TEXT NOT NULL,
|
|
13
|
+
role TEXT NOT NULL,
|
|
14
|
+
decision TEXT NOT NULL CHECK (decision IN ('compact', 'continue')),
|
|
15
|
+
rule TEXT NOT NULL,
|
|
16
|
+
input TEXT NOT NULL CHECK (json_valid(input)),
|
|
17
|
+
result TEXT NOT NULL CHECK (json_valid(result)),
|
|
18
|
+
-- Filled in once the horizon's turns have run.
|
|
19
|
+
actual_turns INTEGER,
|
|
20
|
+
actual_cost REAL,
|
|
21
|
+
actual_at TEXT
|
|
22
|
+
);
|
|
23
|
+
CREATE INDEX core_ai_compaction_decision_at_idx ON core_ai_compaction_decision (at);
|
|
24
|
+
|
|
25
|
+
UPDATE core_meta SET value = '359' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
-- Migration 0360: learned cache lifetimes per provider and model, and their history (stage 17
|
|
2
|
+
-- W2, ADR 0341).
|
|
3
|
+
--
|
|
4
|
+
-- `state` is the learner's state (decayed hit and miss counts per gap bucket and the learned
|
|
5
|
+
-- bucket), updated by each finished turn's bookkeeping write. `version` guards the
|
|
6
|
+
-- read-modify-write: an update that lost a race is dropped, and the observations it carried are
|
|
7
|
+
-- still in core_ai_cache_observation for a replay. Settings → AI shows the estimate read-only.
|
|
8
|
+
-- A deployment is one workspace, so rows are keyed by provider and model only.
|
|
9
|
+
CREATE TABLE core_ai_cache_estimate (
|
|
10
|
+
provider TEXT NOT NULL,
|
|
11
|
+
model TEXT NOT NULL,
|
|
12
|
+
state TEXT NOT NULL CHECK (json_valid(state)),
|
|
13
|
+
learned_seconds REAL,
|
|
14
|
+
published_seconds REAL,
|
|
15
|
+
confidence REAL,
|
|
16
|
+
sample_size REAL NOT NULL DEFAULT 0,
|
|
17
|
+
version INTEGER NOT NULL DEFAULT 0,
|
|
18
|
+
updated_at TEXT NOT NULL,
|
|
19
|
+
PRIMARY KEY (provider, model)
|
|
20
|
+
) WITHOUT ROWID;
|
|
21
|
+
|
|
22
|
+
-- Every change of a learned estimate (rise or fall), appended.
|
|
23
|
+
CREATE TABLE core_ai_cache_estimate_history (
|
|
24
|
+
id INTEGER PRIMARY KEY,
|
|
25
|
+
provider TEXT NOT NULL,
|
|
26
|
+
model TEXT NOT NULL,
|
|
27
|
+
at TEXT NOT NULL,
|
|
28
|
+
from_seconds REAL,
|
|
29
|
+
to_seconds REAL,
|
|
30
|
+
reason TEXT NOT NULL CHECK (reason IN ('rise', 'fall')),
|
|
31
|
+
sample_size REAL NOT NULL
|
|
32
|
+
);
|
|
33
|
+
CREATE INDEX core_ai_cache_estimate_history_at_idx ON core_ai_cache_estimate_history (at);
|
|
34
|
+
|
|
35
|
+
UPDATE core_meta SET value = '360' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
-- Migration 0361: voice preferences (stage 17 W9, ADR 0349).
|
|
2
|
+
--
|
|
3
|
+
-- Voice, speed and how much to read out are per person. How someone talks (push to talk or
|
|
4
|
+
-- hands-free) is per device: `default_mode` is what first setup chose and what every new device
|
|
5
|
+
-- starts with; `core_voice_device.mode` is set only when it changes on that device.
|
|
6
|
+
CREATE TABLE core_voice_prefs (
|
|
7
|
+
user_id TEXT PRIMARY KEY NOT NULL REFERENCES core_user (id),
|
|
8
|
+
voice_id TEXT NOT NULL,
|
|
9
|
+
speed REAL NOT NULL DEFAULT 1,
|
|
10
|
+
default_mode TEXT NOT NULL CHECK (default_mode IN ('push_to_talk', 'hands_free')),
|
|
11
|
+
-- When the person can see the screen: a short version, or everything.
|
|
12
|
+
read_out TEXT NOT NULL DEFAULT 'short' CHECK (read_out IN ('short', 'full')),
|
|
13
|
+
created_at TEXT NOT NULL,
|
|
14
|
+
updated_at TEXT NOT NULL
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
CREATE TABLE core_voice_device (
|
|
18
|
+
user_id TEXT NOT NULL REFERENCES core_user (id),
|
|
19
|
+
-- A random id the browser keeps in local storage.
|
|
20
|
+
device_id TEXT NOT NULL,
|
|
21
|
+
label TEXT NOT NULL,
|
|
22
|
+
mode TEXT CHECK (mode IS NULL OR mode IN ('push_to_talk', 'hands_free')),
|
|
23
|
+
last_seen_at TEXT NOT NULL,
|
|
24
|
+
PRIMARY KEY (user_id, device_id)
|
|
25
|
+
) WITHOUT ROWID;
|
|
26
|
+
|
|
27
|
+
UPDATE core_meta SET value = '361' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
-- Migration 0362: speech usage counted in the workspace (stage 17 W9, ADR 0349's amendment).
|
|
2
|
+
--
|
|
3
|
+
-- AssemblyAI's streaming sockets do not go through AI Gateway, so no gateway log sees them. Each
|
|
4
|
+
-- call's usage is counted here per day, person, role and provider, beside core_ai_usage: seconds
|
|
5
|
+
-- of audio in (`transcribe`), characters out (`speak`). Counts only, never words or audio.
|
|
6
|
+
CREATE TABLE core_voice_usage (
|
|
7
|
+
day TEXT NOT NULL,
|
|
8
|
+
user_id TEXT NOT NULL,
|
|
9
|
+
role TEXT NOT NULL,
|
|
10
|
+
provider TEXT NOT NULL,
|
|
11
|
+
requests INTEGER NOT NULL DEFAULT 0,
|
|
12
|
+
audio_seconds REAL NOT NULL DEFAULT 0,
|
|
13
|
+
characters INTEGER NOT NULL DEFAULT 0,
|
|
14
|
+
PRIMARY KEY (day, user_id, role, provider)
|
|
15
|
+
) WITHOUT ROWID;
|
|
16
|
+
|
|
17
|
+
UPDATE core_meta SET value = '362' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
-- Migration 0365: personal routines (stage 17 W4, ADR 0343).
|
|
2
|
+
--
|
|
3
|
+
-- A routine is a personal automation on the existing engine: a core_automations row with
|
|
4
|
+
-- `scope = 'personal'` and `owner_user_id` set, matched and started by the same dispatcher, under
|
|
5
|
+
-- the same kill switch and rails. Its extension_id is the reserved `routine` (there is no
|
|
6
|
+
-- extension: the Workflow runs its checks and delivery itself). Run history stays in
|
|
7
|
+
-- core_automation_runs. automation.* operations show only `scope = 'org'` rows: a routine belongs
|
|
8
|
+
-- to its owner.
|
|
9
|
+
ALTER TABLE core_automations ADD COLUMN owner_user_id TEXT;
|
|
10
|
+
ALTER TABLE core_automations ADD COLUMN scope TEXT NOT NULL DEFAULT 'org'
|
|
11
|
+
CHECK (scope IN ('org', 'personal'));
|
|
12
|
+
CREATE INDEX core_automations_owner_idx ON core_automations (owner_user_id)
|
|
13
|
+
WHERE owner_user_id IS NOT NULL;
|
|
14
|
+
|
|
15
|
+
-- What only a routine has: the person's words, what it sends and its delivery state. One row per
|
|
16
|
+
-- routine; `definition` is the RoutineDefinition JSON the automation's spec was built from.
|
|
17
|
+
CREATE TABLE core_routine (
|
|
18
|
+
id TEXT PRIMARY KEY NOT NULL CHECK (id GLOB 'rtn_*'),
|
|
19
|
+
automation_id TEXT NOT NULL UNIQUE,
|
|
20
|
+
owner_user_id TEXT NOT NULL,
|
|
21
|
+
name TEXT NOT NULL,
|
|
22
|
+
-- Finishes "I'll …": "send you your open deals with no activity for 14 days".
|
|
23
|
+
what TEXT NOT NULL,
|
|
24
|
+
-- What the person said when they asked for it, and when (the why panel). Null for an offer.
|
|
25
|
+
asked TEXT,
|
|
26
|
+
asked_at TEXT,
|
|
27
|
+
definition TEXT NOT NULL CHECK (json_valid(definition)),
|
|
28
|
+
-- The read-back it came from: pressing Turn on twice makes one routine.
|
|
29
|
+
draft_id TEXT UNIQUE,
|
|
30
|
+
-- Snoozed: runs before this are stopped at their checks.
|
|
31
|
+
paused_until TEXT,
|
|
32
|
+
last_delivered_at TEXT,
|
|
33
|
+
-- The last delivery that failed (the app could not make the message). Cleared by the next one.
|
|
34
|
+
last_error TEXT,
|
|
35
|
+
created_at TEXT NOT NULL,
|
|
36
|
+
updated_at TEXT NOT NULL
|
|
37
|
+
);
|
|
38
|
+
CREATE INDEX core_routine_owner_idx ON core_routine (owner_user_id, created_at);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
-- Migration 0370: approvals by tap, typing or voice (stage 17 W5, ADR 0345).
|
|
2
|
+
--
|
|
3
|
+
-- `execution_id` makes applying idempotent: an approval claims the actions it will apply, in one
|
|
4
|
+
-- statement, before it applies any. A tap and a spoken yes that arrive together both ask, one
|
|
5
|
+
-- claims, and each action applies once. `execution_at` is when it was claimed: a claim left by a
|
|
6
|
+
-- request that died can be taken over after a few minutes, which is safe because each action
|
|
7
|
+
-- applies and changes status in one batch.
|
|
8
|
+
--
|
|
9
|
+
-- `decided_via` is how the person gave the decision. The person's words stay in their thread; they
|
|
10
|
+
-- are not copied here, so an erase has no new place to reach.
|
|
11
|
+
ALTER TABLE core_pending_action ADD COLUMN execution_id TEXT;
|
|
12
|
+
ALTER TABLE core_pending_action ADD COLUMN execution_at TEXT;
|
|
13
|
+
ALTER TABLE core_pending_action ADD COLUMN decided_via TEXT
|
|
14
|
+
CHECK (decided_via IS NULL OR decided_via IN ('tap', 'typed', 'spoken'));
|
|
15
|
+
CREATE INDEX core_pending_action_execution_idx ON core_pending_action (execution_id)
|
|
16
|
+
WHERE execution_id IS NOT NULL;
|
|
17
|
+
|
|
18
|
+
-- Guarded: migrations land out of order (docs/parallel-work.md).
|
|
19
|
+
UPDATE core_meta SET value = '370'
|
|
20
|
+
WHERE key = 'schema_version' AND CAST(value AS INTEGER) < 370;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
-- Migration 0371: agents (stage 17 W5, ADR 0344).
|
|
2
|
+
--
|
|
3
|
+
-- One row per agent the assistant, a routine or a plugin started. In code they are jobs; the
|
|
4
|
+
-- person sees "Agents". The AgentJob Durable Object (`job:<id>`) runs the work and deletes its
|
|
5
|
+
-- storage when it is done; this row is what stays: the card, the limits, the results.
|
|
6
|
+
--
|
|
7
|
+
-- state:
|
|
8
|
+
-- awaiting_confirm the grant is shown to the person first (the judge is off or could not answer)
|
|
9
|
+
-- refused the grant was judged wider than the brief needs
|
|
10
|
+
-- queued waiting for a slot (the per-user and per-workspace limits)
|
|
11
|
+
-- running the object is working
|
|
12
|
+
-- paused stopped at its spend limit, waiting for "Allow $X more"
|
|
13
|
+
-- done, stopped, failed, cancelled finished
|
|
14
|
+
--
|
|
15
|
+
-- `access` is the grant (operations, target, caps, expiry) and `budget` the step, time and spend
|
|
16
|
+
-- limits, both JSON. `spent_microusd` is charged to the starter (`starter_kind`, `starter_id`).
|
|
17
|
+
-- `progress` is what the card shows ({ done, total, now }). `result` is the agent's final words.
|
|
18
|
+
CREATE TABLE core_agent_job (
|
|
19
|
+
id TEXT PRIMARY KEY NOT NULL,
|
|
20
|
+
user_id TEXT NOT NULL REFERENCES core_user (id) ON DELETE CASCADE,
|
|
21
|
+
starter_kind TEXT NOT NULL CHECK (starter_kind IN ('user', 'routine', 'plugin')),
|
|
22
|
+
starter_id TEXT NOT NULL,
|
|
23
|
+
profile TEXT,
|
|
24
|
+
role TEXT NOT NULL,
|
|
25
|
+
title TEXT NOT NULL,
|
|
26
|
+
brief TEXT NOT NULL,
|
|
27
|
+
records TEXT NOT NULL CHECK (json_valid(records)),
|
|
28
|
+
access TEXT NOT NULL CHECK (json_valid(access)),
|
|
29
|
+
budget TEXT NOT NULL CHECK (json_valid(budget)),
|
|
30
|
+
mode TEXT NOT NULL CHECK (mode IN ('awaited', 'background')),
|
|
31
|
+
review_everything INTEGER NOT NULL DEFAULT 0,
|
|
32
|
+
state TEXT NOT NULL CHECK (state IN (
|
|
33
|
+
'awaiting_confirm', 'refused', 'queued', 'running', 'paused',
|
|
34
|
+
'done', 'stopped', 'failed', 'cancelled'
|
|
35
|
+
)),
|
|
36
|
+
-- What the judge said about the grant (labels and probabilities), or why it could not.
|
|
37
|
+
judged TEXT CHECK (judged IS NULL OR json_valid(judged)),
|
|
38
|
+
justification TEXT,
|
|
39
|
+
progress TEXT CHECK (progress IS NULL OR json_valid(progress)),
|
|
40
|
+
steps INTEGER NOT NULL DEFAULT 0,
|
|
41
|
+
spent_microusd INTEGER NOT NULL DEFAULT 0,
|
|
42
|
+
fields_filled INTEGER NOT NULL DEFAULT 0,
|
|
43
|
+
result TEXT,
|
|
44
|
+
error TEXT,
|
|
45
|
+
-- The object has been told to start (its alarm owns the work from then on).
|
|
46
|
+
started_at TEXT,
|
|
47
|
+
finished_at TEXT,
|
|
48
|
+
created_at TEXT NOT NULL,
|
|
49
|
+
updated_at TEXT NOT NULL
|
|
50
|
+
);
|
|
51
|
+
CREATE INDEX core_agent_job_user_idx ON core_agent_job (user_id, state, created_at);
|
|
52
|
+
CREATE INDEX core_agent_job_state_idx ON core_agent_job (state, created_at);
|
|
53
|
+
|
|
54
|
+
-- Which people, organisations (`per_…`, `org_…`) and email addresses (`email:<sha256>`) a job's
|
|
55
|
+
-- brief, records, progress and results name, so an erase finds the rows to redact (ADR 0320).
|
|
56
|
+
CREATE TABLE core_agent_job_refs (
|
|
57
|
+
job_id TEXT NOT NULL REFERENCES core_agent_job (id) ON DELETE CASCADE,
|
|
58
|
+
ref TEXT NOT NULL,
|
|
59
|
+
PRIMARY KEY (job_id, ref)
|
|
60
|
+
) WITHOUT ROWID;
|
|
61
|
+
CREATE INDEX core_agent_job_refs_ref_idx ON core_agent_job_refs (ref);
|
|
62
|
+
|
|
63
|
+
-- Guarded: migrations land out of order (docs/parallel-work.md).
|
|
64
|
+
UPDATE core_meta SET value = '371'
|
|
65
|
+
WHERE key = 'schema_version' AND CAST(value AS INTEGER) < 371;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
-- Migration 0380: the read views are named rec_<object> (stage 20, ADR 0400).
|
|
2
|
+
--
|
|
3
|
+
-- The extension contract no longer says `crm`: the views that query.sql, dashboards and extension
|
|
4
|
+
-- code read were `crm_<plural>` and are now `rec_<object>`, named like the object they read, as
|
|
5
|
+
-- extension objects' views already were (`rec_x_<ext>_<object>`):
|
|
6
|
+
--
|
|
7
|
+
-- crm_people rec_person crm_tasks rec_task
|
|
8
|
+
-- crm_organisations rec_organisation crm_task_links rec_task_link
|
|
9
|
+
-- crm_affiliations rec_affiliation crm_record_tags rec_record_tag
|
|
10
|
+
-- crm_activities rec_activity crm_users rec_user
|
|
11
|
+
-- crm_activity_links rec_activity_link crm_stage_history rec_stage_history
|
|
12
|
+
--
|
|
13
|
+
-- The bodies are unchanged: each is the definition the view had (0007, 0020, 0100, 0111, 0221).
|
|
14
|
+
-- The four object views are `SELECT b.* FROM core_base_<x> b` here; the schema reconciler
|
|
15
|
+
-- regenerates them with the extension side tables joined, and names extension objects' views
|
|
16
|
+
-- rec_x_<ext>_<object>, the next time it runs.
|
|
17
|
+
--
|
|
18
|
+
-- No release was installed under the old names (ADR 0400), so nothing reads them afterwards.
|
|
19
|
+
|
|
20
|
+
DROP VIEW crm_people;
|
|
21
|
+
DROP VIEW crm_organisations;
|
|
22
|
+
DROP VIEW crm_affiliations;
|
|
23
|
+
DROP VIEW crm_activities;
|
|
24
|
+
DROP VIEW crm_activity_links;
|
|
25
|
+
DROP VIEW crm_tasks;
|
|
26
|
+
DROP VIEW crm_task_links;
|
|
27
|
+
DROP VIEW crm_record_tags;
|
|
28
|
+
DROP VIEW crm_users;
|
|
29
|
+
DROP VIEW crm_stage_history;
|
|
30
|
+
|
|
31
|
+
CREATE VIEW rec_user AS
|
|
32
|
+
SELECT u.id, u.name, u.email, u.role, u.image, u.created_at
|
|
33
|
+
FROM core_user u
|
|
34
|
+
WHERE u.kind = 'human' AND u.support_grant_id IS NULL;
|
|
35
|
+
|
|
36
|
+
CREATE VIEW rec_person AS SELECT b.* FROM core_base_people b;
|
|
37
|
+
CREATE VIEW rec_organisation AS SELECT b.* FROM core_base_organisations b;
|
|
38
|
+
CREATE VIEW rec_activity AS SELECT b.* FROM core_base_activities b;
|
|
39
|
+
CREATE VIEW rec_task AS SELECT b.* FROM core_base_tasks b;
|
|
40
|
+
|
|
41
|
+
CREATE VIEW rec_affiliation AS
|
|
42
|
+
SELECT
|
|
43
|
+
affiliation.id,
|
|
44
|
+
affiliation.person_id,
|
|
45
|
+
affiliation.organisation_id,
|
|
46
|
+
affiliation.title,
|
|
47
|
+
affiliation.role,
|
|
48
|
+
affiliation.started_on,
|
|
49
|
+
affiliation.ended_on,
|
|
50
|
+
affiliation.is_current,
|
|
51
|
+
affiliation.is_primary,
|
|
52
|
+
affiliation.created_at,
|
|
53
|
+
affiliation.updated_at
|
|
54
|
+
FROM core_affiliation affiliation
|
|
55
|
+
JOIN core_person p ON p.id = affiliation.person_id AND p.deleted_at IS NULL
|
|
56
|
+
JOIN core_organisation o ON o.id = affiliation.organisation_id AND o.deleted_at IS NULL
|
|
57
|
+
WHERE affiliation.deleted_at IS NULL;
|
|
58
|
+
|
|
59
|
+
CREATE VIEW rec_activity_link AS
|
|
60
|
+
SELECT l.activity_id, l.object_type, l.record_id
|
|
61
|
+
FROM core_activity_links l
|
|
62
|
+
JOIN core_activity a ON a.id = l.activity_id AND a.deleted_at IS NULL AND a.private_to IS NULL;
|
|
63
|
+
|
|
64
|
+
CREATE VIEW rec_task_link AS
|
|
65
|
+
SELECT l.task_id, l.object_type, l.record_id
|
|
66
|
+
FROM core_task_links l
|
|
67
|
+
JOIN core_task t ON t.id = l.task_id AND t.deleted_at IS NULL;
|
|
68
|
+
|
|
69
|
+
CREATE VIEW rec_record_tag AS
|
|
70
|
+
SELECT rt.object_type, rt.record_id, tg.id AS tag_id, tg.name AS tag
|
|
71
|
+
FROM core_record_tags rt
|
|
72
|
+
JOIN core_tags tg ON tg.id = rt.tag_id;
|
|
73
|
+
|
|
74
|
+
CREATE VIEW rec_stage_history AS
|
|
75
|
+
SELECT
|
|
76
|
+
id,
|
|
77
|
+
object_type,
|
|
78
|
+
record_id,
|
|
79
|
+
stage_id,
|
|
80
|
+
group_id,
|
|
81
|
+
stage_type,
|
|
82
|
+
entered_at,
|
|
83
|
+
left_at,
|
|
84
|
+
left_at IS NULL AS is_current,
|
|
85
|
+
round(
|
|
86
|
+
julianday(coalesce(left_at, strftime('%Y-%m-%dT%H:%M:%fZ', 'now'))) - julianday(entered_at),
|
|
87
|
+
4
|
|
88
|
+
) AS days_in_stage,
|
|
89
|
+
entered_by
|
|
90
|
+
FROM core_stage_history;
|
|
91
|
+
|
|
92
|
+
-- Guarded: migrations land out of order (docs/parallel-work.md).
|
|
93
|
+
UPDATE core_meta SET value = '380'
|
|
94
|
+
WHERE key = 'schema_version' AND CAST(value AS INTEGER) < 380;
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
-- Migration 0400: the audit log accepts the actors `customer` and `public` (stage 22, ADR 0402,
|
|
2
|
+
-- ADR 0412).
|
|
3
|
+
--
|
|
4
|
+
-- A customer's write is audited like any write, with actor `customer` and the customer account's
|
|
5
|
+
-- id (cus_…) in user_id. A call with no account has actor `public` and no user_id. Successful
|
|
6
|
+
-- reads by either are counted in core_audit_read_counts, as for non-human staff callers
|
|
7
|
+
-- (ADR 0090).
|
|
8
|
+
--
|
|
9
|
+
-- SQLite cannot alter a CHECK constraint, so both tables are rebuilt with the same rows, as
|
|
10
|
+
-- migration 0020 did for the `extension` actor. This rebuild drops the CHECK on `actor`
|
|
11
|
+
-- altogether: the pipeline validates it in code, so this is the last rebuild an actor needs. core_audit's children (core_audit_changes,
|
|
12
|
+
-- core_audit_redactions) reference it by name; foreign keys are deferred so the swap is checked
|
|
13
|
+
-- once, at commit. The two triggers on core_audit_redactions that name core_audit (one writes
|
|
14
|
+
-- it, one reads it) are dropped first and recreated after, so the rename sees a consistent
|
|
15
|
+
-- schema. The append-only triggers on core_audit go with the table. All are recreated exactly as
|
|
16
|
+
-- migration 0061 left them.
|
|
17
|
+
PRAGMA defer_foreign_keys = ON;
|
|
18
|
+
|
|
19
|
+
DROP TRIGGER core_audit_redactions_apply_audit;
|
|
20
|
+
DROP TRIGGER core_audit_redactions_no_delete;
|
|
21
|
+
|
|
22
|
+
CREATE TABLE core_audit_next (
|
|
23
|
+
id TEXT PRIMARY KEY NOT NULL,
|
|
24
|
+
at TEXT NOT NULL,
|
|
25
|
+
operation TEXT NOT NULL,
|
|
26
|
+
risk TEXT NOT NULL
|
|
27
|
+
CHECK (risk IN ('read', 'write', 'bulk-write', 'destructive', 'schema', 'extension', 'outbound')),
|
|
28
|
+
-- No CHECK: the pipeline validates the actor (ACTORS and OUTSIDE_ACTORS in principals.ts), so
|
|
29
|
+
-- a new actor never needs this table rebuilt again.
|
|
30
|
+
actor TEXT NOT NULL,
|
|
31
|
+
-- The staff user (usr_…), the customer account (cus_…) for actor `customer`, or null.
|
|
32
|
+
user_id TEXT,
|
|
33
|
+
origin TEXT NOT NULL CHECK (json_valid(origin)),
|
|
34
|
+
input TEXT NOT NULL CHECK (json_valid(input)),
|
|
35
|
+
result TEXT CHECK (result IS NULL OR json_valid(result)),
|
|
36
|
+
gate_decision TEXT NOT NULL CHECK (gate_decision IN ('auto', 'review', 'deny')),
|
|
37
|
+
outcome TEXT NOT NULL CHECK (outcome IN ('ok', 'forbidden', 'denied', 'review', 'error')),
|
|
38
|
+
error TEXT CHECK (error IS NULL OR json_valid(error)),
|
|
39
|
+
-- Migration 0010: the pending action an audit row queued or applied.
|
|
40
|
+
pending_action_id TEXT
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
INSERT INTO core_audit_next
|
|
44
|
+
(id, at, operation, risk, actor, user_id, origin, input, result, gate_decision, outcome, error,
|
|
45
|
+
pending_action_id)
|
|
46
|
+
SELECT id, at, operation, risk, actor, user_id, origin, input, result, gate_decision, outcome, error,
|
|
47
|
+
pending_action_id
|
|
48
|
+
FROM core_audit;
|
|
49
|
+
|
|
50
|
+
DROP TABLE core_audit;
|
|
51
|
+
ALTER TABLE core_audit_next RENAME TO core_audit;
|
|
52
|
+
|
|
53
|
+
CREATE INDEX core_audit_at_idx ON core_audit (at, id);
|
|
54
|
+
CREATE INDEX core_audit_user_idx ON core_audit (user_id, at);
|
|
55
|
+
CREATE INDEX core_audit_operation_idx ON core_audit (operation, at);
|
|
56
|
+
CREATE INDEX core_audit_actor_idx ON core_audit (actor, at);
|
|
57
|
+
CREATE INDEX core_audit_pending_action_idx ON core_audit (pending_action_id)
|
|
58
|
+
WHERE pending_action_id IS NOT NULL;
|
|
59
|
+
|
|
60
|
+
CREATE TRIGGER core_audit_no_update BEFORE UPDATE ON core_audit
|
|
61
|
+
WHEN NOT (
|
|
62
|
+
EXISTS (SELECT 1 FROM core_audit_redactions r WHERE r.audit_id = OLD.id)
|
|
63
|
+
AND NEW.id IS OLD.id
|
|
64
|
+
AND NEW.at IS OLD.at
|
|
65
|
+
AND NEW.operation IS OLD.operation
|
|
66
|
+
AND NEW.risk IS OLD.risk
|
|
67
|
+
AND NEW.actor IS OLD.actor
|
|
68
|
+
AND NEW.user_id IS OLD.user_id
|
|
69
|
+
AND NEW.origin IS OLD.origin
|
|
70
|
+
AND NEW.gate_decision IS OLD.gate_decision
|
|
71
|
+
AND NEW.outcome IS OLD.outcome
|
|
72
|
+
AND NEW.input IS '"[erased]"'
|
|
73
|
+
AND NEW.result IS (CASE WHEN OLD.result IS NULL THEN NULL ELSE '"[erased]"' END)
|
|
74
|
+
AND NEW.error IS (CASE WHEN OLD.error IS NULL THEN NULL
|
|
75
|
+
ELSE json_object('code', json_extract(OLD.error, '$.code'), 'message', '[erased]') END)
|
|
76
|
+
)
|
|
77
|
+
BEGIN
|
|
78
|
+
SELECT RAISE(ABORT, 'core_audit is append-only');
|
|
79
|
+
END;
|
|
80
|
+
|
|
81
|
+
CREATE TRIGGER core_audit_no_delete BEFORE DELETE ON core_audit
|
|
82
|
+
WHEN NOT (
|
|
83
|
+
(SELECT json_extract(value, '$.years') FROM core_settings WHERE key = 'audit_retention')
|
|
84
|
+
IS NOT NULL
|
|
85
|
+
AND OLD.at < coalesce((SELECT max(cutoff) FROM core_audit_purges), '')
|
|
86
|
+
)
|
|
87
|
+
BEGIN
|
|
88
|
+
SELECT RAISE(ABORT, 'core_audit is append-only');
|
|
89
|
+
END;
|
|
90
|
+
|
|
91
|
+
CREATE TRIGGER core_audit_redactions_apply_audit AFTER INSERT ON core_audit_redactions
|
|
92
|
+
WHEN NEW.audit_id IS NOT NULL
|
|
93
|
+
BEGIN
|
|
94
|
+
UPDATE core_audit SET
|
|
95
|
+
input = '"[erased]"',
|
|
96
|
+
result = CASE WHEN result IS NULL THEN NULL ELSE '"[erased]"' END,
|
|
97
|
+
error = CASE WHEN error IS NULL THEN NULL
|
|
98
|
+
ELSE json_object('code', json_extract(error, '$.code'), 'message', '[erased]') END
|
|
99
|
+
WHERE id = NEW.audit_id;
|
|
100
|
+
END;
|
|
101
|
+
|
|
102
|
+
CREATE TRIGGER core_audit_redactions_no_delete BEFORE DELETE ON core_audit_redactions
|
|
103
|
+
WHEN NOT (
|
|
104
|
+
(SELECT json_extract(value, '$.years') FROM core_settings WHERE key = 'audit_retention')
|
|
105
|
+
IS NOT NULL
|
|
106
|
+
AND coalesce(
|
|
107
|
+
(SELECT a.at FROM core_audit a WHERE a.id = OLD.audit_id),
|
|
108
|
+
(SELECT c.at FROM core_audit_changes c WHERE c.id = OLD.change_id)
|
|
109
|
+
) < coalesce((SELECT max(cutoff) FROM core_audit_purges), '')
|
|
110
|
+
)
|
|
111
|
+
BEGIN
|
|
112
|
+
SELECT RAISE(ABORT, 'core_audit_redactions is append-only');
|
|
113
|
+
END;
|
|
114
|
+
|
|
115
|
+
-- Read counts: the same two actors.
|
|
116
|
+
CREATE TABLE core_audit_read_counts_next (
|
|
117
|
+
-- The UTC hour, 'YYYY-MM-DDTHH:00:00.000Z'.
|
|
118
|
+
hour TEXT NOT NULL,
|
|
119
|
+
actor TEXT NOT NULL,
|
|
120
|
+
-- The staff user, the customer account (cus_…) for actor `customer`, '' for actor `public`.
|
|
121
|
+
user_id TEXT NOT NULL,
|
|
122
|
+
-- Who exactly, within the actor: the connected app (cap_…) for MCP, the extension id, the
|
|
123
|
+
-- automation id, else the MCP client id, else ''.
|
|
124
|
+
caller TEXT NOT NULL DEFAULT '',
|
|
125
|
+
operation TEXT NOT NULL,
|
|
126
|
+
count INTEGER NOT NULL DEFAULT 0,
|
|
127
|
+
-- How many of them saw the session's simulated pending changes (ADR 0032).
|
|
128
|
+
simulated INTEGER NOT NULL DEFAULT 0,
|
|
129
|
+
first_at TEXT NOT NULL,
|
|
130
|
+
last_at TEXT NOT NULL,
|
|
131
|
+
PRIMARY KEY (hour, actor, user_id, caller, operation)
|
|
132
|
+
) WITHOUT ROWID;
|
|
133
|
+
|
|
134
|
+
INSERT INTO core_audit_read_counts_next
|
|
135
|
+
(hour, actor, user_id, caller, operation, count, simulated, first_at, last_at)
|
|
136
|
+
SELECT hour, actor, user_id, caller, operation, count, simulated, first_at, last_at
|
|
137
|
+
FROM core_audit_read_counts;
|
|
138
|
+
|
|
139
|
+
DROP TABLE core_audit_read_counts;
|
|
140
|
+
ALTER TABLE core_audit_read_counts_next RENAME TO core_audit_read_counts;
|
|
141
|
+
|
|
142
|
+
CREATE INDEX core_audit_read_counts_user_idx ON core_audit_read_counts (user_id, hour);
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
-- Migration 0401: customer accounts (stage 22 step 4, ADR 0402).
|
|
2
|
+
--
|
|
3
|
+
-- A customer is a Person who can sign in. Customers sign in through a second Better Auth
|
|
4
|
+
-- configuration (packages/auth/src/customer-auth.ts) with its own tables, cookie and secret, so a
|
|
5
|
+
-- customer session is never in core_session and a staff session never in core_customer_session.
|
|
6
|
+
-- A customer is never a core_user row and never holds a role.
|
|
7
|
+
--
|
|
8
|
+
-- Column names are snake_case; packages/auth maps Better Auth's camelCase fields onto them.
|
|
9
|
+
-- No table here stores a client address: Better Auth's ip_address and user_agent session columns
|
|
10
|
+
-- are left out on purpose, and the customer configuration strips both before a session is written.
|
|
11
|
+
|
|
12
|
+
CREATE TABLE core_customer (
|
|
13
|
+
-- cus_… (ids.ts).
|
|
14
|
+
id TEXT PRIMARY KEY NOT NULL,
|
|
15
|
+
-- The Person the account is linked to. Null until the first sign-in links it, and while the
|
|
16
|
+
-- address matches several people (link_state 'needs_merge'). One account per Person.
|
|
17
|
+
-- Erasing the Person deletes the account (and, through it, its sessions).
|
|
18
|
+
person_id TEXT REFERENCES core_person (id) ON DELETE CASCADE,
|
|
19
|
+
-- The verified sign-in address, lower-cased and trimmed.
|
|
20
|
+
email TEXT NOT NULL UNIQUE CHECK (email = lower(trim(email)) AND email <> ''),
|
|
21
|
+
email_verified INTEGER NOT NULL DEFAULT 0 CHECK (email_verified IN (0, 1)),
|
|
22
|
+
-- 'disabled': cannot sign in, and an existing session resolves to no customer.
|
|
23
|
+
status TEXT NOT NULL DEFAULT 'active' CHECK (status IN ('active', 'disabled')),
|
|
24
|
+
-- 'needs_merge': the address matched several people at sign-in; staff merge them first.
|
|
25
|
+
link_state TEXT NOT NULL DEFAULT 'linked' CHECK (link_state IN ('linked', 'needs_merge')),
|
|
26
|
+
created_at DATE NOT NULL,
|
|
27
|
+
updated_at DATE NOT NULL,
|
|
28
|
+
last_sign_in_at TEXT
|
|
29
|
+
);
|
|
30
|
+
CREATE UNIQUE INDEX core_customer_person_uq ON core_customer (person_id) WHERE person_id IS NOT NULL;
|
|
31
|
+
|
|
32
|
+
CREATE TABLE core_customer_session (
|
|
33
|
+
id TEXT PRIMARY KEY NOT NULL,
|
|
34
|
+
customer_id TEXT NOT NULL REFERENCES core_customer (id) ON DELETE CASCADE,
|
|
35
|
+
token TEXT NOT NULL UNIQUE,
|
|
36
|
+
expires_at DATE NOT NULL,
|
|
37
|
+
created_at DATE NOT NULL,
|
|
38
|
+
updated_at DATE NOT NULL
|
|
39
|
+
);
|
|
40
|
+
CREATE INDEX core_customer_session_customer_idx ON core_customer_session (customer_id);
|
|
41
|
+
|
|
42
|
+
-- One-time sign-in codes, stored hashed. The identifier names the address the code was sent to.
|
|
43
|
+
CREATE TABLE core_customer_verification (
|
|
44
|
+
id TEXT PRIMARY KEY NOT NULL,
|
|
45
|
+
identifier TEXT NOT NULL,
|
|
46
|
+
value TEXT NOT NULL,
|
|
47
|
+
expires_at DATE NOT NULL,
|
|
48
|
+
created_at DATE NOT NULL,
|
|
49
|
+
updated_at DATE NOT NULL
|
|
50
|
+
);
|
|
51
|
+
CREATE INDEX core_customer_verification_identifier_idx ON core_customer_verification (identifier);
|
|
52
|
+
|
|
53
|
+
-- Addresses staff invited (customer.invite). With sign-up `invite_only`, a code is sent only to an
|
|
54
|
+
-- invited address or one that already has an account.
|
|
55
|
+
CREATE TABLE core_customer_invite (
|
|
56
|
+
email TEXT PRIMARY KEY NOT NULL CHECK (email = lower(trim(email)) AND email <> ''),
|
|
57
|
+
invited_by TEXT NOT NULL,
|
|
58
|
+
invited_at TEXT NOT NULL
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
UPDATE core_meta SET value = '401' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
-- Migration 0402: erase requests (stage 22 step 7, ADR 0402).
|
|
2
|
+
--
|
|
3
|
+
-- A customer who deletes their account (me.deleteAccount) is disabled and signed out at once, and
|
|
4
|
+
-- an erase request names their Person for staff to action by a due date: erase the person
|
|
5
|
+
-- (person.erase closes it as 'erased') or decline with a reason (eraseRequest.decline). A request
|
|
6
|
+
-- past its due date notifies admins at most once a day (last_notified_at).
|
|
7
|
+
--
|
|
8
|
+
-- Erasing the Person deletes their requests with everything else about them: only the audit trail
|
|
9
|
+
-- remains. No client address is stored.
|
|
10
|
+
CREATE TABLE core_erase_request (
|
|
11
|
+
-- erq_… (ids.ts).
|
|
12
|
+
id TEXT PRIMARY KEY NOT NULL,
|
|
13
|
+
person_id TEXT NOT NULL REFERENCES core_person (id) ON DELETE CASCADE,
|
|
14
|
+
-- The account that asked, while it exists.
|
|
15
|
+
customer_id TEXT REFERENCES core_customer (id) ON DELETE SET NULL,
|
|
16
|
+
requested_at TEXT NOT NULL,
|
|
17
|
+
due_at TEXT NOT NULL,
|
|
18
|
+
status TEXT NOT NULL DEFAULT 'open' CHECK (status IN ('open', 'erased', 'declined')),
|
|
19
|
+
-- Why staff declined (a record the org must keep). Emailed to the person.
|
|
20
|
+
decline_reason TEXT,
|
|
21
|
+
closed_at TEXT,
|
|
22
|
+
-- The staff user who closed it.
|
|
23
|
+
closed_by TEXT,
|
|
24
|
+
-- When admins were last told the request is overdue.
|
|
25
|
+
last_notified_at TEXT,
|
|
26
|
+
CHECK ((status = 'open') = (closed_at IS NULL)),
|
|
27
|
+
CHECK (status <> 'declined' OR decline_reason IS NOT NULL)
|
|
28
|
+
);
|
|
29
|
+
-- One open request per Person.
|
|
30
|
+
CREATE UNIQUE INDEX core_erase_request_open_uq ON core_erase_request (person_id) WHERE status = 'open';
|
|
31
|
+
CREATE INDEX core_erase_request_due_idx ON core_erase_request (status, due_at);
|
|
32
|
+
CREATE INDEX core_erase_request_customer_idx ON core_erase_request (customer_id);
|
|
33
|
+
|
|
34
|
+
UPDATE core_meta SET value = '402' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
-- Migration 0410: idempotency keys for the HTTP surface (stage 23, ADR 0403, ADR 0416).
|
|
2
|
+
--
|
|
3
|
+
-- Every write over POST /api/v1/op/<name> carries an Idempotency-Key. A key is the caller's own:
|
|
4
|
+
-- its scope is the principal (`staff:<user id>`, `customer:<account id>`, or `public`).
|
|
5
|
+
--
|
|
6
|
+
-- core_idempotency_key is the record of a write that committed: it is inserted in the write's own
|
|
7
|
+
-- D1 batch, so the key and the write commit together or not at all, and a second batch for the
|
|
8
|
+
-- same key fails on the primary key and applies nothing. It holds the operation, a hash of the
|
|
9
|
+
-- input and the response the caller was sent. A response computed after the commit (an
|
|
10
|
+
-- operation that reads its output back) is filled in just after it.
|
|
11
|
+
--
|
|
12
|
+
-- core_idempotency_claim marks a key whose call is running, so the same key sent twice at once
|
|
13
|
+
-- runs the handler once: the second call waits for the first's response. A claim is removed when
|
|
14
|
+
-- its call ends; one left by a Worker that died is taken over after a minute.
|
|
15
|
+
--
|
|
16
|
+
-- Both are purged by the daily maintenance cron 24 hours after they were made. No client address
|
|
17
|
+
-- is stored.
|
|
18
|
+
CREATE TABLE core_idempotency_key (
|
|
19
|
+
scope TEXT NOT NULL,
|
|
20
|
+
idempotency_key TEXT NOT NULL,
|
|
21
|
+
operation TEXT NOT NULL,
|
|
22
|
+
-- SHA-256 of the operation name and the input as sent, in hex.
|
|
23
|
+
input_hash TEXT NOT NULL,
|
|
24
|
+
-- The claim that committed it, so its own call can fill in a late response.
|
|
25
|
+
claim TEXT NOT NULL,
|
|
26
|
+
-- The HTTP status and JSON body the caller was sent; NULL until a late response is filled in.
|
|
27
|
+
status INTEGER,
|
|
28
|
+
response TEXT,
|
|
29
|
+
created_at TEXT NOT NULL,
|
|
30
|
+
PRIMARY KEY (scope, idempotency_key)
|
|
31
|
+
) WITHOUT ROWID;
|
|
32
|
+
CREATE INDEX core_idempotency_key_created_idx ON core_idempotency_key (created_at);
|
|
33
|
+
|
|
34
|
+
CREATE TABLE core_idempotency_claim (
|
|
35
|
+
scope TEXT NOT NULL,
|
|
36
|
+
idempotency_key TEXT NOT NULL,
|
|
37
|
+
operation TEXT NOT NULL,
|
|
38
|
+
input_hash TEXT NOT NULL,
|
|
39
|
+
claim TEXT NOT NULL,
|
|
40
|
+
claimed_at TEXT NOT NULL,
|
|
41
|
+
PRIMARY KEY (scope, idempotency_key)
|
|
42
|
+
) WITHOUT ROWID;
|
|
43
|
+
CREATE INDEX core_idempotency_claim_claimed_idx ON core_idempotency_claim (claimed_at);
|
|
44
|
+
|
|
45
|
+
UPDATE core_meta SET value = '410' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
-- Migration 0411: sessions for native apps on the HTTP surface (stage 23, ADR 0403, ADR 0419).
|
|
2
|
+
--
|
|
3
|
+
-- A phone or a TV exchanges its sign-in for an access token that lasts minutes and a refresh
|
|
4
|
+
-- token. Only SHA-256 hashes of the tokens are stored. Every refresh rotates both; the refresh
|
|
5
|
+
-- hashes already used are kept on the row, and presenting one again ends the session (the row is
|
|
6
|
+
-- deleted). A session unused for the period in the `device_session_idle_days` setting (90 days by
|
|
7
|
+
-- default) is ended when it is next presented.
|
|
8
|
+
--
|
|
9
|
+
-- A session is one audience's: staff (user_id) or a customer (customer_id), never both. Deleting
|
|
10
|
+
-- the user or the customer account deletes its sessions. No client address is stored.
|
|
11
|
+
CREATE TABLE core_device_session (
|
|
12
|
+
-- dvs_… (ids.ts).
|
|
13
|
+
id TEXT PRIMARY KEY NOT NULL,
|
|
14
|
+
audience TEXT NOT NULL CHECK (audience IN ('staff', 'customer')),
|
|
15
|
+
user_id TEXT REFERENCES core_user (id) ON DELETE CASCADE,
|
|
16
|
+
customer_id TEXT REFERENCES core_customer (id) ON DELETE CASCADE,
|
|
17
|
+
-- What the app called the device ("Ada's iPhone"), so a person can tell their sessions apart.
|
|
18
|
+
device_name TEXT NOT NULL,
|
|
19
|
+
access_hash TEXT NOT NULL,
|
|
20
|
+
access_expires_at TEXT NOT NULL,
|
|
21
|
+
refresh_hash TEXT NOT NULL,
|
|
22
|
+
-- JSON array of refresh hashes this session has already rotated past.
|
|
23
|
+
used_refresh_hashes TEXT NOT NULL DEFAULT '[]',
|
|
24
|
+
created_at TEXT NOT NULL,
|
|
25
|
+
last_used_at TEXT NOT NULL,
|
|
26
|
+
CHECK ((audience = 'staff') = (user_id IS NOT NULL)),
|
|
27
|
+
CHECK ((audience = 'customer') = (customer_id IS NOT NULL))
|
|
28
|
+
);
|
|
29
|
+
CREATE UNIQUE INDEX core_device_session_access_uq ON core_device_session (access_hash);
|
|
30
|
+
CREATE INDEX core_device_session_user_idx ON core_device_session (user_id);
|
|
31
|
+
CREATE INDEX core_device_session_customer_idx ON core_device_session (customer_id);
|
|
32
|
+
|
|
33
|
+
UPDATE core_meta SET value = '411' WHERE key = 'schema_version';
|