@composable-os/cli 0.0.0-stage → 0.1.0-beta.8
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/blocks-DEELKGDC.js +233 -0
- package/dist/chunk-2ABSVMGB.js +13 -0
- package/dist/chunk-2S7375SC.js +802 -0
- package/dist/chunk-5KSXSK7Y.js +47 -0
- package/dist/chunk-6UWRT4VM.js +220 -0
- package/dist/chunk-E5JLTLRM.js +50 -0
- package/dist/chunk-G3ORKXVP.js +1178 -0
- package/dist/chunk-HDIOVFAZ.js +544 -0
- package/dist/chunk-KGHA67HG.js +765 -0
- package/dist/chunk-KOKYDJ7Z.js +1423 -0
- package/dist/chunk-KTXGEXTY.js +358 -0
- package/dist/chunk-LTQDLCP7.js +16486 -0
- package/dist/chunk-MAXLUQKB.js +1287 -0
- package/dist/chunk-STJZJIRA.js +11378 -0
- package/dist/chunk-X6I2LWB3.js +24319 -0
- package/dist/chunk-XDDBLYKW.js +29154 -0
- package/dist/chunk-ZRWF6QZS.js +2357 -0
- package/dist/cli-BRSACHSG.js +31393 -0
- package/dist/cli-DTMGNDXN.js +121 -0
- package/dist/cli.js +25 -0
- package/dist/client-repo-ZVZ6KW5S.js +55 -0
- package/dist/create.js +25 -0
- package/dist/fields-64BQJA62.js +48 -0
- package/dist/invoke-NHHOLLF6.js +26 -0
- package/dist/person-WMWRF2HV.js +58 -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/0520_publish_requests.sql +20 -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 +112 -0
- package/dist/platform/sdk/contract.ts +766 -0
- package/dist/platform/sdk/document.ts +788 -0
- package/dist/platform/sdk/field-types.ts +106 -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 +33 -0
- package/dist/platform/sdk/manifest.ts +1484 -0
- package/dist/platform/sdk/media.ts +46 -0
- package/dist/platform/sdk/permissions.ts +60 -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 +173 -0
- package/dist/platform/sdk/runtime.ts +410 -0
- package/dist/platform/sdk/sellable.ts +396 -0
- package/dist/platform/sdk/slug.ts +25 -0
- package/dist/platform/sdk/states.ts +162 -0
- package/dist/platform/sdk/testing.ts +836 -0
- package/dist/products-2H5DR232.js +11 -0
- package/dist/run-4JNFLYXV.js +847 -0
- package/dist/src-G6OF5SKW.js +31 -0
- package/dist/src-J27WXNLY.js +270 -0
- package/dist/token-MOJUA2U6.js +70 -0
- package/dist/token-util-TENRN4V7.js +6 -0
- package/package.json +33 -4
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
-- Migration 0150: in-app AI, first half (stage 7a; ADRs 0150-0155).
|
|
2
|
+
--
|
|
3
|
+
-- core_ai_summary: cached `summarise` output (record summaries, meeting prep, activity
|
|
4
|
+
-- one-liners, change-set summaries). One row per (kind, subject). `input_hash` is a SHA-256 of
|
|
5
|
+
-- the exact input the model saw plus the model id, so any change to the inputs (a new note, an
|
|
6
|
+
-- edited field, a different model) makes the row stale; nothing has to invalidate it. `sources`
|
|
7
|
+
-- lists the record ids the input was built from, so an erase (ADR 0019) can delete every
|
|
8
|
+
-- summary that mentioned the subject.
|
|
9
|
+
-- core_embedding: one row per embedded record: the hash of the text that was embedded and the
|
|
10
|
+
-- model. A record is re-embedded only when that hash changes (cost audit U9). Ids and hashes
|
|
11
|
+
-- only; the vectors live in Vectorize.
|
|
12
|
+
-- core_embedding_queue: records whose text may have changed, written in the same batch as the
|
|
13
|
+
-- change by the pipeline (and by erase). Drained in batches after the commit and by the cron
|
|
14
|
+
-- (ADR 0154). Stage 5's event queue can replace the producer side without touching the drain.
|
|
15
|
+
|
|
16
|
+
CREATE TABLE core_ai_summary (
|
|
17
|
+
kind TEXT NOT NULL CHECK (kind IN ('record', 'meeting', 'activity', 'changeset')),
|
|
18
|
+
subject_type TEXT NOT NULL,
|
|
19
|
+
subject_id TEXT NOT NULL,
|
|
20
|
+
input_hash TEXT NOT NULL,
|
|
21
|
+
text TEXT NOT NULL,
|
|
22
|
+
model TEXT NOT NULL,
|
|
23
|
+
sources TEXT NOT NULL DEFAULT '[]' CHECK (json_valid(sources)),
|
|
24
|
+
created_at TEXT NOT NULL,
|
|
25
|
+
created_by TEXT,
|
|
26
|
+
PRIMARY KEY (kind, subject_type, subject_id)
|
|
27
|
+
) WITHOUT ROWID;
|
|
28
|
+
|
|
29
|
+
CREATE TABLE core_embedding (
|
|
30
|
+
object_type TEXT NOT NULL,
|
|
31
|
+
record_id TEXT NOT NULL,
|
|
32
|
+
vector_id TEXT NOT NULL,
|
|
33
|
+
text_hash TEXT NOT NULL,
|
|
34
|
+
model TEXT NOT NULL,
|
|
35
|
+
embedded_at TEXT NOT NULL,
|
|
36
|
+
PRIMARY KEY (object_type, record_id)
|
|
37
|
+
) WITHOUT ROWID;
|
|
38
|
+
|
|
39
|
+
CREATE TABLE core_embedding_queue (
|
|
40
|
+
object_type TEXT NOT NULL,
|
|
41
|
+
record_id TEXT NOT NULL,
|
|
42
|
+
queued_at TEXT NOT NULL,
|
|
43
|
+
attempts INTEGER NOT NULL DEFAULT 0,
|
|
44
|
+
PRIMARY KEY (object_type, record_id)
|
|
45
|
+
) WITHOUT ROWID;
|
|
46
|
+
CREATE INDEX core_embedding_queue_at_idx ON core_embedding_queue (attempts, queued_at);
|
|
47
|
+
|
|
48
|
+
UPDATE core_meta SET value = '150' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
-- Stage 8: release state and update history (ADR 0160, ADR 0164).
|
|
2
|
+
--
|
|
3
|
+
-- core_install: what the installer chose (hostname, identity adapter, installed gatekeepers,
|
|
4
|
+
-- resource ids, var overrides), as JSON under key 'deployment', written by `create-crm` and
|
|
5
|
+
-- read by `crm upgrade` and the self-updater so every deploy of this deployment is the same.
|
|
6
|
+
-- It holds no secrets.
|
|
7
|
+
CREATE TABLE core_install (
|
|
8
|
+
key TEXT PRIMARY KEY NOT NULL,
|
|
9
|
+
value TEXT NOT NULL CHECK (json_valid(value)),
|
|
10
|
+
updated_at TEXT NOT NULL
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
-- Every update and rollback, from Settings → Updates (surface 'ui') or the CLI ('cli'), with the
|
|
14
|
+
-- D1 Time Travel bookmark taken before it changed anything. Rollback restores that bookmark.
|
|
15
|
+
CREATE TABLE core_update_runs (
|
|
16
|
+
id TEXT PRIMARY KEY NOT NULL,
|
|
17
|
+
kind TEXT NOT NULL CHECK (kind IN ('update', 'rollback')),
|
|
18
|
+
from_version TEXT,
|
|
19
|
+
to_version TEXT NOT NULL,
|
|
20
|
+
status TEXT NOT NULL CHECK (status IN ('running', 'succeeded', 'rolled_back', 'failed')),
|
|
21
|
+
step TEXT,
|
|
22
|
+
bookmark TEXT,
|
|
23
|
+
bundle_digest TEXT,
|
|
24
|
+
preflight TEXT CHECK (preflight IS NULL OR json_valid(preflight)),
|
|
25
|
+
error TEXT,
|
|
26
|
+
started_by TEXT REFERENCES core_user (id) ON DELETE SET NULL,
|
|
27
|
+
surface TEXT NOT NULL CHECK (surface IN ('ui', 'cli')),
|
|
28
|
+
started_at TEXT NOT NULL,
|
|
29
|
+
finished_at TEXT
|
|
30
|
+
);
|
|
31
|
+
CREATE INDEX core_update_runs_started_idx ON core_update_runs (started_at);
|
|
32
|
+
|
|
33
|
+
-- Public GitHub Releases, cached per channel so Settings → Updates stays inside GitHub's
|
|
34
|
+
-- anonymous rate limit (ADR 0166).
|
|
35
|
+
CREATE TABLE core_release_cache (
|
|
36
|
+
channel TEXT PRIMARY KEY NOT NULL CHECK (channel IN ('stable', 'beta')),
|
|
37
|
+
releases TEXT NOT NULL CHECK (json_valid(releases)),
|
|
38
|
+
fetched_at TEXT NOT NULL
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
UPDATE core_meta SET value = '160' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
-- Stage 8: the first-run setup wizard (ADR 0167).
|
|
2
|
+
--
|
|
3
|
+
-- core_setup: one row. A fresh install (no human users yet when migrations run) starts
|
|
4
|
+
-- 'pending', so the first admin is taken to /setup; a deployment upgraded into stage 8 already
|
|
5
|
+
-- has users and starts 'skipped' (Settings → General can still open the wizard). `step` and
|
|
6
|
+
-- `data` make it resumable.
|
|
7
|
+
CREATE TABLE core_setup (
|
|
8
|
+
id INTEGER PRIMARY KEY NOT NULL CHECK (id = 1),
|
|
9
|
+
status TEXT NOT NULL CHECK (status IN ('pending', 'in_progress', 'completed', 'skipped')),
|
|
10
|
+
step TEXT NOT NULL DEFAULT 'admin',
|
|
11
|
+
data TEXT NOT NULL DEFAULT '{}' CHECK (json_valid(data)),
|
|
12
|
+
updated_at TEXT NOT NULL,
|
|
13
|
+
updated_by TEXT REFERENCES core_user (id) ON DELETE SET NULL,
|
|
14
|
+
completed_at TEXT
|
|
15
|
+
);
|
|
16
|
+
INSERT INTO core_setup (id, status, step, updated_at)
|
|
17
|
+
SELECT 1,
|
|
18
|
+
CASE WHEN EXISTS (SELECT 1 FROM core_user WHERE kind = 'human') THEN 'skipped' ELSE 'pending' END,
|
|
19
|
+
'admin',
|
|
20
|
+
strftime('%Y-%m-%dT%H:%M:%fZ', 'now');
|
|
21
|
+
|
|
22
|
+
-- Records created by "Install sample data", so "Remove sample data" deletes exactly those.
|
|
23
|
+
CREATE TABLE core_sample_records (
|
|
24
|
+
object_type TEXT NOT NULL,
|
|
25
|
+
record_id TEXT NOT NULL,
|
|
26
|
+
created_at TEXT NOT NULL,
|
|
27
|
+
PRIMARY KEY (object_type, record_id)
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
UPDATE core_meta SET value = '161' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
-- Migration 0170: automation run-as (stage 6b, ADR 0051, ADR 0170).
|
|
2
|
+
--
|
|
3
|
+
-- An automation declares the connections it needs (`connections: [{ id, gatekeeper, purpose }]`).
|
|
4
|
+
-- A person binds each declared slot to a connection they own or to an org connection; that row
|
|
5
|
+
-- is their consent, kept after it is revoked (revoked_at) so the automation page and the audit
|
|
6
|
+
-- log can show who allowed what and when. Steps reach the bound connection as its owner.
|
|
7
|
+
|
|
8
|
+
CREATE TABLE core_automation_binding (
|
|
9
|
+
automation_id TEXT NOT NULL,
|
|
10
|
+
-- The declared connection id (`connections[].id`).
|
|
11
|
+
slot TEXT NOT NULL,
|
|
12
|
+
gatekeeper TEXT NOT NULL,
|
|
13
|
+
purpose TEXT NOT NULL,
|
|
14
|
+
connection_id TEXT NOT NULL,
|
|
15
|
+
-- Who consented, and when.
|
|
16
|
+
bound_by TEXT NOT NULL,
|
|
17
|
+
bound_at TEXT NOT NULL,
|
|
18
|
+
-- Set when the consent was withdrawn, the connection was disconnected or expired, or its owner
|
|
19
|
+
-- was deactivated. A revoked binding no longer lets steps reach the connection.
|
|
20
|
+
revoked_at TEXT,
|
|
21
|
+
revoked_by TEXT,
|
|
22
|
+
revoke_reason TEXT,
|
|
23
|
+
PRIMARY KEY (automation_id, slot)
|
|
24
|
+
) WITHOUT ROWID;
|
|
25
|
+
-- Revocation: which live bindings use a connection.
|
|
26
|
+
CREATE INDEX core_automation_binding_connection_idx
|
|
27
|
+
ON core_automation_binding (connection_id) WHERE revoked_at IS NULL;
|
|
28
|
+
|
|
29
|
+
-- Deactivated people cannot sign in or act; automations bound to their connections pause.
|
|
30
|
+
ALTER TABLE core_user ADD COLUMN deactivated_at TEXT;
|
|
31
|
+
|
|
32
|
+
UPDATE core_meta SET value = '170' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
-- Migration 0171: the automation events outbox (stage 6b, ADR 0171).
|
|
2
|
+
--
|
|
3
|
+
-- An operation that changes records writes its automation events here in the same D1 batch as
|
|
4
|
+
-- the change itself, then sends them to the queue after commit and deletes the row. A row that is
|
|
5
|
+
-- still here (the send failed, or the Worker died before it) is retried by crm-runner's minute
|
|
6
|
+
-- cron with backoff. Reads never write here. Runs are idempotent per event id, so a resend after
|
|
7
|
+
-- a lost delete starts nothing twice.
|
|
8
|
+
|
|
9
|
+
CREATE TABLE core_automation_outbox (
|
|
10
|
+
id TEXT PRIMARY KEY NOT NULL,
|
|
11
|
+
-- JSON array of AutomationQueueMessage (one operation's events, at most ~900 KB a row).
|
|
12
|
+
messages TEXT NOT NULL CHECK (json_valid(messages)),
|
|
13
|
+
attempts INTEGER NOT NULL DEFAULT 0,
|
|
14
|
+
-- When the cron may take it: a minute after it was written (the post-commit send goes first),
|
|
15
|
+
-- then with backoff after each failed attempt.
|
|
16
|
+
next_at TEXT NOT NULL,
|
|
17
|
+
last_error TEXT,
|
|
18
|
+
created_at TEXT NOT NULL
|
|
19
|
+
);
|
|
20
|
+
-- No secondary index: rows live for milliseconds, so the table is nearly always empty and the
|
|
21
|
+
-- cron reads at most one page of it in primary-key (time) order.
|
|
22
|
+
|
|
23
|
+
UPDATE core_meta SET value = '171' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
-- Migration 0172: notification delivery (stage 6b, ADR 0029, ADR 0132, ADR 0172).
|
|
2
|
+
--
|
|
3
|
+
-- In-app notifications (core_notifications) are unchanged. People choose, per notification type,
|
|
4
|
+
-- whether it also goes to them by email or Slack DM, and whether they get a daily digest. Admins
|
|
5
|
+
-- choose the org connections email and Slack go out through, the escalation delay for unread
|
|
6
|
+
-- approvals, and channel routes (deal won → #sales). crm-runner's minute cron delivers.
|
|
7
|
+
|
|
8
|
+
-- One row per person who changed a default. `channels`: JSON { "<type>": ["email", "slack"] }.
|
|
9
|
+
CREATE TABLE core_notification_preference (
|
|
10
|
+
user_id TEXT PRIMARY KEY NOT NULL,
|
|
11
|
+
channels TEXT NOT NULL DEFAULT '{}' CHECK (json_valid(channels)),
|
|
12
|
+
digest INTEGER NOT NULL DEFAULT 0 CHECK (digest IN (0, 1)),
|
|
13
|
+
updated_at TEXT NOT NULL
|
|
14
|
+
) WITHOUT ROWID;
|
|
15
|
+
-- The digest job reads the people who asked for it.
|
|
16
|
+
CREATE INDEX core_notification_preference_digest_idx
|
|
17
|
+
ON core_notification_preference (user_id) WHERE digest = 1;
|
|
18
|
+
|
|
19
|
+
-- Every external delivery attempt, keyed so a repeated cron tick or a redelivered event never
|
|
20
|
+
-- sends twice: `n:<notificationId>:<channel>`, `esc:<notificationId>:<channel>`,
|
|
21
|
+
-- `digest:<date>:<userId>`, `route:<eventId>:<routeId>:<recordId>`.
|
|
22
|
+
CREATE TABLE core_notification_delivery (
|
|
23
|
+
key TEXT PRIMARY KEY NOT NULL,
|
|
24
|
+
kind TEXT NOT NULL CHECK (kind IN ('notification', 'escalation', 'digest', 'route')),
|
|
25
|
+
channel TEXT NOT NULL CHECK (channel IN ('email', 'slack')),
|
|
26
|
+
user_id TEXT,
|
|
27
|
+
-- sending: claimed; sent: applied; pending: waiting for approval as an outbound action;
|
|
28
|
+
-- failed / skipped: not delivered (detail says why).
|
|
29
|
+
status TEXT NOT NULL CHECK (status IN ('sending', 'sent', 'pending', 'failed', 'skipped')),
|
|
30
|
+
detail TEXT,
|
|
31
|
+
created_at TEXT NOT NULL
|
|
32
|
+
) WITHOUT ROWID;
|
|
33
|
+
CREATE INDEX core_notification_delivery_created_idx ON core_notification_delivery (created_at);
|
|
34
|
+
|
|
35
|
+
-- Admin settings: where email and Slack go out, escalation and the digest hour.
|
|
36
|
+
INSERT OR IGNORE INTO core_settings (key, value, updated_at)
|
|
37
|
+
VALUES (
|
|
38
|
+
'notification_delivery',
|
|
39
|
+
'{"email":null,"slack":null,"escalationMinutes":30,"escalationChannels":["email"],"digestHour":8}',
|
|
40
|
+
strftime('%Y-%m-%dT%H:%M:%fZ', 'now')
|
|
41
|
+
);
|
|
42
|
+
-- Admin channel routes: [{ id, label, object, event, channel, enabled }].
|
|
43
|
+
INSERT OR IGNORE INTO core_settings (key, value, updated_at)
|
|
44
|
+
VALUES ('notification_routes', '[]', strftime('%Y-%m-%dT%H:%M:%fZ', 'now'));
|
|
45
|
+
|
|
46
|
+
UPDATE core_meta SET value = '172' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
-- Migration 0200: the in-app assistant's conversation index (stage 7b, ADR 0030, ADR 0200).
|
|
2
|
+
--
|
|
3
|
+
-- Each conversation's history, streaming state and turn bookkeeping live in its own Durable
|
|
4
|
+
-- Object (AssistantConversation, one per conversation, SQLite storage). D1 keeps only the list a
|
|
5
|
+
-- person sees on /assistant: one small row per conversation, written when the conversation starts
|
|
6
|
+
-- and once per finished turn (never per token or per tool call). The id (asc_…) is also the
|
|
7
|
+
-- assistant's MCP session: its pending actions group by it and only it sees them simulated.
|
|
8
|
+
CREATE TABLE core_assistant_conversation (
|
|
9
|
+
id TEXT PRIMARY KEY NOT NULL,
|
|
10
|
+
user_id TEXT NOT NULL,
|
|
11
|
+
title TEXT NOT NULL,
|
|
12
|
+
-- Where it was started: JSON { path, record?, selection? } of the first turn, for the list.
|
|
13
|
+
context TEXT CHECK (context IS NULL OR json_valid(context)),
|
|
14
|
+
turns INTEGER NOT NULL DEFAULT 0,
|
|
15
|
+
-- The last reply's first line, for the list.
|
|
16
|
+
preview TEXT,
|
|
17
|
+
created_at TEXT NOT NULL,
|
|
18
|
+
updated_at TEXT NOT NULL,
|
|
19
|
+
deleted_at TEXT
|
|
20
|
+
);
|
|
21
|
+
-- /assistant lists a person's conversations, newest first.
|
|
22
|
+
CREATE INDEX core_assistant_conversation_user_idx
|
|
23
|
+
ON core_assistant_conversation (user_id, updated_at DESC) WHERE deleted_at IS NULL;
|
|
24
|
+
|
|
25
|
+
UPDATE core_meta SET value = '200' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
-- Migration 0205: the policy adjudicator (stage 7b, ADR 0011, ADR 0031, ADR 0204).
|
|
2
|
+
--
|
|
3
|
+
-- The adjudicator judges pending actions the gate routed to `review` against the org's written
|
|
4
|
+
-- policy, using the `review` model role. Its settings (mode off / shadow / active, confidence
|
|
5
|
+
-- threshold) are the core_settings key `adjudicator`; missing means off.
|
|
6
|
+
|
|
7
|
+
-- Why the gate routed a pending action to review, so the adjudicator knows what it may approve:
|
|
8
|
+
-- policy: the org's preset said review.
|
|
9
|
+
-- floor: the deploy-time floor (APPROVAL_FLOOR) pinned it to review. Never auto-approved.
|
|
10
|
+
-- always: the operation always waits for a person (extension installs). Never auto-approved.
|
|
11
|
+
-- dependency: the preset said auto, but it refers to a record still pending creation.
|
|
12
|
+
-- Null for actions queued before this migration and for outbound items: never auto-approved.
|
|
13
|
+
ALTER TABLE core_pending_action ADD COLUMN review_source TEXT
|
|
14
|
+
CHECK (review_source IS NULL OR review_source IN ('policy', 'floor', 'always', 'dependency'));
|
|
15
|
+
|
|
16
|
+
-- The written policy: plain text only human admins can edit (adjudicator.setPolicy). Each edit
|
|
17
|
+
-- adds a version; the highest is in force, and every verdict names the version and hash it
|
|
18
|
+
-- judged against.
|
|
19
|
+
CREATE TABLE core_written_policy (
|
|
20
|
+
version INTEGER PRIMARY KEY NOT NULL,
|
|
21
|
+
text TEXT NOT NULL,
|
|
22
|
+
-- SHA-256 of the text, hex.
|
|
23
|
+
hash TEXT NOT NULL,
|
|
24
|
+
created_at TEXT NOT NULL,
|
|
25
|
+
created_by TEXT NOT NULL
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
-- One verdict per pending action. Visible to human approvers only (never to the actor).
|
|
29
|
+
CREATE TABLE core_adjudication (
|
|
30
|
+
id TEXT PRIMARY KEY NOT NULL,
|
|
31
|
+
action_id TEXT NOT NULL,
|
|
32
|
+
judged_at TEXT NOT NULL,
|
|
33
|
+
mode TEXT NOT NULL CHECK (mode IN ('shadow', 'active')),
|
|
34
|
+
verdict TEXT NOT NULL CHECK (verdict IN ('approve', 'deny', 'escalate')),
|
|
35
|
+
confidence REAL NOT NULL CHECK (confidence >= 0 AND confidence <= 1),
|
|
36
|
+
-- The reviewer's reason (or why there is no real verdict: an invalid reply, a model error).
|
|
37
|
+
reason TEXT NOT NULL,
|
|
38
|
+
-- recorded: shadow mode, nothing done. approved: applied as the original actor.
|
|
39
|
+
-- apply_failed: approved, but applying failed (the action is marked failed).
|
|
40
|
+
-- escalated: active mode, left for a person (note says why).
|
|
41
|
+
outcome TEXT NOT NULL CHECK (outcome IN ('recorded', 'approved', 'apply_failed', 'escalated')),
|
|
42
|
+
-- 1 when the adjudicator changed the action (approved or apply_failed).
|
|
43
|
+
acted INTEGER NOT NULL DEFAULT 0 CHECK (acted IN (0, 1)),
|
|
44
|
+
-- Why an active-mode verdict was not acted on: deny, escalate, low_confidence, floor, always,
|
|
45
|
+
-- risk, dependency, unknown_source. Also invalid (no valid reply) and error (the model failed).
|
|
46
|
+
note TEXT,
|
|
47
|
+
provider TEXT,
|
|
48
|
+
model TEXT,
|
|
49
|
+
policy_version INTEGER,
|
|
50
|
+
policy_hash TEXT,
|
|
51
|
+
threshold REAL NOT NULL,
|
|
52
|
+
-- JSON { code, message } when the model failed or replied invalidly.
|
|
53
|
+
error TEXT CHECK (error IS NULL OR json_valid(error)),
|
|
54
|
+
audit_id TEXT NOT NULL
|
|
55
|
+
);
|
|
56
|
+
-- One verdict per action (claims it, so the post-commit run and the cron sweep never both act).
|
|
57
|
+
CREATE UNIQUE INDEX core_adjudication_action_idx ON core_adjudication (action_id);
|
|
58
|
+
-- The agreement-rate view reads verdicts by period.
|
|
59
|
+
CREATE INDEX core_adjudication_judged_idx ON core_adjudication (judged_at);
|
|
60
|
+
|
|
61
|
+
UPDATE core_meta SET value = '205' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
-- Migration 0210: the daily digest in the app (stage 7b, ADR 0206, amends ADR 0172).
|
|
2
|
+
--
|
|
3
|
+
-- The digest now also arrives as an in-app notification (type `digest`), on for everyone unless
|
|
4
|
+
-- they turn it off; the email digest keeps its own preference (`digest`, off by default). Its
|
|
5
|
+
-- content reads indexes that already exist: core_audit_at_idx and core_audit_changes_audit_idx
|
|
6
|
+
-- (changes on my records), core_task_assignee_idx (tasks due) and core_notifications_user_idx.
|
|
7
|
+
|
|
8
|
+
-- A person's in-app digest preference. Rows written before this keep the default: on.
|
|
9
|
+
ALTER TABLE core_notification_preference
|
|
10
|
+
ADD COLUMN digest_in_app INTEGER NOT NULL DEFAULT 1 CHECK (digest_in_app IN (0, 1));
|
|
11
|
+
|
|
12
|
+
-- The digest pass walks every person (by primary key, at most 50 a tick), not only those with the
|
|
13
|
+
-- email digest on, so the partial index on `digest = 1` is never read any more.
|
|
14
|
+
DROP INDEX IF EXISTS core_notification_preference_digest_idx;
|
|
15
|
+
|
|
16
|
+
-- The ledger's channel gains `inApp`: a digest that went to the app only is still claimed under
|
|
17
|
+
-- `digest:<date>:<userId>`, so it is written (and its model overview asked for) at most once.
|
|
18
|
+
CREATE TABLE core_notification_delivery_new (
|
|
19
|
+
key TEXT PRIMARY KEY NOT NULL,
|
|
20
|
+
kind TEXT NOT NULL CHECK (kind IN ('notification', 'escalation', 'digest', 'route')),
|
|
21
|
+
channel TEXT NOT NULL CHECK (channel IN ('email', 'slack', 'inApp')),
|
|
22
|
+
user_id TEXT,
|
|
23
|
+
status TEXT NOT NULL CHECK (status IN ('sending', 'sent', 'pending', 'failed', 'skipped')),
|
|
24
|
+
detail TEXT,
|
|
25
|
+
created_at TEXT NOT NULL
|
|
26
|
+
) WITHOUT ROWID;
|
|
27
|
+
INSERT INTO core_notification_delivery_new (key, kind, channel, user_id, status, detail, created_at)
|
|
28
|
+
SELECT key, kind, channel, user_id, status, detail, created_at FROM core_notification_delivery;
|
|
29
|
+
DROP TABLE core_notification_delivery;
|
|
30
|
+
ALTER TABLE core_notification_delivery_new RENAME TO core_notification_delivery;
|
|
31
|
+
CREATE INDEX core_notification_delivery_created_idx ON core_notification_delivery (created_at);
|
|
32
|
+
|
|
33
|
+
UPDATE core_meta SET value = '210' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
-- Stage 10 (SaaS): plan entitlements (ADR 0211).
|
|
2
|
+
--
|
|
3
|
+
-- One row, key 'plan', written only by the hosted control plane through the D1 REST API. Its value
|
|
4
|
+
-- is JSON { plan, maxUsers, maxRecords, platformAi, updatedAt }. No row (a self-hosted install)
|
|
5
|
+
-- means no limits at all. Nothing in the deployment writes this table: no operation, no UI and no
|
|
6
|
+
-- AI path (identity and policy are not AI-configurable).
|
|
7
|
+
CREATE TABLE core_entitlements (
|
|
8
|
+
key TEXT PRIMARY KEY NOT NULL,
|
|
9
|
+
value TEXT NOT NULL,
|
|
10
|
+
updated_at TEXT NOT NULL
|
|
11
|
+
) WITHOUT ROWID;
|
|
12
|
+
|
|
13
|
+
UPDATE core_meta SET value = '220' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
-- Stage 10 (SaaS): customer-approved, time-limited support access without impersonation
|
|
2
|
+
-- (ADR 0212).
|
|
3
|
+
--
|
|
4
|
+
-- The hosted control plane inserts a grant with status 'requested' (and may set 'revoked'),
|
|
5
|
+
-- everything else happens here through support.grant.* operations, so it is in the audit log.
|
|
6
|
+
-- Approving creates a support user (core_user.support_grant_id = the grant): its own identity,
|
|
7
|
+
-- never a customer's account. Support users never count against the plan's user limit and are
|
|
8
|
+
-- not listed in crm_users.
|
|
9
|
+
CREATE TABLE core_support_grants (
|
|
10
|
+
id TEXT PRIMARY KEY NOT NULL,
|
|
11
|
+
staff_email TEXT NOT NULL,
|
|
12
|
+
reason TEXT NOT NULL,
|
|
13
|
+
role TEXT NOT NULL CHECK (role IN ('admin', 'member', 'viewer')),
|
|
14
|
+
requested_minutes INTEGER NOT NULL,
|
|
15
|
+
status TEXT NOT NULL CHECK (status IN ('requested', 'approved', 'denied', 'revoked')),
|
|
16
|
+
requested_at TEXT NOT NULL,
|
|
17
|
+
decided_at TEXT,
|
|
18
|
+
decided_by TEXT,
|
|
19
|
+
expires_at TEXT,
|
|
20
|
+
user_id TEXT
|
|
21
|
+
) WITHOUT ROWID;
|
|
22
|
+
CREATE INDEX core_support_grants_status_idx ON core_support_grants (status);
|
|
23
|
+
|
|
24
|
+
ALTER TABLE core_user ADD COLUMN support_grant_id TEXT;
|
|
25
|
+
|
|
26
|
+
-- Support users are not people of the organisation: keep them out of user lists and pickers.
|
|
27
|
+
DROP VIEW crm_users;
|
|
28
|
+
CREATE VIEW crm_users AS
|
|
29
|
+
SELECT u.id, u.name, u.email, u.role, u.image, u.created_at
|
|
30
|
+
FROM core_user u
|
|
31
|
+
WHERE u.kind = 'human' AND u.support_grant_id IS NULL;
|
|
32
|
+
|
|
33
|
+
UPDATE core_meta SET value = '221' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
-- Stage 11 (Jev as the typed judge, ADR 0230): the authoring.intent check of an extension
|
|
2
|
+
-- proposal, stored with the proposal row in the batch that already writes it (no new write per
|
|
3
|
+
-- judge call). JSON: { status, requestSource, request, automations: [{ id, findings, faults }],
|
|
4
|
+
-- model, checkedAt }, or NULL when nothing was checked (no request, no automation changed, or the
|
|
5
|
+
-- judge is off). Labels and probabilities only, never the judge's evidence beyond the request.
|
|
6
|
+
--
|
|
7
|
+
-- The judge's per-placement switches live in core_settings (key judge_settings) and need no
|
|
8
|
+
-- schema change.
|
|
9
|
+
ALTER TABLE core_extension_proposals ADD COLUMN intent_check TEXT;
|
|
10
|
+
|
|
11
|
+
UPDATE core_meta SET value = '250' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
-- Stage 11, placement adjudicator.policy (ADR 0233): the Jev reviewer's raw answer on the verdict
|
|
2
|
+
-- row, written in the batch that already writes the verdict (no new write per judge call).
|
|
3
|
+
-- JSON: { rules, breaks: { probabilities, p, rule }, allowedBy: { probabilities, p, rule },
|
|
4
|
+
-- thresholds, inputTokens } or { unavailable }. Labels and probabilities only, never the
|
|
5
|
+
-- evidence. NULL for a verdict of the LLM reviewer.
|
|
6
|
+
ALTER TABLE core_adjudication ADD COLUMN judgement TEXT;
|
|
7
|
+
|
|
8
|
+
UPDATE core_meta SET value = '251' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
-- Stage 11, Settings → AI's judge spend (ADR 0234): calls and input tokens per day and placement,
|
|
2
|
+
-- counted by a statement added to the batch a placement already writes (the adjudicator's verdict
|
|
3
|
+
-- batch, the extension proposal batch), never by a write of its own per call. Jev charges for
|
|
4
|
+
-- input tokens only, so spend is input_tokens × JEV_PRICE. Counts only: never a request, an
|
|
5
|
+
-- answer or a key.
|
|
6
|
+
CREATE TABLE core_judge_usage (
|
|
7
|
+
day TEXT NOT NULL,
|
|
8
|
+
placement TEXT NOT NULL,
|
|
9
|
+
calls INTEGER NOT NULL DEFAULT 0,
|
|
10
|
+
input_tokens INTEGER NOT NULL DEFAULT 0,
|
|
11
|
+
PRIMARY KEY (day, placement)
|
|
12
|
+
) WITHOUT ROWID;
|
|
13
|
+
|
|
14
|
+
UPDATE core_meta SET value = '252' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
-- Stage 11, placement summary.statements (ADR 0237): the judge's check of a generated AI summary,
|
|
2
|
+
-- stored with the cached row in the statement that already writes it (no new write per judge
|
|
3
|
+
-- call). JSON: { status: "checked" | "unchecked", statements, removed: [{ index, verdict, fault }],
|
|
4
|
+
-- faults, reason, model, checkedAt }, or NULL when the judge did not run (no key, switched off, or
|
|
5
|
+
-- generated before stage 11). Labels and numbers only: never the removed statements or the facts.
|
|
6
|
+
-- A cached summary is never checked again, and reading one never asks the judge.
|
|
7
|
+
ALTER TABLE core_ai_summary ADD COLUMN checks TEXT;
|
|
8
|
+
|
|
9
|
+
UPDATE core_meta SET value = '255' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
-- Stage 11, placement outbound.message (ADR 0238): the judge's check of a model-written outbound
|
|
2
|
+
-- message (email, chat post), stored on its pending action in the batch that already inserts it.
|
|
3
|
+
-- JSON: { status: "checked" | "unchecked", turnedToReview, findings: [{ part, fault, label }],
|
|
4
|
+
-- recipients, reason, model, checkedAt }, or NULL when the message was not checked (a person's own
|
|
5
|
+
-- action, notification delivery, no key, or the placement switched off). Labels, numbers and the
|
|
6
|
+
-- part of the message each finding is about; never the facts the message was checked against.
|
|
7
|
+
ALTER TABLE core_pending_action ADD COLUMN outbound_check TEXT;
|
|
8
|
+
|
|
9
|
+
UPDATE core_meta SET value = '256' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
-- Hosted AI (ADR 0213 amendment): model usage counted in the workspace itself.
|
|
2
|
+
--
|
|
3
|
+
-- On a hosted deployment the customer's own keys are called directly at the provider, not through
|
|
4
|
+
-- any gateway we can read, so the deployment counts every model call here: requests and tokens per
|
|
5
|
+
-- day, role and provider, and whether the call was Platform AI (billed to the plan) or the
|
|
6
|
+
-- customer's own key (never billed). Settings → AI shows it. Never a prompt, a reply or a key.
|
|
7
|
+
-- Self-hosted deployments read usage from their own AI Gateway instead (ADR 0152) and leave this
|
|
8
|
+
-- table empty.
|
|
9
|
+
CREATE TABLE core_ai_usage (
|
|
10
|
+
day TEXT NOT NULL,
|
|
11
|
+
role TEXT NOT NULL,
|
|
12
|
+
provider TEXT NOT NULL,
|
|
13
|
+
billed INTEGER NOT NULL,
|
|
14
|
+
requests INTEGER NOT NULL DEFAULT 0,
|
|
15
|
+
tokens_in INTEGER NOT NULL DEFAULT 0,
|
|
16
|
+
tokens_out INTEGER NOT NULL DEFAULT 0,
|
|
17
|
+
PRIMARY KEY (day, role, provider)
|
|
18
|
+
) WITHOUT ROWID;
|
|
19
|
+
|
|
20
|
+
UPDATE core_meta SET value = '260' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
-- Migration 0270: which records each assistant conversation referenced (ADR 0019 and ADR 0200
|
|
2
|
+
-- amendments, 2026-11-05).
|
|
3
|
+
--
|
|
4
|
+
-- A conversation's history lives in its Durable Object, out of reach of a D1 query, so an erase
|
|
5
|
+
-- could not find the conversations that hold a person's details. This index says which ones do:
|
|
6
|
+
-- one row per conversation and referenced person or organisation id (`per_…`, `org_…`), or email
|
|
7
|
+
-- address as `email:<sha256 of the lower-cased address>`. The conversation object sends a turn's
|
|
8
|
+
-- refs with the once-per-turn `assistant.finishTurn` (no extra D1 request, never per token or tool
|
|
9
|
+
-- call). An erase scrubs the conversations listed for the subject and deletes those rows.
|
|
10
|
+
CREATE TABLE core_assistant_conversation_refs (
|
|
11
|
+
conversation_id TEXT NOT NULL REFERENCES core_assistant_conversation (id),
|
|
12
|
+
ref TEXT NOT NULL,
|
|
13
|
+
PRIMARY KEY (conversation_id, ref)
|
|
14
|
+
) WITHOUT ROWID;
|
|
15
|
+
-- An erase looks conversations up by ref.
|
|
16
|
+
CREATE INDEX core_assistant_conversation_refs_ref_idx
|
|
17
|
+
ON core_assistant_conversation_refs (ref);
|
|
18
|
+
|
|
19
|
+
-- Conversations started before this migration: index the record and selection their context
|
|
20
|
+
-- names now. Their messages are indexed by their next turn (the object sends its whole history's
|
|
21
|
+
-- refs once).
|
|
22
|
+
INSERT OR IGNORE INTO core_assistant_conversation_refs (conversation_id, ref)
|
|
23
|
+
SELECT c.id, t.value
|
|
24
|
+
FROM core_assistant_conversation c, json_tree(c.context) t
|
|
25
|
+
WHERE c.context IS NOT NULL
|
|
26
|
+
AND t.type = 'text'
|
|
27
|
+
AND (t.value GLOB 'per_*' OR t.value GLOB 'org_*');
|
|
28
|
+
|
|
29
|
+
UPDATE core_meta SET value = '270' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
-- Migration 0310: assignment rules (stage 15, ADR 0246) and admin-editable select options.
|
|
2
|
+
--
|
|
3
|
+
-- core_assignment_rule: per object (`person`, `organisation`, or an extension object that
|
|
4
|
+
-- declares an owner field), ordered by position; the first enabled rule whose conditions all
|
|
5
|
+
-- hold sets the owner of a record created without one. `conditions` is a JSON array of
|
|
6
|
+
-- { field, op, value, via? } (via: a relation field, to test the related record's field);
|
|
7
|
+
-- `user_ids` a JSON array of user ids: the rotation for round-robin, or the one user.
|
|
8
|
+
CREATE TABLE core_assignment_rule (
|
|
9
|
+
id TEXT PRIMARY KEY NOT NULL,
|
|
10
|
+
object_type TEXT NOT NULL,
|
|
11
|
+
name TEXT NOT NULL,
|
|
12
|
+
position INTEGER NOT NULL,
|
|
13
|
+
enabled INTEGER NOT NULL DEFAULT 1 CHECK (enabled IN (0, 1)),
|
|
14
|
+
conditions TEXT NOT NULL DEFAULT '[]',
|
|
15
|
+
method TEXT NOT NULL CHECK (method IN ('roundRobin', 'user')),
|
|
16
|
+
user_ids TEXT NOT NULL DEFAULT '[]',
|
|
17
|
+
created_at TEXT NOT NULL,
|
|
18
|
+
created_by TEXT NOT NULL,
|
|
19
|
+
updated_at TEXT NOT NULL,
|
|
20
|
+
updated_by TEXT NOT NULL
|
|
21
|
+
);
|
|
22
|
+
CREATE INDEX core_assignment_rule_object_idx ON core_assignment_rule (object_type, position);
|
|
23
|
+
|
|
24
|
+
-- Round-robin state: the rotation index of the next record. A create reads it, picks the owner
|
|
25
|
+
-- and advances it in its own batch, guarded by the value it read: a concurrent create makes the
|
|
26
|
+
-- guard write -1, the CHECK fails the batch and the pipeline retries the call (ADR 0246).
|
|
27
|
+
CREATE TABLE core_assignment_state (
|
|
28
|
+
rule_id TEXT PRIMARY KEY NOT NULL,
|
|
29
|
+
next_index INTEGER NOT NULL DEFAULT 0
|
|
30
|
+
CONSTRAINT core_assignment_state_conflict CHECK (next_index >= 0),
|
|
31
|
+
updated_at TEXT
|
|
32
|
+
) WITHOUT ROWID;
|
|
33
|
+
|
|
34
|
+
-- The owner used when no rule matches, per object. A missing row or a null user: no owner.
|
|
35
|
+
CREATE TABLE core_assignment_fallback (
|
|
36
|
+
object_type TEXT PRIMARY KEY NOT NULL,
|
|
37
|
+
user_id TEXT,
|
|
38
|
+
updated_at TEXT NOT NULL,
|
|
39
|
+
updated_by TEXT NOT NULL
|
|
40
|
+
) WITHOUT ROWID;
|
|
41
|
+
|
|
42
|
+
-- Admin-edited options of extension select fields declared with `editableOptions` (ADR 0246
|
|
43
|
+
-- amendment): replaces the declared options in the field registry. `options` is a JSON array of
|
|
44
|
+
-- { value, label, color? }; options the extension marks `fixed` are always kept.
|
|
45
|
+
CREATE TABLE core_field_options (
|
|
46
|
+
object_type TEXT NOT NULL,
|
|
47
|
+
field TEXT NOT NULL,
|
|
48
|
+
options TEXT NOT NULL,
|
|
49
|
+
updated_at TEXT NOT NULL,
|
|
50
|
+
updated_by TEXT NOT NULL,
|
|
51
|
+
PRIMARY KEY (object_type, field)
|
|
52
|
+
) WITHOUT ROWID;
|
|
53
|
+
|
|
54
|
+
UPDATE core_meta SET value = '310' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
-- Migration 0320: duplicates (stage 16, ADR 0247).
|
|
2
|
+
--
|
|
3
|
+
-- name_key: the normalised name (packages/core/src/duplicates/normalise.ts), written by code on
|
|
4
|
+
-- every write that sets a name. Normalisation (legal forms, diacritics, name order) cannot be done
|
|
5
|
+
-- in SQL, so existing rows are filled by a one-off chunked backfill in ros-runner, tracked in
|
|
6
|
+
-- core_settings ('duplicate_scan'); the scan waits for it.
|
|
7
|
+
ALTER TABLE core_person ADD COLUMN name_key TEXT;
|
|
8
|
+
ALTER TABLE core_organisation ADD COLUMN name_key TEXT;
|
|
9
|
+
CREATE INDEX core_person_name_key_idx ON core_person (name_key, id) WHERE deleted_at IS NULL;
|
|
10
|
+
CREATE INDEX core_organisation_name_key_idx ON core_organisation (name_key, id)
|
|
11
|
+
WHERE deleted_at IS NULL;
|
|
12
|
+
|
|
13
|
+
-- The incremental scan reads records changed since its cursor, so its reads follow the number of
|
|
14
|
+
-- changed records, not the table size. The backfill walks rows without a key by id.
|
|
15
|
+
CREATE INDEX core_person_updated_idx ON core_person (updated_at, id);
|
|
16
|
+
CREATE INDEX core_organisation_updated_idx ON core_organisation (updated_at, id);
|
|
17
|
+
CREATE INDEX core_person_no_name_key_idx ON core_person (id) WHERE name_key IS NULL;
|
|
18
|
+
CREATE INDEX core_organisation_no_name_key_idx ON core_organisation (id) WHERE name_key IS NULL;
|
|
19
|
+
|
|
20
|
+
-- Likely duplicates found by the scan, one row per pair (a_id < b_id). rules is a JSON array of
|
|
21
|
+
-- rule ids; details holds what each rule matched (the organisation, the domain, the number), so
|
|
22
|
+
-- the reason sentence can be shown without reading again. A dismissed pair is never suggested
|
|
23
|
+
-- again; a merged one is closed by the merge.
|
|
24
|
+
CREATE TABLE core_duplicate_pair (
|
|
25
|
+
object TEXT NOT NULL CHECK (object IN ('person', 'organisation')),
|
|
26
|
+
a_id TEXT NOT NULL,
|
|
27
|
+
b_id TEXT NOT NULL,
|
|
28
|
+
rules TEXT NOT NULL CHECK (json_valid(rules)),
|
|
29
|
+
details TEXT NOT NULL DEFAULT '{}' CHECK (json_valid(details)),
|
|
30
|
+
status TEXT NOT NULL DEFAULT 'open' CHECK (status IN ('open', 'dismissed', 'merged')),
|
|
31
|
+
created_at TEXT NOT NULL,
|
|
32
|
+
updated_at TEXT NOT NULL,
|
|
33
|
+
decided_at TEXT,
|
|
34
|
+
decided_by TEXT,
|
|
35
|
+
PRIMARY KEY (object, a_id, b_id),
|
|
36
|
+
CHECK (a_id < b_id)
|
|
37
|
+
) WITHOUT ROWID;
|
|
38
|
+
CREATE INDEX core_duplicate_pair_status_idx ON core_duplicate_pair (object, status, a_id, b_id);
|
|
39
|
+
CREATE INDEX core_duplicate_pair_b_idx ON core_duplicate_pair (object, b_id);
|
|
40
|
+
|
|
41
|
+
UPDATE core_meta SET value = '320' WHERE key = 'schema_version';
|