@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,54 @@
|
|
|
1
|
+
-- Migration 0100: stage history and the base currency (stage 4b, ADR 0100, ADR 0101).
|
|
2
|
+
--
|
|
3
|
+
-- Stage history is one row per stage a record has been in: entered and left times. The host
|
|
4
|
+
-- writes it in the same batch as the record change whenever an object with a stage behaviour
|
|
5
|
+
-- (an extension's `stages`, e.g. Deals) enters a stage. It powers time-in-stage and velocity.
|
|
6
|
+
-- `left_at` is NULL for the stage a record is in now; at most one such row per record.
|
|
7
|
+
CREATE TABLE core_stage_history (
|
|
8
|
+
id TEXT PRIMARY KEY NOT NULL,
|
|
9
|
+
-- Registry name of the object: `deals.deal`.
|
|
10
|
+
object_type TEXT NOT NULL,
|
|
11
|
+
record_id TEXT NOT NULL,
|
|
12
|
+
stage_id TEXT NOT NULL,
|
|
13
|
+
-- The stage's group (pipeline) when the record entered it, if the behaviour has groups.
|
|
14
|
+
group_id TEXT,
|
|
15
|
+
-- The stage type when the record entered it: open, won or lost.
|
|
16
|
+
stage_type TEXT NOT NULL CHECK (stage_type IN ('open', 'won', 'lost')),
|
|
17
|
+
entered_at TEXT NOT NULL,
|
|
18
|
+
left_at TEXT,
|
|
19
|
+
entered_by TEXT
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
-- A record's history in order, and its current stage (the left_at IS NULL row).
|
|
23
|
+
CREATE INDEX core_stage_history_record_idx
|
|
24
|
+
ON core_stage_history (object_type, record_id, entered_at);
|
|
25
|
+
CREATE UNIQUE INDEX core_stage_history_current_idx
|
|
26
|
+
ON core_stage_history (object_type, record_id) WHERE left_at IS NULL;
|
|
27
|
+
-- Time in stage and conversion per stage over a period.
|
|
28
|
+
CREATE INDEX core_stage_history_stage_idx ON core_stage_history (stage_id, entered_at);
|
|
29
|
+
|
|
30
|
+
-- Read view for query.sql and dashboards. `days_in_stage` runs to now for the current stage.
|
|
31
|
+
CREATE VIEW crm_stage_history AS
|
|
32
|
+
SELECT
|
|
33
|
+
id,
|
|
34
|
+
object_type,
|
|
35
|
+
record_id,
|
|
36
|
+
stage_id,
|
|
37
|
+
group_id,
|
|
38
|
+
stage_type,
|
|
39
|
+
entered_at,
|
|
40
|
+
left_at,
|
|
41
|
+
left_at IS NULL AS is_current,
|
|
42
|
+
round(
|
|
43
|
+
julianday(coalesce(left_at, strftime('%Y-%m-%dT%H:%M:%fZ', 'now'))) - julianday(entered_at),
|
|
44
|
+
4
|
|
45
|
+
) AS days_in_stage,
|
|
46
|
+
entered_by
|
|
47
|
+
FROM core_stage_history;
|
|
48
|
+
|
|
49
|
+
-- The deployment's one base currency (ADR 0026). Currency fields without their own currency
|
|
50
|
+
-- display in it. Changed with settings.update (admins).
|
|
51
|
+
INSERT OR IGNORE INTO core_settings (key, value, updated_at)
|
|
52
|
+
VALUES ('base_currency', '"USD"', strftime('%Y-%m-%dT%H:%M:%fZ', 'now'));
|
|
53
|
+
|
|
54
|
+
UPDATE core_meta SET value = '100' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
-- Migration 0110: integrations (stage 6a, ADRs 0050, 0051, 0110, 0111).
|
|
2
|
+
--
|
|
3
|
+
-- The integration host (one Durable Object per connection in crm-runner) is the authority for
|
|
4
|
+
-- gatekeeper accounts, facets and hooks: those are RPC stubs that only DO storage can hold. The
|
|
5
|
+
-- tables below mirror connection state for the UI and record what the CRM itself decides:
|
|
6
|
+
-- which gatekeepers an admin enabled, which outbound action kinds may auto-apply, the outbound
|
|
7
|
+
-- items mirrored into the approval queue, and inbound events (webhooks, sync) for stage 5.
|
|
8
|
+
|
|
9
|
+
-- Gatekeepers an admin enabled for this deployment. A vendor with no row is disabled.
|
|
10
|
+
CREATE TABLE core_integration_vendor (
|
|
11
|
+
vendor TEXT PRIMARY KEY NOT NULL,
|
|
12
|
+
enabled INTEGER NOT NULL DEFAULT 0 CHECK (enabled IN (0, 1)),
|
|
13
|
+
-- Auto-provisioned singletons (web search): 'off' | 'optional' (each user turns it on for
|
|
14
|
+
-- their own actors) | 'on' (one org connection everyone's actors use). Null otherwise.
|
|
15
|
+
mode TEXT CHECK (mode IS NULL OR mode IN ('off', 'optional', 'on')),
|
|
16
|
+
updated_at TEXT NOT NULL,
|
|
17
|
+
updated_by TEXT
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
-- A connected gatekeeper account. Personal connections are used only by their owner's actors;
|
|
21
|
+
-- org connections are created by admins and used by everyone's. The host DO named by `id` holds
|
|
22
|
+
-- the account, facets and hooks; this row is the UI's mirror.
|
|
23
|
+
CREATE TABLE core_integration_connection (
|
|
24
|
+
id TEXT PRIMARY KEY NOT NULL,
|
|
25
|
+
vendor TEXT NOT NULL,
|
|
26
|
+
scope TEXT NOT NULL CHECK (scope IN ('personal', 'org')),
|
|
27
|
+
owner_user_id TEXT NOT NULL REFERENCES core_user (id),
|
|
28
|
+
title TEXT NOT NULL,
|
|
29
|
+
-- What the provider calls the account (a mailbox address, a workspace name).
|
|
30
|
+
account_label TEXT,
|
|
31
|
+
-- How synced mail and meetings are disclosed to the CRM (ADR 0052): full | metadata | none.
|
|
32
|
+
sharing_level TEXT NOT NULL DEFAULT 'metadata'
|
|
33
|
+
CHECK (sharing_level IN ('full', 'metadata', 'none')),
|
|
34
|
+
status TEXT NOT NULL DEFAULT 'connecting'
|
|
35
|
+
CHECK (status IN ('connecting', 'active', 'expired', 'error', 'disconnected')),
|
|
36
|
+
error TEXT,
|
|
37
|
+
-- JSON `[{ key, url, pattern, title, tsType, bindingName, hookTsType }]`: bound resources.
|
|
38
|
+
resources TEXT NOT NULL DEFAULT '[]' CHECK (json_valid(resources)),
|
|
39
|
+
-- JSON: what sync does on this connection and how far it got (for the UI).
|
|
40
|
+
sync TEXT NOT NULL DEFAULT '{}' CHECK (json_valid(sync)),
|
|
41
|
+
created_at TEXT NOT NULL,
|
|
42
|
+
updated_at TEXT NOT NULL,
|
|
43
|
+
connected_at TEXT,
|
|
44
|
+
disconnected_at TEXT,
|
|
45
|
+
last_sync_at TEXT
|
|
46
|
+
);
|
|
47
|
+
CREATE INDEX core_integration_connection_owner_idx
|
|
48
|
+
ON core_integration_connection (owner_user_id, status);
|
|
49
|
+
CREATE INDEX core_integration_connection_scope_idx ON core_integration_connection (scope, status);
|
|
50
|
+
CREATE INDEX core_integration_connection_vendor_idx
|
|
51
|
+
ON core_integration_connection (vendor, status);
|
|
52
|
+
|
|
53
|
+
-- Outbound action kinds (ADR 0051) the CRM has seen, and whether an admin let them auto-apply.
|
|
54
|
+
-- Only kinds the gatekeeper marks `autoApprovable` can be enabled; enabling is human-admin-only
|
|
55
|
+
-- and audited (outbound.setAutoApprove).
|
|
56
|
+
CREATE TABLE core_outbound_kind (
|
|
57
|
+
tag TEXT PRIMARY KEY NOT NULL,
|
|
58
|
+
vendor TEXT NOT NULL,
|
|
59
|
+
label TEXT NOT NULL,
|
|
60
|
+
auto_approvable INTEGER NOT NULL DEFAULT 0 CHECK (auto_approvable IN (0, 1)),
|
|
61
|
+
auto_approve INTEGER NOT NULL DEFAULT 0 CHECK (auto_approve IN (0, 1)),
|
|
62
|
+
first_seen_at TEXT NOT NULL,
|
|
63
|
+
updated_at TEXT NOT NULL,
|
|
64
|
+
updated_by TEXT,
|
|
65
|
+
CHECK (auto_approve = 0 OR auto_approvable = 1)
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
-- Gatekeeper actions mirrored into the approval queue as `outbound` items (ADR 0051). The
|
|
69
|
+
-- gatekeeper journals the action; approval calls `applyAction(gk_action)` on the facet
|
|
70
|
+
-- `facet_key` of the host for `connection_id`, in gk_action order per facet.
|
|
71
|
+
ALTER TABLE core_pending_action ADD COLUMN connection_id TEXT;
|
|
72
|
+
ALTER TABLE core_pending_action ADD COLUMN facet_key TEXT;
|
|
73
|
+
ALTER TABLE core_pending_action ADD COLUMN gk_action INTEGER;
|
|
74
|
+
ALTER TABLE core_pending_action ADD COLUMN action_kind TEXT;
|
|
75
|
+
CREATE UNIQUE INDEX core_pending_action_outbound_idx
|
|
76
|
+
ON core_pending_action (connection_id, facet_key, gk_action)
|
|
77
|
+
WHERE connection_id IS NOT NULL;
|
|
78
|
+
|
|
79
|
+
-- Inbound events for stage 5 automations: verified webhook deliveries and sync events (an email
|
|
80
|
+
-- received from a customer, a meeting updated). Payloads hold ids and typed fields, never content
|
|
81
|
+
-- from a restricted read.
|
|
82
|
+
CREATE TABLE core_integration_event (
|
|
83
|
+
id TEXT PRIMARY KEY NOT NULL,
|
|
84
|
+
source TEXT NOT NULL CHECK (source IN ('webhook', 'sync')),
|
|
85
|
+
connection_id TEXT,
|
|
86
|
+
type TEXT NOT NULL,
|
|
87
|
+
-- The provider's delivery id (webhooks), for dedupe.
|
|
88
|
+
external_id TEXT,
|
|
89
|
+
payload TEXT NOT NULL CHECK (json_valid(payload)),
|
|
90
|
+
occurred_at TEXT NOT NULL,
|
|
91
|
+
created_at TEXT NOT NULL,
|
|
92
|
+
-- Set by stage 5 once an automation trigger has taken the event.
|
|
93
|
+
consumed_at TEXT
|
|
94
|
+
);
|
|
95
|
+
CREATE UNIQUE INDEX core_integration_event_dedupe_idx
|
|
96
|
+
ON core_integration_event (source, connection_id, external_id)
|
|
97
|
+
WHERE external_id IS NOT NULL;
|
|
98
|
+
CREATE INDEX core_integration_event_type_idx ON core_integration_event (source, type, id);
|
|
99
|
+
CREATE INDEX core_integration_event_unconsumed_idx ON core_integration_event (id)
|
|
100
|
+
WHERE consumed_at IS NULL;
|
|
101
|
+
CREATE INDEX core_integration_event_created_idx ON core_integration_event (created_at);
|
|
102
|
+
|
|
103
|
+
UPDATE core_meta SET value = '110' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
-- Migration 0111: email and calendar sync (stage 6a, ADR 0052, ADR 0112).
|
|
2
|
+
--
|
|
3
|
+
-- Synced mail and meetings become `email` and `meeting` activities. Cost audit U1/U2:
|
|
4
|
+
-- * dedupe across mailboxes uses an indexed key (`external_key`: 'email:<Message-ID>' or
|
|
5
|
+
-- 'ical:<UID>'), never a scan of payload JSON;
|
|
6
|
+
-- * full bodies live in R2 (`body_ref`); D1 and the search index get a short snippet only;
|
|
7
|
+
-- * "emailed at least twice" is a counter table, not a scan.
|
|
8
|
+
-- Restricted reads (a gatekeeper observation with containsRestrictedData) are never written:
|
|
9
|
+
-- the sync service drops them before anything here is touched.
|
|
10
|
+
|
|
11
|
+
ALTER TABLE core_activity ADD COLUMN external_key TEXT;
|
|
12
|
+
CREATE UNIQUE INDEX core_activity_external_key_idx ON core_activity (external_key)
|
|
13
|
+
WHERE external_key IS NOT NULL;
|
|
14
|
+
-- The conversation an email belongs to: 'thread:<root Message-ID>' (References / In-Reply-To).
|
|
15
|
+
ALTER TABLE core_activity ADD COLUMN thread_key TEXT;
|
|
16
|
+
CREATE INDEX core_activity_thread_idx ON core_activity (thread_key, occurred_at)
|
|
17
|
+
WHERE thread_key IS NOT NULL;
|
|
18
|
+
-- Set when the activity was marked private: only this user sees it (activity.setPrivate).
|
|
19
|
+
ALTER TABLE core_activity ADD COLUMN private_to TEXT;
|
|
20
|
+
-- The R2 key of the full email body, when its mailbox shares full content.
|
|
21
|
+
ALTER TABLE core_activity ADD COLUMN body_ref TEXT;
|
|
22
|
+
-- What the activity discloses: 'full' or 'metadata' (synced activities only).
|
|
23
|
+
ALTER TABLE core_activity ADD COLUMN disclosure TEXT
|
|
24
|
+
CHECK (disclosure IS NULL OR disclosure IN ('full', 'metadata'));
|
|
25
|
+
|
|
26
|
+
-- Private activities stay out of SQL views and search; their owner still sees them on timelines.
|
|
27
|
+
DROP VIEW crm_activities;
|
|
28
|
+
DROP VIEW core_base_activities;
|
|
29
|
+
CREATE VIEW core_base_activities AS
|
|
30
|
+
SELECT
|
|
31
|
+
activity.id,
|
|
32
|
+
activity.type,
|
|
33
|
+
activity.subject,
|
|
34
|
+
activity.body,
|
|
35
|
+
activity.payload,
|
|
36
|
+
activity.occurred_at,
|
|
37
|
+
activity.author_user_id,
|
|
38
|
+
activity.author_actor,
|
|
39
|
+
activity.created_at,
|
|
40
|
+
activity.updated_at
|
|
41
|
+
FROM core_activity activity
|
|
42
|
+
WHERE activity.deleted_at IS NULL AND activity.private_to IS NULL;
|
|
43
|
+
CREATE VIEW crm_activities AS SELECT b.* FROM core_base_activities b;
|
|
44
|
+
|
|
45
|
+
DROP VIEW crm_activity_links;
|
|
46
|
+
CREATE VIEW crm_activity_links AS
|
|
47
|
+
SELECT l.activity_id, l.object_type, l.record_id
|
|
48
|
+
FROM core_activity_links l
|
|
49
|
+
JOIN core_activity a ON a.id = l.activity_id AND a.deleted_at IS NULL AND a.private_to IS NULL;
|
|
50
|
+
|
|
51
|
+
DROP TRIGGER core_activity_search_ai;
|
|
52
|
+
CREATE TRIGGER core_activity_search_ai AFTER INSERT ON core_activity
|
|
53
|
+
BEGIN
|
|
54
|
+
DELETE FROM core_search_docs WHERE object_type = 'activity' AND record_id = NEW.id;
|
|
55
|
+
INSERT INTO core_search_docs (object_type, record_id, title, body)
|
|
56
|
+
SELECT 'activity', a.id, coalesce(a.subject, ''), coalesce(a.body, '')
|
|
57
|
+
FROM core_activity a WHERE a.id = NEW.id AND a.deleted_at IS NULL AND a.private_to IS NULL;
|
|
58
|
+
END;
|
|
59
|
+
|
|
60
|
+
DROP TRIGGER core_activity_search_au;
|
|
61
|
+
CREATE TRIGGER core_activity_search_au AFTER UPDATE OF subject, body, deleted_at, private_to
|
|
62
|
+
ON core_activity
|
|
63
|
+
BEGIN
|
|
64
|
+
DELETE FROM core_search_docs WHERE object_type = 'activity' AND record_id = NEW.id;
|
|
65
|
+
INSERT INTO core_search_docs (object_type, record_id, title, body)
|
|
66
|
+
SELECT 'activity', a.id, coalesce(a.subject, ''), coalesce(a.body, '')
|
|
67
|
+
FROM core_activity a WHERE a.id = NEW.id AND a.deleted_at IS NULL AND a.private_to IS NULL;
|
|
68
|
+
END;
|
|
69
|
+
|
|
70
|
+
-- One row per message or event seen in one mailbox or calendar: which activity it became (null
|
|
71
|
+
-- when nothing was written: no known person or organisation). Deletes propagate when the last
|
|
72
|
+
-- mailbox holding a key drops it.
|
|
73
|
+
CREATE TABLE core_sync_item (
|
|
74
|
+
connection_id TEXT NOT NULL,
|
|
75
|
+
provider_id TEXT NOT NULL,
|
|
76
|
+
external_key TEXT NOT NULL,
|
|
77
|
+
kind TEXT NOT NULL CHECK (kind IN ('email', 'meeting')),
|
|
78
|
+
activity_id TEXT,
|
|
79
|
+
updated_at TEXT NOT NULL,
|
|
80
|
+
PRIMARY KEY (connection_id, provider_id)
|
|
81
|
+
);
|
|
82
|
+
CREATE INDEX core_sync_item_key_idx ON core_sync_item (external_key);
|
|
83
|
+
|
|
84
|
+
-- Suggested contacts (ADR 0052): external addresses the org has exchanged mail with that match
|
|
85
|
+
-- no person. Counted once per distinct message. Shown from `message_count >= 2`, grouped by
|
|
86
|
+
-- domain. Nothing is created automatically.
|
|
87
|
+
CREATE TABLE core_suggested_contact (
|
|
88
|
+
email TEXT PRIMARY KEY NOT NULL,
|
|
89
|
+
domain TEXT NOT NULL,
|
|
90
|
+
name TEXT,
|
|
91
|
+
message_count INTEGER NOT NULL DEFAULT 0,
|
|
92
|
+
first_seen_at TEXT NOT NULL,
|
|
93
|
+
last_seen_at TEXT NOT NULL,
|
|
94
|
+
status TEXT NOT NULL DEFAULT 'open' CHECK (status IN ('open', 'added', 'dismissed')),
|
|
95
|
+
person_id TEXT,
|
|
96
|
+
decided_by TEXT,
|
|
97
|
+
decided_at TEXT
|
|
98
|
+
);
|
|
99
|
+
CREATE INDEX core_suggested_contact_open_idx
|
|
100
|
+
ON core_suggested_contact (status, domain, message_count);
|
|
101
|
+
|
|
102
|
+
-- Job-change signals from mail (ADR 0052 amendment): a bounce from a known address, a new
|
|
103
|
+
-- signature, or a new domain for a known person. Confirming applies person.changeJob.
|
|
104
|
+
CREATE TABLE core_job_change_suggestion (
|
|
105
|
+
id TEXT PRIMARY KEY NOT NULL,
|
|
106
|
+
person_id TEXT NOT NULL,
|
|
107
|
+
signal TEXT NOT NULL CHECK (signal IN ('bounce', 'signature', 'domain')),
|
|
108
|
+
-- One open suggestion per person and evidence (e.g. 'bounce:ada@old.example').
|
|
109
|
+
dedupe_key TEXT NOT NULL,
|
|
110
|
+
evidence TEXT NOT NULL CHECK (json_valid(evidence)),
|
|
111
|
+
-- What confirming would do: { organisationId?, organisationName?, domain?, title?, endOnly }.
|
|
112
|
+
proposal TEXT NOT NULL CHECK (json_valid(proposal)),
|
|
113
|
+
status TEXT NOT NULL DEFAULT 'open' CHECK (status IN ('open', 'applied', 'dismissed')),
|
|
114
|
+
created_at TEXT NOT NULL,
|
|
115
|
+
decided_by TEXT,
|
|
116
|
+
decided_at TEXT
|
|
117
|
+
);
|
|
118
|
+
CREATE UNIQUE INDEX core_job_change_suggestion_dedupe_idx
|
|
119
|
+
ON core_job_change_suggestion (person_id, dedupe_key);
|
|
120
|
+
CREATE INDEX core_job_change_suggestion_status_idx
|
|
121
|
+
ON core_job_change_suggestion (status, created_at);
|
|
122
|
+
|
|
123
|
+
-- Job-change "new domain" signals look people up by name.
|
|
124
|
+
CREATE INDEX core_person_display_name_lower_idx ON core_person (lower(display_name))
|
|
125
|
+
WHERE deleted_at IS NULL;
|
|
126
|
+
|
|
127
|
+
-- The last signature seen from each known person, to notice a new one.
|
|
128
|
+
CREATE TABLE core_person_signature (
|
|
129
|
+
person_id TEXT PRIMARY KEY NOT NULL,
|
|
130
|
+
email TEXT NOT NULL,
|
|
131
|
+
signature_hash TEXT NOT NULL,
|
|
132
|
+
company TEXT,
|
|
133
|
+
title TEXT,
|
|
134
|
+
seen_at TEXT NOT NULL
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
UPDATE core_meta SET value = '111' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
-- Stage 6a: delete reconciliation (ADR 0112). When the message was sent or the event starts:
|
|
2
|
+
-- after each caught-up pass the host lists one time window from the provider and deletes what
|
|
3
|
+
-- was synced there but is no longer listed, comparing against these rows.
|
|
4
|
+
ALTER TABLE core_sync_item ADD COLUMN occurred_at TEXT;
|
|
5
|
+
CREATE INDEX core_sync_item_window_idx ON core_sync_item (connection_id, kind, occurred_at)
|
|
6
|
+
WHERE activity_id IS NOT NULL;
|
|
7
|
+
|
|
8
|
+
UPDATE core_meta SET value = '112' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
-- Migration 0130: automations (stage 5, ADR 0028, ADR 0130).
|
|
2
|
+
--
|
|
3
|
+
-- core_automations mirrors the `automations` of every installed extension (one row per
|
|
4
|
+
-- automation, written by extension.install from the manifest). The queue consumer matches events
|
|
5
|
+
-- against enabled rows through core_automations_trigger_idx; the manifest JSON is in `spec`.
|
|
6
|
+
CREATE TABLE core_automations (
|
|
7
|
+
-- `<extensionId>.<key>`, e.g. `deals.wonOnboarding`.
|
|
8
|
+
id TEXT PRIMARY KEY NOT NULL,
|
|
9
|
+
extension_id TEXT NOT NULL,
|
|
10
|
+
key TEXT NOT NULL,
|
|
11
|
+
label TEXT NOT NULL,
|
|
12
|
+
-- record | fieldChanged | schedule | dateRelative | manual | approvalDecided (6b: webhook, syncEvent)
|
|
13
|
+
trigger_type TEXT NOT NULL,
|
|
14
|
+
-- The trigger's object, when it has one.
|
|
15
|
+
trigger_object TEXT,
|
|
16
|
+
-- The automation's manifest (AutomationManifest JSON).
|
|
17
|
+
spec TEXT NOT NULL,
|
|
18
|
+
-- The extension commit this definition came from.
|
|
19
|
+
commit_oid TEXT,
|
|
20
|
+
-- Enabled by an admin (automation.enable / disable). Shipped automations start enabled.
|
|
21
|
+
enabled INTEGER NOT NULL DEFAULT 1 CHECK (enabled IN (0, 1)),
|
|
22
|
+
-- Set when a rail auto-paused it (rate limit); cleared by automation.enable.
|
|
23
|
+
paused_reason TEXT,
|
|
24
|
+
paused_at TEXT,
|
|
25
|
+
-- Set when a later version of the extension no longer declares it (kept for run history).
|
|
26
|
+
removed_at TEXT,
|
|
27
|
+
created_at TEXT NOT NULL,
|
|
28
|
+
updated_at TEXT NOT NULL
|
|
29
|
+
);
|
|
30
|
+
-- Matching: enabled, live automations by trigger type and object.
|
|
31
|
+
CREATE INDEX core_automations_trigger_idx
|
|
32
|
+
ON core_automations (trigger_type, trigger_object)
|
|
33
|
+
WHERE enabled = 1 AND paused_reason IS NULL AND removed_at IS NULL;
|
|
34
|
+
CREATE INDEX core_automations_extension_idx ON core_automations (extension_id);
|
|
35
|
+
|
|
36
|
+
-- One row per run (and per test run). `workflow_id` is the Workflow instance id, derived from the
|
|
37
|
+
-- run's idempotency key (event id + automation id, or automation id + period for schedules and
|
|
38
|
+
-- date-relative triggers): its unique index makes a duplicate delivery a no-op.
|
|
39
|
+
CREATE TABLE core_automation_runs (
|
|
40
|
+
id TEXT PRIMARY KEY NOT NULL,
|
|
41
|
+
automation_id TEXT NOT NULL,
|
|
42
|
+
extension_id TEXT NOT NULL,
|
|
43
|
+
commit_oid TEXT,
|
|
44
|
+
workflow_id TEXT,
|
|
45
|
+
-- JSON: { type, eventId, period?, manual?, approval?, change? }
|
|
46
|
+
trigger TEXT NOT NULL,
|
|
47
|
+
record_object TEXT,
|
|
48
|
+
record_id TEXT,
|
|
49
|
+
status TEXT NOT NULL CHECK (status IN (
|
|
50
|
+
'queued', 'running', 'waiting', 'review', 'completed', 'failed', 'cancelled', 'expired',
|
|
51
|
+
'skipped'
|
|
52
|
+
)),
|
|
53
|
+
status_reason TEXT,
|
|
54
|
+
test INTEGER NOT NULL DEFAULT 0 CHECK (test IN (0, 1)),
|
|
55
|
+
depth INTEGER NOT NULL DEFAULT 0,
|
|
56
|
+
root_event_id TEXT,
|
|
57
|
+
-- JSON array of RunStepRecord.
|
|
58
|
+
steps TEXT NOT NULL DEFAULT '[]',
|
|
59
|
+
-- Records written by the run (rate limit: writes per hour).
|
|
60
|
+
writes INTEGER NOT NULL DEFAULT 0,
|
|
61
|
+
-- The change set its pending actions go in (review pause).
|
|
62
|
+
change_set_id TEXT,
|
|
63
|
+
-- When a waiting run resumes (sleep) or gives up (waitForEvent, review expiry).
|
|
64
|
+
wait_until TEXT,
|
|
65
|
+
retry_of TEXT,
|
|
66
|
+
replay_of TEXT,
|
|
67
|
+
-- Test runs: the AutomationTestReport JSON.
|
|
68
|
+
report TEXT,
|
|
69
|
+
error TEXT,
|
|
70
|
+
started_at TEXT NOT NULL,
|
|
71
|
+
updated_at TEXT NOT NULL,
|
|
72
|
+
finished_at TEXT
|
|
73
|
+
);
|
|
74
|
+
CREATE UNIQUE INDEX core_automation_runs_workflow_idx
|
|
75
|
+
ON core_automation_runs (workflow_id) WHERE workflow_id IS NOT NULL;
|
|
76
|
+
-- An automation's runs, newest first (Runs tab, recent runs, rails).
|
|
77
|
+
CREATE INDEX core_automation_runs_automation_idx
|
|
78
|
+
ON core_automation_runs (automation_id, started_at);
|
|
79
|
+
-- Retention (ADR 0090): the oldest finished runs of a status.
|
|
80
|
+
CREATE INDEX core_automation_runs_status_idx ON core_automation_runs (status, started_at);
|
|
81
|
+
|
|
82
|
+
-- Records a run touched (its trigger record and records it wrote): the per-record Automations
|
|
83
|
+
-- section on record pages.
|
|
84
|
+
CREATE TABLE core_automation_run_records (
|
|
85
|
+
object_type TEXT NOT NULL,
|
|
86
|
+
record_id TEXT NOT NULL,
|
|
87
|
+
run_id TEXT NOT NULL,
|
|
88
|
+
-- trigger | create | update | delete
|
|
89
|
+
role TEXT NOT NULL,
|
|
90
|
+
at TEXT NOT NULL,
|
|
91
|
+
PRIMARY KEY (object_type, record_id, run_id)
|
|
92
|
+
) WITHOUT ROWID;
|
|
93
|
+
CREATE INDEX core_automation_run_records_run_idx ON core_automation_run_records (run_id);
|
|
94
|
+
|
|
95
|
+
-- Per-automation counters per UTC hour (rails: writes per hour; run counts), one upsert per run.
|
|
96
|
+
CREATE TABLE core_automation_counters (
|
|
97
|
+
automation_id TEXT NOT NULL,
|
|
98
|
+
-- 'YYYY-MM-DDTHH'
|
|
99
|
+
hour TEXT NOT NULL,
|
|
100
|
+
runs INTEGER NOT NULL DEFAULT 0,
|
|
101
|
+
writes INTEGER NOT NULL DEFAULT 0,
|
|
102
|
+
PRIMARY KEY (automation_id, hour)
|
|
103
|
+
) WITHOUT ROWID;
|
|
104
|
+
|
|
105
|
+
-- Settings: the kill switch (human admins only), the schedule timezone and the debounce window.
|
|
106
|
+
INSERT OR IGNORE INTO core_settings (key, value, updated_at)
|
|
107
|
+
VALUES ('automations_kill_switch', 'false', strftime('%Y-%m-%dT%H:%M:%fZ', 'now'));
|
|
108
|
+
INSERT OR IGNORE INTO core_settings (key, value, updated_at)
|
|
109
|
+
VALUES ('automation_timezone', '"UTC"', strftime('%Y-%m-%dT%H:%M:%fZ', 'now'));
|
|
110
|
+
INSERT OR IGNORE INTO core_settings (key, value, updated_at)
|
|
111
|
+
VALUES ('automation_debounce_seconds', '30', strftime('%Y-%m-%dT%H:%M:%fZ', 'now'));
|
|
112
|
+
|
|
113
|
+
UPDATE core_meta SET value = '130' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
-- Migration 0131: the in-app notification centre (stage 5, ADR 0029, ADR 0132).
|
|
2
|
+
--
|
|
3
|
+
-- One row per notification per user. Typed (`type`, see NOTIFICATION_TYPES in @crm/core) so stage
|
|
4
|
+
-- 6b can route types to email or Slack. Kept 90 days (the daily maintenance cron).
|
|
5
|
+
CREATE TABLE core_notifications (
|
|
6
|
+
id TEXT PRIMARY KEY NOT NULL,
|
|
7
|
+
user_id TEXT NOT NULL,
|
|
8
|
+
type TEXT NOT NULL,
|
|
9
|
+
title TEXT NOT NULL,
|
|
10
|
+
body TEXT,
|
|
11
|
+
-- JSON NotificationLink: record, approval, automationRun or automation.
|
|
12
|
+
link TEXT,
|
|
13
|
+
-- JSON: { actor, automationId?, runId?, userId? }
|
|
14
|
+
source TEXT NOT NULL DEFAULT '{}',
|
|
15
|
+
-- Optional: one notification per (user, key), e.g. one per change set waiting for approval.
|
|
16
|
+
dedupe_key TEXT,
|
|
17
|
+
read_at TEXT,
|
|
18
|
+
created_at TEXT NOT NULL
|
|
19
|
+
);
|
|
20
|
+
-- The inbox, newest first.
|
|
21
|
+
CREATE INDEX core_notifications_user_idx ON core_notifications (user_id, created_at);
|
|
22
|
+
-- The bell's unread count.
|
|
23
|
+
CREATE INDEX core_notifications_unread_idx ON core_notifications (user_id) WHERE read_at IS NULL;
|
|
24
|
+
CREATE UNIQUE INDEX core_notifications_dedupe_idx
|
|
25
|
+
ON core_notifications (user_id, dedupe_key) WHERE dedupe_key IS NOT NULL;
|
|
26
|
+
-- Retention.
|
|
27
|
+
CREATE INDEX core_notifications_created_idx ON core_notifications (created_at);
|
|
28
|
+
|
|
29
|
+
UPDATE core_meta SET value = '131' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
-- Migration 0132: indexes for the automation runtime (stage 5, ADR 0130).
|
|
2
|
+
--
|
|
3
|
+
-- Fan-out budget: runs started from one root event (an import, a cascade), cost audit U3.
|
|
4
|
+
CREATE INDEX core_automation_runs_root_idx
|
|
5
|
+
ON core_automation_runs (root_event_id) WHERE root_event_id IS NOT NULL;
|
|
6
|
+
-- Every automation's runs, newest first (automation.runs without an automation).
|
|
7
|
+
CREATE INDEX core_automation_runs_started_idx ON core_automation_runs (started_at);
|
|
8
|
+
-- The latest test-mode report of an automation (automation.get).
|
|
9
|
+
CREATE INDEX core_automation_runs_test_idx
|
|
10
|
+
ON core_automation_runs (automation_id, started_at) WHERE test = 1;
|
|
11
|
+
-- Retention: counters older than two days.
|
|
12
|
+
CREATE INDEX core_automation_counters_hour_idx ON core_automation_counters (hour);
|
|
13
|
+
|
|
14
|
+
UPDATE core_meta SET value = '132' WHERE key = 'schema_version';
|
|
@@ -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';
|