@composable-os/cli 0.0.0-stage → 0.1.0-beta.10
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-X4CKM3HL.js +46 -0
- package/dist/blocks-YWDHEBOK.js +233 -0
- package/dist/chunk-2ABSVMGB.js +13 -0
- package/dist/chunk-5KSXSK7Y.js +47 -0
- package/dist/chunk-6GDEDOV7.js +157 -0
- package/dist/chunk-6UPUF4ML.js +29998 -0
- package/dist/chunk-6UWRT4VM.js +220 -0
- package/dist/chunk-6VXHPKGG.js +1302 -0
- package/dist/chunk-7CQGMVDO.js +63 -0
- package/dist/chunk-A4NTSYWV.js +11092 -0
- package/dist/chunk-CP6BXI6F.js +25825 -0
- package/dist/chunk-DU6OIFOU.js +2358 -0
- package/dist/chunk-E4WCYTCT.js +347 -0
- package/dist/chunk-GYSGVT6R.js +284 -0
- package/dist/chunk-GYTEW66E.js +50 -0
- package/dist/chunk-HDIOVFAZ.js +544 -0
- package/dist/chunk-IFG4FRW5.js +504 -0
- package/dist/chunk-JJHHNV46.js +227 -0
- package/dist/chunk-K6T42YCH.js +704 -0
- package/dist/chunk-KGHA67HG.js +765 -0
- package/dist/chunk-LJFLENFC.js +88 -0
- package/dist/chunk-LLULPZAJ.js +365 -0
- package/dist/chunk-M7A6FR2Z.js +2586 -0
- package/dist/chunk-O2UIZHND.js +249 -0
- package/dist/chunk-Q4N55M2Z.js +552 -0
- package/dist/chunk-QGGJ2G6Z.js +349 -0
- package/dist/chunk-R4W5XAUD.js +837 -0
- package/dist/chunk-TQFGGSA4.js +748 -0
- package/dist/chunk-VY64DMQO.js +15302 -0
- package/dist/chunk-WC5LHBBA.js +426 -0
- package/dist/chunk-WO6D3XP3.js +9351 -0
- package/dist/chunk-Y7JZFSTQ.js +1425 -0
- package/dist/chunk-YJJHF65I.js +759 -0
- package/dist/chunk-Z3RMMB6S.js +668 -0
- package/dist/cli-2DFENR62.js +134 -0
- package/dist/cli-YIOVSKOD.js +24531 -0
- package/dist/cli.js +25 -0
- package/dist/client-repo-PRU3VCQQ.js +55 -0
- package/dist/create.js +25 -0
- package/dist/fields-2NC7LSYE.js +50 -0
- package/dist/grants-QXMKYMGB.js +32 -0
- package/dist/invoke-I3NNNXVL.js +39 -0
- package/dist/order-PUWD65BC.js +19 -0
- package/dist/person-WIQQ7ITU.js +68 -0
- package/dist/plan-on-sale-NB774CQL.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/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 +201 -0
- package/dist/platform/sdk/contract.ts +884 -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 +1709 -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 +888 -0
- package/dist/platform/sdk/slug.ts +25 -0
- package/dist/platform/sdk/states.ts +484 -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-PZUCSDDL.js +508 -0
- package/dist/run-RT2HVWMK.js +648 -0
- package/dist/run-Y7T4TVOL.js +309 -0
- package/dist/src-GYS6NBQB.js +44 -0
- package/dist/src-XTOD7EXW.js +348 -0
- package/dist/token-MOJUA2U6.js +70 -0
- package/dist/token-util-TENRN4V7.js +6 -0
- package/dist/visibility-DLGHU4YN.js +33 -0
- package/package.json +33 -4
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
-- Migration 0061: audit retention, a sanctioned purge path through the append-only triggers
|
|
2
|
+
-- (ADR 0090; amends ADR 0017, in the spirit of ADR 0019's redaction markers).
|
|
3
|
+
--
|
|
4
|
+
-- Retention is an org setting, `audit_retention` = {"years": null | 1 | 2 | 7}. null (the
|
|
5
|
+
-- default, and the meaning of a missing row) keeps the audit log forever. Only a human admin can
|
|
6
|
+
-- change it (`audit.setRetention`, risk destructive).
|
|
7
|
+
--
|
|
8
|
+
-- DELETE on core_audit, core_audit_changes and core_audit_redactions stays refused unless
|
|
9
|
+
-- retention is not "forever" AND the row is older than the cutoff of a purge marker in
|
|
10
|
+
-- core_audit_purges. A marker can only be inserted with the current setting and a cutoff at least
|
|
11
|
+
-- that many years before the database clock, and markers are append-only. So:
|
|
12
|
+
-- - an ordinary DELETE of audit rows inside the retention window still fails "append-only";
|
|
13
|
+
-- - nothing can purge what the admin's setting keeps, whatever code inserts the marker;
|
|
14
|
+
-- - every purge leaves a permanent marker, and its own audit row (`audit.purge`).
|
|
15
|
+
CREATE TABLE core_audit_purges (
|
|
16
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
17
|
+
-- Audit rows with `at` before this may be deleted, with their change rows and markers.
|
|
18
|
+
cutoff TEXT NOT NULL,
|
|
19
|
+
-- The retention setting in force when the marker was written.
|
|
20
|
+
retention_years INTEGER NOT NULL CHECK (retention_years IN (1, 2, 7)),
|
|
21
|
+
-- The audit.purge invocation's own audit row, written in the same batch.
|
|
22
|
+
audit_id TEXT,
|
|
23
|
+
user_id TEXT,
|
|
24
|
+
at TEXT NOT NULL
|
|
25
|
+
);
|
|
26
|
+
CREATE INDEX core_audit_purges_cutoff_idx ON core_audit_purges (cutoff);
|
|
27
|
+
|
|
28
|
+
CREATE TRIGGER core_audit_purges_no_update BEFORE UPDATE ON core_audit_purges
|
|
29
|
+
BEGIN
|
|
30
|
+
SELECT RAISE(ABORT, 'core_audit_purges is append-only');
|
|
31
|
+
END;
|
|
32
|
+
|
|
33
|
+
CREATE TRIGGER core_audit_purges_no_delete BEFORE DELETE ON core_audit_purges
|
|
34
|
+
BEGIN
|
|
35
|
+
SELECT RAISE(ABORT, 'core_audit_purges is append-only');
|
|
36
|
+
END;
|
|
37
|
+
|
|
38
|
+
-- A marker must match the current setting and lie at least that many years in the past.
|
|
39
|
+
CREATE TRIGGER core_audit_purges_check BEFORE INSERT ON core_audit_purges
|
|
40
|
+
WHEN NOT (
|
|
41
|
+
NEW.retention_years IS (
|
|
42
|
+
SELECT json_extract(value, '$.years') FROM core_settings WHERE key = 'audit_retention'
|
|
43
|
+
)
|
|
44
|
+
AND NEW.cutoff <= strftime('%Y-%m-%dT%H:%M:%fZ', 'now', '-' || NEW.retention_years || ' years')
|
|
45
|
+
)
|
|
46
|
+
BEGIN
|
|
47
|
+
SELECT RAISE(ABORT, 'audit purge cutoff is inside the retention window');
|
|
48
|
+
END;
|
|
49
|
+
|
|
50
|
+
-- Guards: replace the unconditional DELETE refusals (migrations 0005, 0008, 0020).
|
|
51
|
+
|
|
52
|
+
DROP TRIGGER core_audit_no_delete;
|
|
53
|
+
CREATE TRIGGER core_audit_no_delete BEFORE DELETE ON core_audit
|
|
54
|
+
WHEN NOT (
|
|
55
|
+
(SELECT json_extract(value, '$.years') FROM core_settings WHERE key = 'audit_retention')
|
|
56
|
+
IS NOT NULL
|
|
57
|
+
AND OLD.at < coalesce((SELECT max(cutoff) FROM core_audit_purges), '')
|
|
58
|
+
)
|
|
59
|
+
BEGIN
|
|
60
|
+
SELECT RAISE(ABORT, 'core_audit is append-only');
|
|
61
|
+
END;
|
|
62
|
+
|
|
63
|
+
DROP TRIGGER core_audit_changes_no_delete;
|
|
64
|
+
CREATE TRIGGER core_audit_changes_no_delete BEFORE DELETE ON core_audit_changes
|
|
65
|
+
WHEN NOT (
|
|
66
|
+
(SELECT json_extract(value, '$.years') FROM core_settings WHERE key = 'audit_retention')
|
|
67
|
+
IS NOT NULL
|
|
68
|
+
AND OLD.at < coalesce((SELECT max(cutoff) FROM core_audit_purges), '')
|
|
69
|
+
)
|
|
70
|
+
BEGIN
|
|
71
|
+
SELECT RAISE(ABORT, 'core_audit_changes is append-only');
|
|
72
|
+
END;
|
|
73
|
+
|
|
74
|
+
-- A redaction marker goes with the audit or change row it redacted (its foreign key would
|
|
75
|
+
-- otherwise keep that row forever). The erase's own audit row is newer and stays.
|
|
76
|
+
DROP TRIGGER core_audit_redactions_no_delete;
|
|
77
|
+
CREATE TRIGGER core_audit_redactions_no_delete BEFORE DELETE ON core_audit_redactions
|
|
78
|
+
WHEN NOT (
|
|
79
|
+
(SELECT json_extract(value, '$.years') FROM core_settings WHERE key = 'audit_retention')
|
|
80
|
+
IS NOT NULL
|
|
81
|
+
AND coalesce(
|
|
82
|
+
(SELECT a.at FROM core_audit a WHERE a.id = OLD.audit_id),
|
|
83
|
+
(SELECT c.at FROM core_audit_changes c WHERE c.id = OLD.change_id)
|
|
84
|
+
) < coalesce((SELECT max(cutoff) FROM core_audit_purges), '')
|
|
85
|
+
)
|
|
86
|
+
BEGIN
|
|
87
|
+
SELECT RAISE(ABORT, 'core_audit_redactions is append-only');
|
|
88
|
+
END;
|
|
89
|
+
|
|
90
|
+
-- The default: keep forever.
|
|
91
|
+
INSERT INTO core_settings (key, value, updated_at)
|
|
92
|
+
VALUES ('audit_retention', '{"years":null}', strftime('%Y-%m-%dT%H:%M:%fZ', 'now'))
|
|
93
|
+
ON CONFLICT (key) DO NOTHING;
|
|
94
|
+
|
|
95
|
+
UPDATE core_meta SET value = '61' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
-- Migration 0062: run history retention (ADR 0090, cost audit F16). The daily cron deletes
|
|
2
|
+
-- successful extension and automation runs after 30 days and failed ones after 90. This index
|
|
3
|
+
-- lets each chunk find the oldest runs of an outcome without scanning the table.
|
|
4
|
+
CREATE INDEX core_extension_runs_outcome_idx ON core_extension_runs (outcome, started_at);
|
|
5
|
+
|
|
6
|
+
UPDATE core_meta SET value = '62' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
-- Migration 0063: compacting decided pending actions (ADR 0090, cost audit F17).
|
|
2
|
+
--
|
|
3
|
+
-- 30 days after a pending action was decided (applied, failed, skipped, rejected) or expired,
|
|
4
|
+
-- the daily cron replaces its input, preview and simulated records with empty values and keeps
|
|
5
|
+
-- a summary, `summary` = {"records": n, "actions": {"update": n, ...}, "inputBytes": n, ...},
|
|
6
|
+
-- next to the columns that already say what, who and when (operation, risk, actor, user_id,
|
|
7
|
+
-- status, decided_by, decided_at, result, error). `compacted_at` says when that happened.
|
|
8
|
+
ALTER TABLE core_pending_action ADD COLUMN compacted_at TEXT;
|
|
9
|
+
ALTER TABLE core_pending_action ADD COLUMN summary TEXT
|
|
10
|
+
CHECK (summary IS NULL OR json_valid(summary));
|
|
11
|
+
|
|
12
|
+
-- Compaction candidates, oldest first: decided or expired, not yet compacted. Expired actions
|
|
13
|
+
-- have no decided_at, so the key is the decision time, else the expiry.
|
|
14
|
+
CREATE INDEX core_pending_action_compact_idx
|
|
15
|
+
ON core_pending_action (coalesce(decided_at, expires_at))
|
|
16
|
+
WHERE compacted_at IS NULL AND status <> 'pending';
|
|
17
|
+
|
|
18
|
+
UPDATE core_meta SET value = '63' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
-- Migration 0064: MCP rate limits moved to the Workers Rate Limiting binding (ADR 0091, cost
|
|
2
|
+
-- audit F7, decision D4). Nothing writes the per-request D1 counter any more, so it is dropped.
|
|
3
|
+
DROP INDEX core_rate_limit_window_idx;
|
|
4
|
+
DROP TABLE core_rate_limit;
|
|
5
|
+
|
|
6
|
+
UPDATE core_meta SET value = '64' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
-- Migration 0065: the storage gauge's cache (ADR 0090). The daily cron, or an admin's refresh,
|
|
2
|
+
-- records the database size and the row counts of the big tables here, so Settings → Storage
|
|
3
|
+
-- reads one row instead of counting millions on every page view.
|
|
4
|
+
CREATE TABLE core_storage_stats (
|
|
5
|
+
id INTEGER PRIMARY KEY CHECK (id = 1),
|
|
6
|
+
-- D1's meta.size_after in bytes, or null where the runtime does not report it.
|
|
7
|
+
size_bytes INTEGER,
|
|
8
|
+
-- JSON {"core_audit": n, ...}.
|
|
9
|
+
tables TEXT NOT NULL CHECK (json_valid(tables)),
|
|
10
|
+
measured_at TEXT NOT NULL
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
UPDATE core_meta SET value = '65' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
-- Migration 0070: drop an unused index (docs/research/cloudflare-cost-audit.md, ADR 0043).
|
|
2
|
+
--
|
|
3
|
+
-- core_extension_proposals is read by action_id (its primary key) for the approval screen. Nothing
|
|
4
|
+
-- queries it by (extension_id, created_at), so the index only cost an extra row written per
|
|
5
|
+
-- proposal and its storage.
|
|
6
|
+
|
|
7
|
+
DROP INDEX IF EXISTS core_extension_proposals_ext_idx;
|
|
8
|
+
|
|
9
|
+
UPDATE core_meta SET value = '70' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
-- Migration 0080: view types and dashboards (stage 4a, ADR 0027, ADR 0056, ADR 0057).
|
|
2
|
+
--
|
|
3
|
+
-- 1. Saved views can be shared with the org. A view spec is now a discriminated union
|
|
4
|
+
-- (`table | board | calendar | gallery`); stored stage-1 table specs are already valid
|
|
5
|
+
-- (`{ "type": "table", ... }`), so no data changes.
|
|
6
|
+
ALTER TABLE core_views ADD COLUMN shared INTEGER NOT NULL DEFAULT 0 CHECK (shared IN (0, 1));
|
|
7
|
+
CREATE INDEX core_views_shared_object_idx ON core_views (object, position) WHERE shared = 1;
|
|
8
|
+
|
|
9
|
+
-- 2. Dashboards: a title, filters, a layout grid and widgets (`spec`, JSON), owned by a user and
|
|
10
|
+
-- private to them unless shared. The shipped Overview dashboard lives in code, not here.
|
|
11
|
+
CREATE TABLE core_dashboards (
|
|
12
|
+
id TEXT PRIMARY KEY NOT NULL,
|
|
13
|
+
owner_id TEXT NOT NULL REFERENCES core_user (id) ON DELETE CASCADE,
|
|
14
|
+
title TEXT NOT NULL CHECK (title <> ''),
|
|
15
|
+
description TEXT,
|
|
16
|
+
shared INTEGER NOT NULL DEFAULT 0 CHECK (shared IN (0, 1)),
|
|
17
|
+
spec TEXT NOT NULL CHECK (json_valid(spec)),
|
|
18
|
+
created_at TEXT NOT NULL,
|
|
19
|
+
updated_at TEXT NOT NULL
|
|
20
|
+
);
|
|
21
|
+
CREATE INDEX core_dashboards_owner_idx ON core_dashboards (owner_id, title);
|
|
22
|
+
CREATE INDEX core_dashboards_shared_idx ON core_dashboards (title) WHERE shared = 1;
|
|
23
|
+
|
|
24
|
+
-- 3. Each user's Home: the dashboard rendered at `/`. No row means the shipped Overview.
|
|
25
|
+
CREATE TABLE core_user_home (
|
|
26
|
+
user_id TEXT PRIMARY KEY NOT NULL REFERENCES core_user (id) ON DELETE CASCADE,
|
|
27
|
+
dashboard_id TEXT NOT NULL,
|
|
28
|
+
updated_at TEXT NOT NULL
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
-- 4. Typed extension settings (ADR 0058): one JSON object per extension, validated against the
|
|
32
|
+
-- `settings` its manifest declares.
|
|
33
|
+
CREATE TABLE core_extension_settings (
|
|
34
|
+
extension_id TEXT PRIMARY KEY NOT NULL,
|
|
35
|
+
value TEXT NOT NULL CHECK (json_valid(value)),
|
|
36
|
+
updated_at TEXT NOT NULL,
|
|
37
|
+
updated_by TEXT REFERENCES core_user (id) ON DELETE SET NULL
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
-- 5. Indexes the Overview dashboard's widgets need (ADR 0057: every widget query walks an
|
|
41
|
+
-- index). Partial on live rows, so Trash reads never pick them (see migration 0050).
|
|
42
|
+
CREATE INDEX core_person_created_idx ON core_person (created_at) WHERE deleted_at IS NULL;
|
|
43
|
+
CREATE INDEX core_organisation_created_idx ON core_organisation (created_at)
|
|
44
|
+
WHERE deleted_at IS NULL;
|
|
45
|
+
|
|
46
|
+
UPDATE core_meta SET value = '80' WHERE key = 'schema_version';
|
|
@@ -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';
|