@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,225 @@
|
|
|
1
|
+
-- Migration 0003: People, Organisations, Affiliations and Tags (ADR 0015, ADR 0018).
|
|
2
|
+
--
|
|
3
|
+
-- Conventions for every core record table from here on:
|
|
4
|
+
-- * id is a prefixed, time-sortable text id generated by @crm/core (per_, org_, aff_, ...).
|
|
5
|
+
-- * Timestamps are ISO-8601 UTC text (`2026-11-04T10:00:00.000Z`). Calendar dates are
|
|
6
|
+
-- `YYYY-MM-DD` text.
|
|
7
|
+
-- * Soft delete: `deleted_at` / `deleted_by`. Live rows have `deleted_at IS NULL`. Trash is the
|
|
8
|
+
-- set of soft-deleted rows; a scheduled purge hard-deletes them after 30 days.
|
|
9
|
+
-- * `merged_into_id` points a merged-away record at its survivor.
|
|
10
|
+
-- * Child rows (emails, phones, domains, addresses) are owned by their parent and replaced
|
|
11
|
+
-- wholesale by operations; they are hard-deleted with the parent on purge or erase.
|
|
12
|
+
-- * Uniqueness "across live records" uses a denormalised `live` flag on the child row, kept in
|
|
13
|
+
-- step with the parent's `deleted_at` by triggers, so a partial unique index can enforce it.
|
|
14
|
+
-- Restoring a parent whose email/domain has since been taken fails with a UNIQUE error.
|
|
15
|
+
|
|
16
|
+
-- People ---------------------------------------------------------------------------------------
|
|
17
|
+
|
|
18
|
+
CREATE TABLE core_person (
|
|
19
|
+
id TEXT PRIMARY KEY NOT NULL,
|
|
20
|
+
given_name TEXT,
|
|
21
|
+
family_name TEXT,
|
|
22
|
+
display_name TEXT NOT NULL,
|
|
23
|
+
location TEXT,
|
|
24
|
+
timezone TEXT,
|
|
25
|
+
-- JSON array of { network, url, handle? }.
|
|
26
|
+
social_profiles TEXT NOT NULL DEFAULT '[]' CHECK (json_valid(social_profiles)),
|
|
27
|
+
-- R2 object key of the avatar image.
|
|
28
|
+
avatar_key TEXT,
|
|
29
|
+
owner_id TEXT REFERENCES core_user (id) ON DELETE SET NULL,
|
|
30
|
+
-- Rich text, stored as Markdown.
|
|
31
|
+
description TEXT,
|
|
32
|
+
created_at TEXT NOT NULL,
|
|
33
|
+
created_by TEXT REFERENCES core_user (id) ON DELETE SET NULL,
|
|
34
|
+
updated_at TEXT NOT NULL,
|
|
35
|
+
deleted_at TEXT,
|
|
36
|
+
deleted_by TEXT REFERENCES core_user (id) ON DELETE SET NULL,
|
|
37
|
+
merged_into_id TEXT REFERENCES core_person (id) ON DELETE SET NULL
|
|
38
|
+
);
|
|
39
|
+
CREATE INDEX core_person_display_name_idx ON core_person (display_name COLLATE NOCASE, id);
|
|
40
|
+
CREATE INDEX core_person_owner_idx ON core_person (owner_id);
|
|
41
|
+
CREATE INDEX core_person_deleted_idx ON core_person (deleted_at);
|
|
42
|
+
|
|
43
|
+
CREATE TABLE core_person_emails (
|
|
44
|
+
id TEXT PRIMARY KEY NOT NULL,
|
|
45
|
+
person_id TEXT NOT NULL REFERENCES core_person (id) ON DELETE CASCADE,
|
|
46
|
+
-- Stored lower-cased and trimmed by the operation layer.
|
|
47
|
+
email TEXT NOT NULL CHECK (email = lower(trim(email)) AND email <> ''),
|
|
48
|
+
label TEXT,
|
|
49
|
+
is_primary INTEGER NOT NULL DEFAULT 0 CHECK (is_primary IN (0, 1)),
|
|
50
|
+
position INTEGER NOT NULL DEFAULT 0,
|
|
51
|
+
live INTEGER NOT NULL DEFAULT 1 CHECK (live IN (0, 1)),
|
|
52
|
+
created_at TEXT NOT NULL
|
|
53
|
+
);
|
|
54
|
+
CREATE INDEX core_person_emails_person_idx ON core_person_emails (person_id, position);
|
|
55
|
+
CREATE UNIQUE INDEX core_person_emails_live_email_uq ON core_person_emails (email) WHERE live = 1;
|
|
56
|
+
CREATE UNIQUE INDEX core_person_emails_primary_uq ON core_person_emails (person_id)
|
|
57
|
+
WHERE is_primary = 1;
|
|
58
|
+
CREATE UNIQUE INDEX core_person_emails_person_email_uq ON core_person_emails (person_id, email);
|
|
59
|
+
|
|
60
|
+
CREATE TABLE core_person_phones (
|
|
61
|
+
id TEXT PRIMARY KEY NOT NULL,
|
|
62
|
+
person_id TEXT NOT NULL REFERENCES core_person (id) ON DELETE CASCADE,
|
|
63
|
+
-- As entered; `number_normalised` holds digits and a leading + for matching.
|
|
64
|
+
number TEXT NOT NULL CHECK (number <> ''),
|
|
65
|
+
number_normalised TEXT NOT NULL,
|
|
66
|
+
label TEXT,
|
|
67
|
+
is_primary INTEGER NOT NULL DEFAULT 0 CHECK (is_primary IN (0, 1)),
|
|
68
|
+
position INTEGER NOT NULL DEFAULT 0,
|
|
69
|
+
created_at TEXT NOT NULL
|
|
70
|
+
);
|
|
71
|
+
CREATE INDEX core_person_phones_person_idx ON core_person_phones (person_id, position);
|
|
72
|
+
CREATE INDEX core_person_phones_number_idx ON core_person_phones (number_normalised);
|
|
73
|
+
CREATE UNIQUE INDEX core_person_phones_primary_uq ON core_person_phones (person_id)
|
|
74
|
+
WHERE is_primary = 1;
|
|
75
|
+
|
|
76
|
+
CREATE TRIGGER core_person_emails_live_on_insert
|
|
77
|
+
AFTER INSERT ON core_person_emails
|
|
78
|
+
WHEN (SELECT deleted_at FROM core_person WHERE id = NEW.person_id) IS NOT NULL
|
|
79
|
+
BEGIN
|
|
80
|
+
UPDATE core_person_emails SET live = 0 WHERE id = NEW.id;
|
|
81
|
+
END;
|
|
82
|
+
|
|
83
|
+
CREATE TRIGGER core_person_emails_live_on_delete
|
|
84
|
+
AFTER UPDATE OF deleted_at ON core_person
|
|
85
|
+
WHEN (OLD.deleted_at IS NULL) <> (NEW.deleted_at IS NULL)
|
|
86
|
+
BEGIN
|
|
87
|
+
UPDATE core_person_emails SET live = (NEW.deleted_at IS NULL) WHERE person_id = NEW.id;
|
|
88
|
+
END;
|
|
89
|
+
|
|
90
|
+
-- Organisations --------------------------------------------------------------------------------
|
|
91
|
+
|
|
92
|
+
CREATE TABLE core_organisation (
|
|
93
|
+
id TEXT PRIMARY KEY NOT NULL,
|
|
94
|
+
name TEXT NOT NULL CHECK (name <> ''),
|
|
95
|
+
website TEXT,
|
|
96
|
+
industry TEXT,
|
|
97
|
+
parent_id TEXT REFERENCES core_organisation (id) ON DELETE SET NULL CHECK (parent_id <> id),
|
|
98
|
+
-- R2 object key of the logo.
|
|
99
|
+
avatar_key TEXT,
|
|
100
|
+
owner_id TEXT REFERENCES core_user (id) ON DELETE SET NULL,
|
|
101
|
+
-- Rich text, stored as Markdown.
|
|
102
|
+
description TEXT,
|
|
103
|
+
created_at TEXT NOT NULL,
|
|
104
|
+
created_by TEXT REFERENCES core_user (id) ON DELETE SET NULL,
|
|
105
|
+
updated_at TEXT NOT NULL,
|
|
106
|
+
deleted_at TEXT,
|
|
107
|
+
deleted_by TEXT REFERENCES core_user (id) ON DELETE SET NULL,
|
|
108
|
+
merged_into_id TEXT REFERENCES core_organisation (id) ON DELETE SET NULL
|
|
109
|
+
);
|
|
110
|
+
CREATE INDEX core_organisation_name_idx ON core_organisation (name COLLATE NOCASE, id);
|
|
111
|
+
CREATE INDEX core_organisation_parent_idx ON core_organisation (parent_id);
|
|
112
|
+
CREATE INDEX core_organisation_owner_idx ON core_organisation (owner_id);
|
|
113
|
+
CREATE INDEX core_organisation_deleted_idx ON core_organisation (deleted_at);
|
|
114
|
+
|
|
115
|
+
CREATE TABLE core_organisation_domains (
|
|
116
|
+
id TEXT PRIMARY KEY NOT NULL,
|
|
117
|
+
organisation_id TEXT NOT NULL REFERENCES core_organisation (id) ON DELETE CASCADE,
|
|
118
|
+
-- Bare host, lower-cased, no scheme or `www.` (normalised by the operation layer).
|
|
119
|
+
domain TEXT NOT NULL CHECK (domain = lower(trim(domain)) AND domain <> ''),
|
|
120
|
+
is_primary INTEGER NOT NULL DEFAULT 0 CHECK (is_primary IN (0, 1)),
|
|
121
|
+
position INTEGER NOT NULL DEFAULT 0,
|
|
122
|
+
live INTEGER NOT NULL DEFAULT 1 CHECK (live IN (0, 1)),
|
|
123
|
+
created_at TEXT NOT NULL
|
|
124
|
+
);
|
|
125
|
+
CREATE INDEX core_organisation_domains_org_idx ON core_organisation_domains (organisation_id, position);
|
|
126
|
+
CREATE UNIQUE INDEX core_organisation_domains_live_domain_uq ON core_organisation_domains (domain)
|
|
127
|
+
WHERE live = 1;
|
|
128
|
+
CREATE UNIQUE INDEX core_organisation_domains_primary_uq ON core_organisation_domains (organisation_id)
|
|
129
|
+
WHERE is_primary = 1;
|
|
130
|
+
CREATE UNIQUE INDEX core_organisation_domains_org_domain_uq
|
|
131
|
+
ON core_organisation_domains (organisation_id, domain);
|
|
132
|
+
|
|
133
|
+
CREATE TRIGGER core_organisation_domains_live_on_insert
|
|
134
|
+
AFTER INSERT ON core_organisation_domains
|
|
135
|
+
WHEN (SELECT deleted_at FROM core_organisation WHERE id = NEW.organisation_id) IS NOT NULL
|
|
136
|
+
BEGIN
|
|
137
|
+
UPDATE core_organisation_domains SET live = 0 WHERE id = NEW.id;
|
|
138
|
+
END;
|
|
139
|
+
|
|
140
|
+
CREATE TRIGGER core_organisation_domains_live_on_delete
|
|
141
|
+
AFTER UPDATE OF deleted_at ON core_organisation
|
|
142
|
+
WHEN (OLD.deleted_at IS NULL) <> (NEW.deleted_at IS NULL)
|
|
143
|
+
BEGIN
|
|
144
|
+
UPDATE core_organisation_domains SET live = (NEW.deleted_at IS NULL)
|
|
145
|
+
WHERE organisation_id = NEW.id;
|
|
146
|
+
END;
|
|
147
|
+
|
|
148
|
+
CREATE TABLE core_organisation_addresses (
|
|
149
|
+
id TEXT PRIMARY KEY NOT NULL,
|
|
150
|
+
organisation_id TEXT NOT NULL REFERENCES core_organisation (id) ON DELETE CASCADE,
|
|
151
|
+
label TEXT,
|
|
152
|
+
line1 TEXT,
|
|
153
|
+
line2 TEXT,
|
|
154
|
+
city TEXT,
|
|
155
|
+
region TEXT,
|
|
156
|
+
postal_code TEXT,
|
|
157
|
+
-- ISO 3166-1 alpha-2 where known.
|
|
158
|
+
country TEXT,
|
|
159
|
+
is_primary INTEGER NOT NULL DEFAULT 0 CHECK (is_primary IN (0, 1)),
|
|
160
|
+
position INTEGER NOT NULL DEFAULT 0,
|
|
161
|
+
created_at TEXT NOT NULL
|
|
162
|
+
);
|
|
163
|
+
CREATE INDEX core_organisation_addresses_org_idx ON core_organisation_addresses (organisation_id, position);
|
|
164
|
+
CREATE UNIQUE INDEX core_organisation_addresses_primary_uq ON core_organisation_addresses (organisation_id)
|
|
165
|
+
WHERE is_primary = 1;
|
|
166
|
+
|
|
167
|
+
-- Affiliations ---------------------------------------------------------------------------------
|
|
168
|
+
-- A Person's link to an Organisation. Ending one and starting another is a job change.
|
|
169
|
+
|
|
170
|
+
CREATE TABLE core_affiliation (
|
|
171
|
+
id TEXT PRIMARY KEY NOT NULL,
|
|
172
|
+
person_id TEXT NOT NULL REFERENCES core_person (id) ON DELETE CASCADE,
|
|
173
|
+
organisation_id TEXT NOT NULL REFERENCES core_organisation (id) ON DELETE CASCADE,
|
|
174
|
+
-- Job title, e.g. "Head of Sales".
|
|
175
|
+
title TEXT,
|
|
176
|
+
-- Free-text role in the relationship, e.g. "Decision maker".
|
|
177
|
+
role TEXT,
|
|
178
|
+
started_on TEXT,
|
|
179
|
+
ended_on TEXT,
|
|
180
|
+
is_current INTEGER NOT NULL DEFAULT 1 CHECK (is_current IN (0, 1)),
|
|
181
|
+
is_primary INTEGER NOT NULL DEFAULT 0 CHECK (is_primary IN (0, 1)),
|
|
182
|
+
created_at TEXT NOT NULL,
|
|
183
|
+
created_by TEXT REFERENCES core_user (id) ON DELETE SET NULL,
|
|
184
|
+
updated_at TEXT NOT NULL,
|
|
185
|
+
deleted_at TEXT,
|
|
186
|
+
deleted_by TEXT REFERENCES core_user (id) ON DELETE SET NULL
|
|
187
|
+
);
|
|
188
|
+
CREATE INDEX core_affiliation_person_idx ON core_affiliation (person_id);
|
|
189
|
+
CREATE INDEX core_affiliation_org_idx ON core_affiliation (organisation_id);
|
|
190
|
+
CREATE UNIQUE INDEX core_affiliation_primary_uq ON core_affiliation (person_id)
|
|
191
|
+
WHERE is_primary = 1 AND deleted_at IS NULL;
|
|
192
|
+
|
|
193
|
+
-- Tags -----------------------------------------------------------------------------------------
|
|
194
|
+
-- One org-wide tag vocabulary, applied to any record through a polymorphic link (object type +
|
|
195
|
+
-- record id), so extension objects can be tagged later without schema changes.
|
|
196
|
+
|
|
197
|
+
CREATE TABLE core_tags (
|
|
198
|
+
id TEXT PRIMARY KEY NOT NULL,
|
|
199
|
+
name TEXT NOT NULL COLLATE NOCASE UNIQUE CHECK (name = trim(name) AND name <> ''),
|
|
200
|
+
color TEXT,
|
|
201
|
+
created_at TEXT NOT NULL,
|
|
202
|
+
created_by TEXT REFERENCES core_user (id) ON DELETE SET NULL
|
|
203
|
+
);
|
|
204
|
+
|
|
205
|
+
CREATE TABLE core_record_tags (
|
|
206
|
+
tag_id TEXT NOT NULL REFERENCES core_tags (id) ON DELETE CASCADE,
|
|
207
|
+
object_type TEXT NOT NULL,
|
|
208
|
+
record_id TEXT NOT NULL,
|
|
209
|
+
created_at TEXT NOT NULL,
|
|
210
|
+
PRIMARY KEY (object_type, record_id, tag_id)
|
|
211
|
+
);
|
|
212
|
+
CREATE INDEX core_record_tags_tag_idx ON core_record_tags (tag_id, object_type);
|
|
213
|
+
|
|
214
|
+
-- Hard-deleting a core record (purge or erase) removes its tag links.
|
|
215
|
+
CREATE TRIGGER core_person_purge_tags AFTER DELETE ON core_person
|
|
216
|
+
BEGIN
|
|
217
|
+
DELETE FROM core_record_tags WHERE object_type = 'person' AND record_id = OLD.id;
|
|
218
|
+
END;
|
|
219
|
+
|
|
220
|
+
CREATE TRIGGER core_organisation_purge_tags AFTER DELETE ON core_organisation
|
|
221
|
+
BEGIN
|
|
222
|
+
DELETE FROM core_record_tags WHERE object_type = 'organisation' AND record_id = OLD.id;
|
|
223
|
+
END;
|
|
224
|
+
|
|
225
|
+
UPDATE core_meta SET value = '3' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
-- Migration 0004: Activities and Tasks, linked to records polymorphically (ADR 0015).
|
|
2
|
+
--
|
|
3
|
+
-- Links are (object_type, record_id) pairs, not foreign keys, so extension objects can be linked
|
|
4
|
+
-- later. object_type is the object's registry name: 'person', 'organisation', 'task', or an
|
|
5
|
+
-- extension object's name.
|
|
6
|
+
|
|
7
|
+
CREATE TABLE core_activity (
|
|
8
|
+
id TEXT PRIMARY KEY NOT NULL,
|
|
9
|
+
type TEXT NOT NULL CHECK (type IN ('note', 'email', 'call', 'meeting', 'system')),
|
|
10
|
+
-- Short headline: an email subject, meeting title, or a system event summary.
|
|
11
|
+
subject TEXT,
|
|
12
|
+
-- Plain-text or Markdown body (notes, email text, call notes). Indexed for search.
|
|
13
|
+
body TEXT,
|
|
14
|
+
-- Typed per `type` (validated by the operation layer), e.g. email headers, call duration,
|
|
15
|
+
-- or a system event's field changes.
|
|
16
|
+
payload TEXT NOT NULL DEFAULT '{}' CHECK (json_valid(payload)),
|
|
17
|
+
occurred_at TEXT NOT NULL,
|
|
18
|
+
-- The user the activity is attributed to (null for automation or system events).
|
|
19
|
+
author_user_id TEXT REFERENCES core_user (id) ON DELETE SET NULL,
|
|
20
|
+
-- Who caused it: human | assistant | mcp | automation | system.
|
|
21
|
+
author_actor TEXT NOT NULL DEFAULT 'human'
|
|
22
|
+
CHECK (author_actor IN ('human', 'assistant', 'mcp', 'automation', 'system')),
|
|
23
|
+
created_at TEXT NOT NULL,
|
|
24
|
+
updated_at TEXT NOT NULL,
|
|
25
|
+
deleted_at TEXT,
|
|
26
|
+
deleted_by TEXT REFERENCES core_user (id) ON DELETE SET NULL
|
|
27
|
+
);
|
|
28
|
+
CREATE INDEX core_activity_occurred_idx ON core_activity (occurred_at, id);
|
|
29
|
+
CREATE INDEX core_activity_type_idx ON core_activity (type);
|
|
30
|
+
CREATE INDEX core_activity_deleted_idx ON core_activity (deleted_at);
|
|
31
|
+
|
|
32
|
+
CREATE TABLE core_activity_links (
|
|
33
|
+
activity_id TEXT NOT NULL REFERENCES core_activity (id) ON DELETE CASCADE,
|
|
34
|
+
object_type TEXT NOT NULL,
|
|
35
|
+
record_id TEXT NOT NULL,
|
|
36
|
+
PRIMARY KEY (activity_id, object_type, record_id)
|
|
37
|
+
);
|
|
38
|
+
CREATE INDEX core_activity_links_record_idx ON core_activity_links (object_type, record_id, activity_id);
|
|
39
|
+
|
|
40
|
+
CREATE TABLE core_task (
|
|
41
|
+
id TEXT PRIMARY KEY NOT NULL,
|
|
42
|
+
title TEXT NOT NULL CHECK (title <> ''),
|
|
43
|
+
notes TEXT,
|
|
44
|
+
-- A date (`YYYY-MM-DD`) or an ISO timestamp.
|
|
45
|
+
due_at TEXT,
|
|
46
|
+
status TEXT NOT NULL DEFAULT 'open' CHECK (status IN ('open', 'done')),
|
|
47
|
+
completed_at TEXT,
|
|
48
|
+
completed_by TEXT REFERENCES core_user (id) ON DELETE SET NULL,
|
|
49
|
+
assignee_id TEXT REFERENCES core_user (id) ON DELETE SET NULL,
|
|
50
|
+
created_at TEXT NOT NULL,
|
|
51
|
+
created_by TEXT REFERENCES core_user (id) ON DELETE SET NULL,
|
|
52
|
+
updated_at TEXT NOT NULL,
|
|
53
|
+
deleted_at TEXT,
|
|
54
|
+
deleted_by TEXT REFERENCES core_user (id) ON DELETE SET NULL
|
|
55
|
+
);
|
|
56
|
+
CREATE INDEX core_task_assignee_idx ON core_task (assignee_id, status, due_at);
|
|
57
|
+
CREATE INDEX core_task_due_idx ON core_task (status, due_at);
|
|
58
|
+
CREATE INDEX core_task_deleted_idx ON core_task (deleted_at);
|
|
59
|
+
|
|
60
|
+
CREATE TABLE core_task_links (
|
|
61
|
+
task_id TEXT NOT NULL REFERENCES core_task (id) ON DELETE CASCADE,
|
|
62
|
+
object_type TEXT NOT NULL,
|
|
63
|
+
record_id TEXT NOT NULL,
|
|
64
|
+
PRIMARY KEY (task_id, object_type, record_id)
|
|
65
|
+
);
|
|
66
|
+
CREATE INDEX core_task_links_record_idx ON core_task_links (object_type, record_id, task_id);
|
|
67
|
+
|
|
68
|
+
-- Hard-deleting a record (purge or erase) removes links that point at it. The activities and
|
|
69
|
+
-- tasks themselves stay; the purge decides what to do with ones left unlinked.
|
|
70
|
+
CREATE TRIGGER core_person_purge_links AFTER DELETE ON core_person
|
|
71
|
+
BEGIN
|
|
72
|
+
DELETE FROM core_activity_links WHERE object_type = 'person' AND record_id = OLD.id;
|
|
73
|
+
DELETE FROM core_task_links WHERE object_type = 'person' AND record_id = OLD.id;
|
|
74
|
+
END;
|
|
75
|
+
|
|
76
|
+
CREATE TRIGGER core_organisation_purge_links AFTER DELETE ON core_organisation
|
|
77
|
+
BEGIN
|
|
78
|
+
DELETE FROM core_activity_links WHERE object_type = 'organisation' AND record_id = OLD.id;
|
|
79
|
+
DELETE FROM core_task_links WHERE object_type = 'organisation' AND record_id = OLD.id;
|
|
80
|
+
END;
|
|
81
|
+
|
|
82
|
+
CREATE TRIGGER core_task_purge_links AFTER DELETE ON core_task
|
|
83
|
+
BEGIN
|
|
84
|
+
DELETE FROM core_activity_links WHERE object_type = 'task' AND record_id = OLD.id;
|
|
85
|
+
DELETE FROM core_record_tags WHERE object_type = 'task' AND record_id = OLD.id;
|
|
86
|
+
END;
|
|
87
|
+
|
|
88
|
+
UPDATE core_meta SET value = '4' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
-- Migration 0005: saved views and the audit log (ADR 0016, ADR 0017, ADR 0018).
|
|
2
|
+
|
|
3
|
+
-- Saved views: a user's stored list configuration. `spec` is a `table`-type view spec
|
|
4
|
+
-- `{ "type": "table", "object", "filter", "sort", "columns" }` that stage 4 extends.
|
|
5
|
+
CREATE TABLE core_views (
|
|
6
|
+
id TEXT PRIMARY KEY NOT NULL,
|
|
7
|
+
user_id TEXT NOT NULL REFERENCES core_user (id) ON DELETE CASCADE,
|
|
8
|
+
object TEXT NOT NULL,
|
|
9
|
+
name TEXT NOT NULL CHECK (name <> ''),
|
|
10
|
+
spec TEXT NOT NULL CHECK (json_valid(spec)),
|
|
11
|
+
position INTEGER NOT NULL DEFAULT 0,
|
|
12
|
+
created_at TEXT NOT NULL,
|
|
13
|
+
updated_at TEXT NOT NULL
|
|
14
|
+
);
|
|
15
|
+
CREATE INDEX core_views_user_object_idx ON core_views (user_id, object, position);
|
|
16
|
+
|
|
17
|
+
-- Audit log: one row per operation invocation (successful writes, every denial, and reads by
|
|
18
|
+
-- non-human actors). Append-only: UPDATE and DELETE are refused by triggers.
|
|
19
|
+
CREATE TABLE core_audit (
|
|
20
|
+
id TEXT PRIMARY KEY NOT NULL,
|
|
21
|
+
at TEXT NOT NULL,
|
|
22
|
+
operation TEXT NOT NULL,
|
|
23
|
+
risk TEXT NOT NULL
|
|
24
|
+
CHECK (risk IN ('read', 'write', 'bulk-write', 'destructive', 'schema', 'extension', 'outbound')),
|
|
25
|
+
actor TEXT NOT NULL CHECK (actor IN ('human', 'assistant', 'mcp', 'automation')),
|
|
26
|
+
user_id TEXT,
|
|
27
|
+
-- JSON `{ surface: "ui" | "mcp" | "automation" | "system", clientId?, automationId? }`.
|
|
28
|
+
origin TEXT NOT NULL CHECK (json_valid(origin)),
|
|
29
|
+
-- Validated input with secrets redacted.
|
|
30
|
+
input TEXT NOT NULL CHECK (json_valid(input)),
|
|
31
|
+
-- A small summary of the output (ids, counts), not the full result.
|
|
32
|
+
result TEXT CHECK (result IS NULL OR json_valid(result)),
|
|
33
|
+
gate_decision TEXT NOT NULL CHECK (gate_decision IN ('auto', 'review', 'deny')),
|
|
34
|
+
-- ok: applied. forbidden: refused by role or actor rules. denied: refused by the gate.
|
|
35
|
+
-- review: routed to review (not yet supported in stage 1). error: failed and rolled back.
|
|
36
|
+
outcome TEXT NOT NULL CHECK (outcome IN ('ok', 'forbidden', 'denied', 'review', 'error')),
|
|
37
|
+
error TEXT CHECK (error IS NULL OR json_valid(error))
|
|
38
|
+
);
|
|
39
|
+
CREATE INDEX core_audit_at_idx ON core_audit (at, id);
|
|
40
|
+
CREATE INDEX core_audit_user_idx ON core_audit (user_id, at);
|
|
41
|
+
CREATE INDEX core_audit_operation_idx ON core_audit (operation, at);
|
|
42
|
+
CREATE INDEX core_audit_actor_idx ON core_audit (actor, at);
|
|
43
|
+
|
|
44
|
+
-- Field-level changes, one row per record an audited operation touched. The record History tab
|
|
45
|
+
-- reads these by (object_type, record_id).
|
|
46
|
+
CREATE TABLE core_audit_changes (
|
|
47
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
48
|
+
audit_id TEXT NOT NULL REFERENCES core_audit (id),
|
|
49
|
+
object_type TEXT NOT NULL,
|
|
50
|
+
record_id TEXT NOT NULL,
|
|
51
|
+
action TEXT NOT NULL CHECK (action IN ('create', 'update', 'delete', 'restore', 'erase', 'merge')),
|
|
52
|
+
-- JSON `{ "<field>": { "before": ..., "after": ... } }` for changed fields only.
|
|
53
|
+
diff TEXT NOT NULL CHECK (json_valid(diff)),
|
|
54
|
+
at TEXT NOT NULL
|
|
55
|
+
);
|
|
56
|
+
CREATE INDEX core_audit_changes_record_idx ON core_audit_changes (object_type, record_id, id);
|
|
57
|
+
CREATE INDEX core_audit_changes_audit_idx ON core_audit_changes (audit_id);
|
|
58
|
+
|
|
59
|
+
CREATE TRIGGER core_audit_no_update BEFORE UPDATE ON core_audit
|
|
60
|
+
BEGIN
|
|
61
|
+
SELECT RAISE(ABORT, 'core_audit is append-only');
|
|
62
|
+
END;
|
|
63
|
+
|
|
64
|
+
CREATE TRIGGER core_audit_no_delete BEFORE DELETE ON core_audit
|
|
65
|
+
BEGIN
|
|
66
|
+
SELECT RAISE(ABORT, 'core_audit is append-only');
|
|
67
|
+
END;
|
|
68
|
+
|
|
69
|
+
CREATE TRIGGER core_audit_changes_no_update BEFORE UPDATE ON core_audit_changes
|
|
70
|
+
BEGIN
|
|
71
|
+
SELECT RAISE(ABORT, 'core_audit_changes is append-only');
|
|
72
|
+
END;
|
|
73
|
+
|
|
74
|
+
CREATE TRIGGER core_audit_changes_no_delete BEFORE DELETE ON core_audit_changes
|
|
75
|
+
BEGIN
|
|
76
|
+
SELECT RAISE(ABORT, 'core_audit_changes is append-only');
|
|
77
|
+
END;
|
|
78
|
+
|
|
79
|
+
UPDATE core_meta SET value = '5' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
-- Migration 0006: full-text search (FTS5) over people, organisations, activities and tasks.
|
|
2
|
+
--
|
|
3
|
+
-- Two layers:
|
|
4
|
+
-- * core_search_docs: one plain row per live record (object_type, record_id, title, body).
|
|
5
|
+
-- Domain triggers below rebuild a record's row whenever it or its emails/domains change, and
|
|
6
|
+
-- drop it when the record is soft-deleted or purged.
|
|
7
|
+
-- * core_search: an external-content FTS5 index over core_search_docs, kept in step by the
|
|
8
|
+
-- standard external-content triggers. Query it with
|
|
9
|
+
-- SELECT d.object_type, d.record_id FROM core_search s
|
|
10
|
+
-- JOIN core_search_docs d ON d.id = s.rowid WHERE core_search MATCH ? ORDER BY rank
|
|
11
|
+
--
|
|
12
|
+
-- What is indexed: people (display, given and family names; all emails), organisations (name;
|
|
13
|
+
-- all domains), activities (subject, body) and tasks (title, notes). unicode61 splits emails and
|
|
14
|
+
-- domains on punctuation, so "ada", "example" and "com" are tokens; prefix indexes keep
|
|
15
|
+
-- type-ahead queries ("ad*") fast.
|
|
16
|
+
|
|
17
|
+
CREATE TABLE core_search_docs (
|
|
18
|
+
id INTEGER PRIMARY KEY,
|
|
19
|
+
object_type TEXT NOT NULL,
|
|
20
|
+
record_id TEXT NOT NULL,
|
|
21
|
+
title TEXT NOT NULL DEFAULT '',
|
|
22
|
+
body TEXT NOT NULL DEFAULT '',
|
|
23
|
+
UNIQUE (object_type, record_id)
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
CREATE VIRTUAL TABLE core_search USING fts5(
|
|
27
|
+
title,
|
|
28
|
+
body,
|
|
29
|
+
content = 'core_search_docs',
|
|
30
|
+
content_rowid = 'id',
|
|
31
|
+
tokenize = 'unicode61 remove_diacritics 2',
|
|
32
|
+
prefix = '2 3'
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
CREATE TRIGGER core_search_docs_ai AFTER INSERT ON core_search_docs
|
|
36
|
+
BEGIN
|
|
37
|
+
INSERT INTO core_search (rowid, title, body) VALUES (NEW.id, NEW.title, NEW.body);
|
|
38
|
+
END;
|
|
39
|
+
|
|
40
|
+
CREATE TRIGGER core_search_docs_ad AFTER DELETE ON core_search_docs
|
|
41
|
+
BEGIN
|
|
42
|
+
INSERT INTO core_search (core_search, rowid, title, body)
|
|
43
|
+
VALUES ('delete', OLD.id, OLD.title, OLD.body);
|
|
44
|
+
END;
|
|
45
|
+
|
|
46
|
+
CREATE TRIGGER core_search_docs_au AFTER UPDATE ON core_search_docs
|
|
47
|
+
BEGIN
|
|
48
|
+
INSERT INTO core_search (core_search, rowid, title, body)
|
|
49
|
+
VALUES ('delete', OLD.id, OLD.title, OLD.body);
|
|
50
|
+
INSERT INTO core_search (rowid, title, body) VALUES (NEW.id, NEW.title, NEW.body);
|
|
51
|
+
END;
|
|
52
|
+
|
|
53
|
+
-- person
|
|
54
|
+
CREATE TRIGGER core_person_search_ai AFTER INSERT ON core_person
|
|
55
|
+
BEGIN
|
|
56
|
+
DELETE FROM core_search_docs WHERE object_type = 'person' AND record_id = NEW.id;
|
|
57
|
+
INSERT INTO core_search_docs (object_type, record_id, title, body)
|
|
58
|
+
SELECT 'person', p.id,
|
|
59
|
+
trim(p.display_name || ' ' || coalesce(p.given_name, '') || ' ' || coalesce(p.family_name, '')),
|
|
60
|
+
coalesce((SELECT group_concat(e.email, ' ') FROM core_person_emails e WHERE e.person_id = p.id), '')
|
|
61
|
+
FROM core_person p WHERE p.id = NEW.id AND p.deleted_at IS NULL;
|
|
62
|
+
END;
|
|
63
|
+
|
|
64
|
+
CREATE TRIGGER core_person_search_au AFTER UPDATE OF display_name, given_name, family_name, deleted_at ON core_person
|
|
65
|
+
BEGIN
|
|
66
|
+
DELETE FROM core_search_docs WHERE object_type = 'person' AND record_id = NEW.id;
|
|
67
|
+
INSERT INTO core_search_docs (object_type, record_id, title, body)
|
|
68
|
+
SELECT 'person', p.id,
|
|
69
|
+
trim(p.display_name || ' ' || coalesce(p.given_name, '') || ' ' || coalesce(p.family_name, '')),
|
|
70
|
+
coalesce((SELECT group_concat(e.email, ' ') FROM core_person_emails e WHERE e.person_id = p.id), '')
|
|
71
|
+
FROM core_person p WHERE p.id = NEW.id AND p.deleted_at IS NULL;
|
|
72
|
+
END;
|
|
73
|
+
|
|
74
|
+
CREATE TRIGGER core_person_search_ad AFTER DELETE ON core_person
|
|
75
|
+
BEGIN
|
|
76
|
+
DELETE FROM core_search_docs WHERE object_type = 'person' AND record_id = OLD.id;
|
|
77
|
+
END;
|
|
78
|
+
|
|
79
|
+
-- organisation
|
|
80
|
+
CREATE TRIGGER core_organisation_search_ai AFTER INSERT ON core_organisation
|
|
81
|
+
BEGIN
|
|
82
|
+
DELETE FROM core_search_docs WHERE object_type = 'organisation' AND record_id = NEW.id;
|
|
83
|
+
INSERT INTO core_search_docs (object_type, record_id, title, body)
|
|
84
|
+
SELECT 'organisation', o.id, o.name,
|
|
85
|
+
coalesce((SELECT group_concat(d.domain, ' ') FROM core_organisation_domains d
|
|
86
|
+
WHERE d.organisation_id = o.id), '')
|
|
87
|
+
FROM core_organisation o WHERE o.id = NEW.id AND o.deleted_at IS NULL;
|
|
88
|
+
END;
|
|
89
|
+
|
|
90
|
+
CREATE TRIGGER core_organisation_search_au AFTER UPDATE OF name, deleted_at ON core_organisation
|
|
91
|
+
BEGIN
|
|
92
|
+
DELETE FROM core_search_docs WHERE object_type = 'organisation' AND record_id = NEW.id;
|
|
93
|
+
INSERT INTO core_search_docs (object_type, record_id, title, body)
|
|
94
|
+
SELECT 'organisation', o.id, o.name,
|
|
95
|
+
coalesce((SELECT group_concat(d.domain, ' ') FROM core_organisation_domains d
|
|
96
|
+
WHERE d.organisation_id = o.id), '')
|
|
97
|
+
FROM core_organisation o WHERE o.id = NEW.id AND o.deleted_at IS NULL;
|
|
98
|
+
END;
|
|
99
|
+
|
|
100
|
+
CREATE TRIGGER core_organisation_search_ad AFTER DELETE ON core_organisation
|
|
101
|
+
BEGIN
|
|
102
|
+
DELETE FROM core_search_docs WHERE object_type = 'organisation' AND record_id = OLD.id;
|
|
103
|
+
END;
|
|
104
|
+
|
|
105
|
+
-- activity
|
|
106
|
+
CREATE TRIGGER core_activity_search_ai AFTER INSERT ON core_activity
|
|
107
|
+
BEGIN
|
|
108
|
+
DELETE FROM core_search_docs WHERE object_type = 'activity' AND record_id = NEW.id;
|
|
109
|
+
INSERT INTO core_search_docs (object_type, record_id, title, body)
|
|
110
|
+
SELECT 'activity', a.id, coalesce(a.subject, ''), coalesce(a.body, '')
|
|
111
|
+
FROM core_activity a WHERE a.id = NEW.id AND a.deleted_at IS NULL;
|
|
112
|
+
END;
|
|
113
|
+
|
|
114
|
+
CREATE TRIGGER core_activity_search_au AFTER UPDATE OF subject, body, deleted_at ON core_activity
|
|
115
|
+
BEGIN
|
|
116
|
+
DELETE FROM core_search_docs WHERE object_type = 'activity' AND record_id = NEW.id;
|
|
117
|
+
INSERT INTO core_search_docs (object_type, record_id, title, body)
|
|
118
|
+
SELECT 'activity', a.id, coalesce(a.subject, ''), coalesce(a.body, '')
|
|
119
|
+
FROM core_activity a WHERE a.id = NEW.id AND a.deleted_at IS NULL;
|
|
120
|
+
END;
|
|
121
|
+
|
|
122
|
+
CREATE TRIGGER core_activity_search_ad AFTER DELETE ON core_activity
|
|
123
|
+
BEGIN
|
|
124
|
+
DELETE FROM core_search_docs WHERE object_type = 'activity' AND record_id = OLD.id;
|
|
125
|
+
END;
|
|
126
|
+
|
|
127
|
+
-- task
|
|
128
|
+
CREATE TRIGGER core_task_search_ai AFTER INSERT ON core_task
|
|
129
|
+
BEGIN
|
|
130
|
+
DELETE FROM core_search_docs WHERE object_type = 'task' AND record_id = NEW.id;
|
|
131
|
+
INSERT INTO core_search_docs (object_type, record_id, title, body)
|
|
132
|
+
SELECT 'task', t.id, t.title, coalesce(t.notes, '')
|
|
133
|
+
FROM core_task t WHERE t.id = NEW.id AND t.deleted_at IS NULL;
|
|
134
|
+
END;
|
|
135
|
+
|
|
136
|
+
CREATE TRIGGER core_task_search_au AFTER UPDATE OF title, notes, deleted_at ON core_task
|
|
137
|
+
BEGIN
|
|
138
|
+
DELETE FROM core_search_docs WHERE object_type = 'task' AND record_id = NEW.id;
|
|
139
|
+
INSERT INTO core_search_docs (object_type, record_id, title, body)
|
|
140
|
+
SELECT 'task', t.id, t.title, coalesce(t.notes, '')
|
|
141
|
+
FROM core_task t WHERE t.id = NEW.id AND t.deleted_at IS NULL;
|
|
142
|
+
END;
|
|
143
|
+
|
|
144
|
+
CREATE TRIGGER core_task_search_ad AFTER DELETE ON core_task
|
|
145
|
+
BEGIN
|
|
146
|
+
DELETE FROM core_search_docs WHERE object_type = 'task' AND record_id = OLD.id;
|
|
147
|
+
END;
|
|
148
|
+
|
|
149
|
+
-- person child rows
|
|
150
|
+
CREATE TRIGGER core_person_emails_search_ai AFTER INSERT ON core_person_emails
|
|
151
|
+
BEGIN
|
|
152
|
+
DELETE FROM core_search_docs WHERE object_type = 'person' AND record_id = NEW.person_id;
|
|
153
|
+
INSERT INTO core_search_docs (object_type, record_id, title, body)
|
|
154
|
+
SELECT 'person', p.id,
|
|
155
|
+
trim(p.display_name || ' ' || coalesce(p.given_name, '') || ' ' || coalesce(p.family_name, '')),
|
|
156
|
+
coalesce((SELECT group_concat(e.email, ' ') FROM core_person_emails e WHERE e.person_id = p.id), '')
|
|
157
|
+
FROM core_person p WHERE p.id = NEW.person_id AND p.deleted_at IS NULL;
|
|
158
|
+
END;
|
|
159
|
+
|
|
160
|
+
CREATE TRIGGER core_person_emails_search_au AFTER UPDATE ON core_person_emails
|
|
161
|
+
BEGIN
|
|
162
|
+
DELETE FROM core_search_docs WHERE object_type = 'person' AND record_id = OLD.person_id;
|
|
163
|
+
INSERT INTO core_search_docs (object_type, record_id, title, body)
|
|
164
|
+
SELECT 'person', p.id,
|
|
165
|
+
trim(p.display_name || ' ' || coalesce(p.given_name, '') || ' ' || coalesce(p.family_name, '')),
|
|
166
|
+
coalesce((SELECT group_concat(e.email, ' ') FROM core_person_emails e WHERE e.person_id = p.id), '')
|
|
167
|
+
FROM core_person p WHERE p.id = OLD.person_id AND p.deleted_at IS NULL;
|
|
168
|
+
DELETE FROM core_search_docs WHERE object_type = 'person' AND record_id = NEW.person_id;
|
|
169
|
+
INSERT INTO core_search_docs (object_type, record_id, title, body)
|
|
170
|
+
SELECT 'person', p.id,
|
|
171
|
+
trim(p.display_name || ' ' || coalesce(p.given_name, '') || ' ' || coalesce(p.family_name, '')),
|
|
172
|
+
coalesce((SELECT group_concat(e.email, ' ') FROM core_person_emails e WHERE e.person_id = p.id), '')
|
|
173
|
+
FROM core_person p WHERE p.id = NEW.person_id AND p.deleted_at IS NULL;
|
|
174
|
+
END;
|
|
175
|
+
|
|
176
|
+
CREATE TRIGGER core_person_emails_search_ad AFTER DELETE ON core_person_emails
|
|
177
|
+
BEGIN
|
|
178
|
+
DELETE FROM core_search_docs WHERE object_type = 'person' AND record_id = OLD.person_id;
|
|
179
|
+
INSERT INTO core_search_docs (object_type, record_id, title, body)
|
|
180
|
+
SELECT 'person', p.id,
|
|
181
|
+
trim(p.display_name || ' ' || coalesce(p.given_name, '') || ' ' || coalesce(p.family_name, '')),
|
|
182
|
+
coalesce((SELECT group_concat(e.email, ' ') FROM core_person_emails e WHERE e.person_id = p.id), '')
|
|
183
|
+
FROM core_person p WHERE p.id = OLD.person_id AND p.deleted_at IS NULL;
|
|
184
|
+
END;
|
|
185
|
+
|
|
186
|
+
-- organisation child rows
|
|
187
|
+
CREATE TRIGGER core_organisation_domains_search_ai AFTER INSERT ON core_organisation_domains
|
|
188
|
+
BEGIN
|
|
189
|
+
DELETE FROM core_search_docs WHERE object_type = 'organisation' AND record_id = NEW.organisation_id;
|
|
190
|
+
INSERT INTO core_search_docs (object_type, record_id, title, body)
|
|
191
|
+
SELECT 'organisation', o.id, o.name,
|
|
192
|
+
coalesce((SELECT group_concat(d.domain, ' ') FROM core_organisation_domains d
|
|
193
|
+
WHERE d.organisation_id = o.id), '')
|
|
194
|
+
FROM core_organisation o WHERE o.id = NEW.organisation_id AND o.deleted_at IS NULL;
|
|
195
|
+
END;
|
|
196
|
+
|
|
197
|
+
CREATE TRIGGER core_organisation_domains_search_au AFTER UPDATE ON core_organisation_domains
|
|
198
|
+
BEGIN
|
|
199
|
+
DELETE FROM core_search_docs WHERE object_type = 'organisation' AND record_id = OLD.organisation_id;
|
|
200
|
+
INSERT INTO core_search_docs (object_type, record_id, title, body)
|
|
201
|
+
SELECT 'organisation', o.id, o.name,
|
|
202
|
+
coalesce((SELECT group_concat(d.domain, ' ') FROM core_organisation_domains d
|
|
203
|
+
WHERE d.organisation_id = o.id), '')
|
|
204
|
+
FROM core_organisation o WHERE o.id = OLD.organisation_id AND o.deleted_at IS NULL;
|
|
205
|
+
DELETE FROM core_search_docs WHERE object_type = 'organisation' AND record_id = NEW.organisation_id;
|
|
206
|
+
INSERT INTO core_search_docs (object_type, record_id, title, body)
|
|
207
|
+
SELECT 'organisation', o.id, o.name,
|
|
208
|
+
coalesce((SELECT group_concat(d.domain, ' ') FROM core_organisation_domains d
|
|
209
|
+
WHERE d.organisation_id = o.id), '')
|
|
210
|
+
FROM core_organisation o WHERE o.id = NEW.organisation_id AND o.deleted_at IS NULL;
|
|
211
|
+
END;
|
|
212
|
+
|
|
213
|
+
CREATE TRIGGER core_organisation_domains_search_ad AFTER DELETE ON core_organisation_domains
|
|
214
|
+
BEGIN
|
|
215
|
+
DELETE FROM core_search_docs WHERE object_type = 'organisation' AND record_id = OLD.organisation_id;
|
|
216
|
+
INSERT INTO core_search_docs (object_type, record_id, title, body)
|
|
217
|
+
SELECT 'organisation', o.id, o.name,
|
|
218
|
+
coalesce((SELECT group_concat(d.domain, ' ') FROM core_organisation_domains d
|
|
219
|
+
WHERE d.organisation_id = o.id), '')
|
|
220
|
+
FROM core_organisation o WHERE o.id = OLD.organisation_id AND o.deleted_at IS NULL;
|
|
221
|
+
END;
|
|
222
|
+
|
|
223
|
+
UPDATE core_meta SET value = '6' WHERE key = 'schema_version';
|