@intelligo-dev/core 1.0.0-beta.1 → 1.0.0-beta.13
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/NOTICE +6 -0
- package/README.md +102 -0
- package/dist/attachments/errors.d.ts +7 -0
- package/dist/attachments/errors.d.ts.map +1 -0
- package/dist/attachments/errors.js +11 -0
- package/dist/attachments/errors.js.map +1 -0
- package/dist/attachments/index.d.ts +8 -0
- package/dist/attachments/index.d.ts.map +1 -0
- package/dist/attachments/index.js +7 -0
- package/dist/attachments/index.js.map +1 -0
- package/dist/attachments/service.d.ts +45 -0
- package/dist/attachments/service.d.ts.map +1 -0
- package/dist/attachments/service.js +100 -0
- package/dist/attachments/service.js.map +1 -0
- package/dist/attachments/types.d.ts +6 -0
- package/dist/attachments/types.d.ts.map +1 -0
- package/dist/attachments/types.js +2 -0
- package/dist/attachments/types.js.map +1 -0
- package/dist/conversations/errors.d.ts +2 -8
- package/dist/conversations/errors.d.ts.map +1 -1
- package/dist/conversations/errors.js +2 -8
- package/dist/conversations/errors.js.map +1 -1
- package/dist/conversations/index.d.ts +4 -12
- package/dist/conversations/index.d.ts.map +1 -1
- package/dist/conversations/index.js +2 -11
- package/dist/conversations/index.js.map +1 -1
- package/dist/conversations/service.d.ts +49 -61
- package/dist/conversations/service.d.ts.map +1 -1
- package/dist/conversations/service.js +110 -83
- package/dist/conversations/service.js.map +1 -1
- package/dist/conversations/types.d.ts +1 -4
- package/dist/conversations/types.d.ts.map +1 -1
- package/dist/conversations/types.js +0 -3
- package/dist/conversations/types.js.map +1 -1
- package/dist/db/client.d.ts +21 -10
- package/dist/db/client.d.ts.map +1 -1
- package/dist/db/client.js +43 -18
- package/dist/db/client.js.map +1 -1
- package/dist/db/index.d.ts +3 -3
- package/dist/db/index.d.ts.map +1 -1
- package/dist/db/index.js +3 -7
- package/dist/db/index.js.map +1 -1
- package/dist/db/schema/agents.d.ts +14 -51
- package/dist/db/schema/agents.d.ts.map +1 -1
- package/dist/db/schema/agents.js +9 -21
- package/dist/db/schema/agents.js.map +1 -1
- package/dist/db/schema/ai.d.ts +86 -1556
- package/dist/db/schema/ai.d.ts.map +1 -1
- package/dist/db/schema/ai.js +32 -236
- package/dist/db/schema/ai.js.map +1 -1
- package/dist/db/schema/auth.d.ts +5 -34
- package/dist/db/schema/auth.d.ts.map +1 -1
- package/dist/db/schema/auth.js +25 -56
- package/dist/db/schema/auth.js.map +1 -1
- package/dist/db/schema/billing.d.ts +136 -107
- package/dist/db/schema/billing.d.ts.map +1 -1
- package/dist/db/schema/billing.js +72 -60
- package/dist/db/schema/billing.js.map +1 -1
- package/dist/db/schema/feature-flags.d.ts +3 -12
- package/dist/db/schema/feature-flags.d.ts.map +1 -1
- package/dist/db/schema/feature-flags.js +3 -12
- package/dist/db/schema/feature-flags.js.map +1 -1
- package/dist/db/schema/identity.d.ts +12 -274
- package/dist/db/schema/identity.d.ts.map +1 -1
- package/dist/db/schema/identity.js +19 -104
- package/dist/db/schema/identity.js.map +1 -1
- package/dist/db/schema/index.d.ts +8 -15
- package/dist/db/schema/index.d.ts.map +1 -1
- package/dist/db/schema/index.js +12 -42
- package/dist/db/schema/index.js.map +1 -1
- package/dist/db/schema/notifications.d.ts +3 -17
- package/dist/db/schema/notifications.d.ts.map +1 -1
- package/dist/db/schema/notifications.js +3 -17
- package/dist/db/schema/notifications.js.map +1 -1
- package/dist/db/schema/usage.d.ts +94 -77
- package/dist/db/schema/usage.d.ts.map +1 -1
- package/dist/db/schema/usage.js +59 -89
- package/dist/db/schema/usage.js.map +1 -1
- package/dist/db/validate.d.ts +2 -11
- package/dist/db/validate.d.ts.map +1 -1
- package/dist/db/validate.js +6 -17
- package/dist/db/validate.js.map +1 -1
- package/dist/db/workspace-queries.d.ts +5 -29
- package/dist/db/workspace-queries.d.ts.map +1 -1
- package/dist/db/workspace-queries.js +5 -29
- package/dist/db/workspace-queries.js.map +1 -1
- package/dist/documents/classifier.d.ts +5 -12
- package/dist/documents/classifier.d.ts.map +1 -1
- package/dist/documents/classifier.js +16 -16
- package/dist/documents/classifier.js.map +1 -1
- package/dist/documents/errors.d.ts +2 -10
- package/dist/documents/errors.d.ts.map +1 -1
- package/dist/documents/errors.js +2 -10
- package/dist/documents/errors.js.map +1 -1
- package/dist/documents/index.d.ts +4 -13
- package/dist/documents/index.d.ts.map +1 -1
- package/dist/documents/index.js +3 -12
- package/dist/documents/index.js.map +1 -1
- package/dist/documents/service.d.ts +19 -26
- package/dist/documents/service.d.ts.map +1 -1
- package/dist/documents/service.js +44 -38
- package/dist/documents/service.js.map +1 -1
- package/dist/documents/types.d.ts +6 -10
- package/dist/documents/types.d.ts.map +1 -1
- package/dist/documents/types.js +0 -3
- package/dist/documents/types.js.map +1 -1
- package/dist/email/brand.d.ts +17 -0
- package/dist/email/brand.d.ts.map +1 -0
- package/dist/email/brand.js +9 -0
- package/dist/email/brand.js.map +1 -0
- package/dist/email/index.d.ts +4 -4
- package/dist/email/index.js +4 -4
- package/dist/email/provider.d.ts +1 -7
- package/dist/email/provider.d.ts.map +1 -1
- package/dist/email/provider.js +10 -19
- package/dist/email/provider.js.map +1 -1
- package/dist/email/send.d.ts +12 -12
- package/dist/email/send.d.ts.map +1 -1
- package/dist/email/send.js +5 -19
- package/dist/email/send.js.map +1 -1
- package/dist/email/senders.d.ts +17 -30
- package/dist/email/senders.d.ts.map +1 -1
- package/dist/email/senders.js +33 -47
- package/dist/email/senders.js.map +1 -1
- package/dist/email/templates/base-layout.d.ts +1 -1
- package/dist/email/templates/base-layout.d.ts.map +1 -1
- package/dist/email/templates/base-layout.js +4 -6
- package/dist/email/templates/base-layout.js.map +1 -1
- package/dist/email/templates/index.d.ts +10 -10
- package/dist/email/templates/index.d.ts.map +1 -1
- package/dist/email/templates/index.js +10 -16
- package/dist/email/templates/index.js.map +1 -1
- package/dist/email/templates/password-reset.d.ts +2 -2
- package/dist/email/templates/password-reset.d.ts.map +1 -1
- package/dist/email/templates/password-reset.js +10 -22
- package/dist/email/templates/password-reset.js.map +1 -1
- package/dist/email/templates/payment-failed.d.ts +2 -2
- package/dist/email/templates/payment-failed.d.ts.map +1 -1
- package/dist/email/templates/payment-failed.js +11 -24
- package/dist/email/templates/payment-failed.js.map +1 -1
- package/dist/email/templates/quota-warning.d.ts +4 -4
- package/dist/email/templates/quota-warning.d.ts.map +1 -1
- package/dist/email/templates/quota-warning.js +19 -39
- package/dist/email/templates/quota-warning.js.map +1 -1
- package/dist/email/templates/subscription-confirmed.d.ts +2 -2
- package/dist/email/templates/subscription-confirmed.d.ts.map +1 -1
- package/dist/email/templates/subscription-confirmed.js +13 -28
- package/dist/email/templates/subscription-confirmed.js.map +1 -1
- package/dist/email/templates/trial-expiry.d.ts +2 -2
- package/dist/email/templates/trial-expiry.d.ts.map +1 -1
- package/dist/email/templates/trial-expiry.js +12 -36
- package/dist/email/templates/trial-expiry.js.map +1 -1
- package/dist/email/templates/trial-warning.d.ts +2 -2
- package/dist/email/templates/trial-warning.d.ts.map +1 -1
- package/dist/email/templates/trial-warning.js +15 -32
- package/dist/email/templates/trial-warning.js.map +1 -1
- package/dist/email/templates/verify-email.d.ts +2 -2
- package/dist/email/templates/verify-email.d.ts.map +1 -1
- package/dist/email/templates/verify-email.js +10 -22
- package/dist/email/templates/verify-email.js.map +1 -1
- package/dist/email/templates/welcome.d.ts +2 -2
- package/dist/email/templates/welcome.d.ts.map +1 -1
- package/dist/email/templates/welcome.js +13 -20
- package/dist/email/templates/welcome.js.map +1 -1
- package/dist/email/templates/workspace-invitation.d.ts +2 -2
- package/dist/email/templates/workspace-invitation.d.ts.map +1 -1
- package/dist/email/templates/workspace-invitation.js +12 -26
- package/dist/email/templates/workspace-invitation.js.map +1 -1
- package/dist/env.d.ts +5 -10
- package/dist/env.d.ts.map +1 -1
- package/dist/env.js +41 -31
- package/dist/env.js.map +1 -1
- package/dist/identity/audit.d.ts +11 -24
- package/dist/identity/audit.d.ts.map +1 -1
- package/dist/identity/audit.js +13 -27
- package/dist/identity/audit.js.map +1 -1
- package/dist/identity/errors.d.ts +4 -12
- package/dist/identity/errors.d.ts.map +1 -1
- package/dist/identity/errors.js +2 -8
- package/dist/identity/errors.js.map +1 -1
- package/dist/identity/index.d.ts +5 -13
- package/dist/identity/index.d.ts.map +1 -1
- package/dist/identity/index.js +4 -12
- package/dist/identity/index.js.map +1 -1
- package/dist/identity/service.d.ts +13 -47
- package/dist/identity/service.d.ts.map +1 -1
- package/dist/identity/service.js +31 -78
- package/dist/identity/service.js.map +1 -1
- package/dist/identity/types.d.ts +1 -4
- package/dist/identity/types.d.ts.map +1 -1
- package/dist/identity/types.js +0 -3
- package/dist/identity/types.js.map +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -10
- package/dist/index.js.map +1 -1
- package/dist/logger.d.ts +7 -18
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +45 -49
- package/dist/logger.js.map +1 -1
- package/dist/money.d.ts +95 -0
- package/dist/money.d.ts.map +1 -0
- package/dist/money.js +208 -0
- package/dist/money.js.map +1 -0
- package/dist/notifications/index.d.ts +9 -43
- package/dist/notifications/index.d.ts.map +1 -1
- package/dist/notifications/index.js +9 -49
- package/dist/notifications/index.js.map +1 -1
- package/dist/notifications/triggers.d.ts +9 -32
- package/dist/notifications/triggers.d.ts.map +1 -1
- package/dist/notifications/triggers.js +21 -58
- package/dist/notifications/triggers.js.map +1 -1
- package/dist/notifications/types.d.ts +1 -10
- package/dist/notifications/types.d.ts.map +1 -1
- package/dist/notifications/types.js +0 -9
- package/dist/notifications/types.js.map +1 -1
- package/dist/prompt.d.ts +38 -0
- package/dist/prompt.d.ts.map +1 -0
- package/dist/prompt.js +118 -0
- package/dist/prompt.js.map +1 -0
- package/dist/registry.d.ts +32 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +60 -0
- package/dist/registry.js.map +1 -0
- package/dist/request-context.d.ts +49 -0
- package/dist/request-context.d.ts.map +1 -0
- package/dist/request-context.js +100 -0
- package/dist/request-context.js.map +1 -0
- package/dist/storage/index.d.ts +65 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +109 -0
- package/dist/storage/index.js.map +1 -0
- package/package.json +74 -24
- package/src/attachments/errors.ts +18 -0
- package/src/attachments/index.ts +22 -0
- package/src/attachments/service.ts +178 -0
- package/src/attachments/types.ts +6 -0
- package/src/conversations/errors.ts +45 -0
- package/src/conversations/index.ts +39 -0
- package/src/conversations/service.ts +594 -0
- package/src/conversations/types.ts +15 -0
- package/src/db/client.ts +91 -0
- package/src/db/index.ts +3 -0
- package/src/db/migrations/0000_baseline.sql +652 -0
- package/src/db/migrations/0001_reconcile_chain_built_databases.sql +53 -0
- package/src/db/migrations/0002_webhook_claim_lease.sql +1 -0
- package/src/db/migrations/README.md +74 -36
- package/src/db/migrations/legacy-chain.json +197 -0
- package/src/db/migrations/meta/0000_snapshot.json +4182 -157
- package/src/db/migrations/meta/0002_snapshot.json +2478 -368
- package/src/db/migrations/meta/_journal.json +6 -279
- package/src/db/schema/agents.ts +57 -0
- package/src/db/schema/ai.ts +174 -0
- package/src/db/schema/auth.ts +183 -0
- package/src/db/schema/billing.ts +209 -0
- package/src/db/schema/feature-flags.ts +20 -0
- package/src/db/schema/identity.ts +250 -0
- package/src/db/schema/index.ts +12 -0
- package/src/db/schema/notifications.ts +31 -0
- package/src/db/schema/usage.ts +269 -0
- package/src/db/validate.ts +63 -0
- package/src/db/workspace-queries.ts +64 -0
- package/src/documents/classifier.ts +61 -0
- package/src/documents/errors.ts +44 -0
- package/src/documents/index.ts +24 -0
- package/src/documents/service.ts +256 -0
- package/src/documents/types.ts +24 -0
- package/src/email/brand.ts +24 -0
- package/src/email/index.ts +19 -0
- package/src/email/provider.ts +278 -0
- package/src/email/send.ts +169 -0
- package/src/email/senders.ts +292 -0
- package/src/email/templates/base-layout.tsx +145 -0
- package/src/email/templates/index.ts +28 -0
- package/src/email/templates/password-reset.tsx +72 -0
- package/src/email/templates/payment-failed.tsx +77 -0
- package/src/email/templates/quota-warning.tsx +118 -0
- package/src/email/templates/subscription-confirmed.tsx +91 -0
- package/src/email/templates/trial-expiry.tsx +124 -0
- package/src/email/templates/trial-warning.tsx +104 -0
- package/src/email/templates/verify-email.tsx +72 -0
- package/src/email/templates/welcome.tsx +64 -0
- package/src/email/templates/workspace-invitation.tsx +105 -0
- package/src/env.ts +180 -0
- package/src/identity/audit.ts +65 -0
- package/src/identity/errors.ts +44 -0
- package/src/identity/index.ts +26 -0
- package/src/identity/service.ts +202 -0
- package/src/identity/types.ts +28 -0
- package/src/index.ts +4 -0
- package/src/logger.ts +198 -0
- package/src/money.ts +270 -0
- package/src/notifications/index.ts +108 -0
- package/src/notifications/triggers.ts +158 -0
- package/src/notifications/types.ts +18 -0
- package/src/prompt.ts +142 -0
- package/src/registry.ts +75 -0
- package/src/request-context.ts +137 -0
- package/src/storage/index.ts +153 -0
- package/dist/db/schema/rag.d.ts +0 -171
- package/dist/db/schema/rag.d.ts.map +0 -1
- package/dist/db/schema/rag.js +0 -42
- package/dist/db/schema/rag.js.map +0 -1
- package/src/db/migrations/0000_sharp_night_nurse.sql +0 -52
- package/src/db/migrations/0001_hesitant_vapor.sql +0 -40
- package/src/db/migrations/0002_numerous_lady_vermin.sql +0 -235
- package/src/db/migrations/0003_mighty_jean_grey.sql +0 -37
- package/src/db/migrations/0004_cynical_grandmaster.sql +0 -2
- package/src/db/migrations/0005_careful_switch.sql +0 -8
- package/src/db/migrations/0006_tense_blue_marvel.sql +0 -16
- package/src/db/migrations/0007_next_squadron_sinister.sql +0 -1
- package/src/db/migrations/0008_powerful_scream.sql +0 -39
- package/src/db/migrations/0009_sad_ink.sql +0 -1
- package/src/db/migrations/0010_shocking_omega_flight.sql +0 -2
- package/src/db/migrations/0011_ambiguous_otto_octavius.sql +0 -151
- package/src/db/migrations/0011_hnsw_vector_index.sql +0 -17
- package/src/db/migrations/0012_user_profiles.sql +0 -30
- package/src/db/migrations/0013_trending_seasonal_columns.sql +0 -9
- package/src/db/migrations/0014_add_product_type_to_agents.sql +0 -6
- package/src/db/migrations/0015_new_v1_tables.sql +0 -149
- package/src/db/migrations/0016_document_types.sql +0 -30
- package/src/db/migrations/0017_document_metadata.sql +0 -2
- package/src/db/migrations/0018_identity_graph.sql +0 -200
- package/src/db/migrations/0019_db_driven_prompts.sql +0 -20
- package/src/db/migrations/0020_pending_extractions.sql +0 -35
- package/src/db/migrations/0021_rag_documents.sql +0 -39
- package/src/db/migrations/0022_user_quotas_usage_jsonb.sql +0 -70
- package/src/db/migrations/0023_user_facts_user_scoped_unique.sql +0 -17
- package/src/db/migrations/0024_user_memories_hnsw.sql +0 -23
- package/src/db/migrations/0025_audit_trigger_errcode.sql +0 -21
- package/src/db/migrations/0026_user_profile_snapshots_composite_pk.sql +0 -17
- package/src/db/migrations/0027_billing_settings_mnt_columns.sql +0 -54
- package/src/db/migrations/0028_trial_credits_normalized_email.sql +0 -37
- package/src/db/migrations/0029_usage_records_conversation_idx.sql +0 -13
- package/src/db/migrations/0030_pending_extractions_composite_idx.sql +0 -11
- package/src/db/migrations/0031_rag_documents_hnsw.sql +0 -16
- package/src/db/migrations/0032_rate_limit_unique_idx.sql +0 -16
- package/src/db/migrations/0033_pending_extractions_partial_idx.sql +0 -18
- package/src/db/migrations/0034_rate_limit_count.sql +0 -9
- package/src/db/migrations/0035_credit_reservations.sql +0 -24
- package/src/db/migrations/0036_executions_audit_jobs.sql +0 -96
- package/src/db/migrations/0037_rate_limit_minute_bucket.sql +0 -46
- package/src/db/migrations/0038_user_quotas_generic_usage.sql +0 -25
- package/src/db/migrations/0039_platform_admin_impersonation.sql +0 -27
- package/src/db/migrations/0040_ee_audit_chain.sql +0 -23
- package/src/db/migrations/meta/0001_snapshot.json +0 -631
- package/src/db/migrations/meta/0003_snapshot.json +0 -2488
- package/src/db/migrations/meta/0004_snapshot.json +0 -2500
- package/src/db/migrations/meta/0005_snapshot.json +0 -2548
- package/src/db/migrations/meta/0006_snapshot.json +0 -2650
- package/src/db/migrations/meta/0007_snapshot.json +0 -2657
- package/src/db/migrations/meta/0008_snapshot.json +0 -2719
- package/src/db/migrations/meta/0009_snapshot.json +0 -2726
- package/src/db/migrations/meta/0010_snapshot.json +0 -2739
- package/src/db/migrations/meta/0011_snapshot.json +0 -3886
|
@@ -0,0 +1,652 @@
|
|
|
1
|
+
-- The framework's schema as of 1.0: every table Intelligo owns, in one
|
|
2
|
+
-- migration. It replaces the chain that grew before the release (see
|
|
3
|
+
-- legacy-chain.json and the README); a database that ran that whole
|
|
4
|
+
-- chain is adopted by `intelligo migrate` without running this file.
|
|
5
|
+
--
|
|
6
|
+
-- pgvector backs the identity graph's memory embeddings.
|
|
7
|
+
CREATE EXTENSION IF NOT EXISTS vector;
|
|
8
|
+
--> statement-breakpoint
|
|
9
|
+
CREATE TABLE "agents" (
|
|
10
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
11
|
+
"name" jsonb NOT NULL,
|
|
12
|
+
"description" jsonb NOT NULL,
|
|
13
|
+
"system_prompt_key" text NOT NULL,
|
|
14
|
+
"system_prompt" jsonb,
|
|
15
|
+
"model_config" jsonb,
|
|
16
|
+
"icon" text NOT NULL,
|
|
17
|
+
"default_model" text NOT NULL,
|
|
18
|
+
"max_steps" integer NOT NULL,
|
|
19
|
+
"context_window_size" integer NOT NULL,
|
|
20
|
+
"tools" jsonb DEFAULT '[]'::jsonb NOT NULL,
|
|
21
|
+
"base_path" text NOT NULL,
|
|
22
|
+
"is_active" boolean DEFAULT true NOT NULL,
|
|
23
|
+
"suggestions" jsonb DEFAULT '[]'::jsonb NOT NULL,
|
|
24
|
+
"is_system" boolean DEFAULT true NOT NULL,
|
|
25
|
+
"feature_key" text,
|
|
26
|
+
"color" text DEFAULT 'bg-gray-500' NOT NULL,
|
|
27
|
+
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
28
|
+
"updated_at" timestamp DEFAULT now() NOT NULL
|
|
29
|
+
);
|
|
30
|
+
--> statement-breakpoint
|
|
31
|
+
CREATE TABLE "attachments" (
|
|
32
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
33
|
+
"workspace_id" text NOT NULL,
|
|
34
|
+
"user_id" text NOT NULL,
|
|
35
|
+
"conversation_id" text,
|
|
36
|
+
"storage_key" text NOT NULL,
|
|
37
|
+
"filename" text NOT NULL,
|
|
38
|
+
"media_type" text NOT NULL,
|
|
39
|
+
"size_bytes" integer NOT NULL,
|
|
40
|
+
"extracted_text" text,
|
|
41
|
+
"created_at" timestamp DEFAULT now() NOT NULL
|
|
42
|
+
);
|
|
43
|
+
--> statement-breakpoint
|
|
44
|
+
CREATE TABLE "conversations" (
|
|
45
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
46
|
+
"workspace_id" text NOT NULL,
|
|
47
|
+
"user_id" text NOT NULL,
|
|
48
|
+
"agent_id" text NOT NULL,
|
|
49
|
+
"title" text,
|
|
50
|
+
"model_id" text,
|
|
51
|
+
"visibility" text DEFAULT 'private' NOT NULL,
|
|
52
|
+
"metadata" jsonb,
|
|
53
|
+
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
54
|
+
"updated_at" timestamp DEFAULT now() NOT NULL
|
|
55
|
+
);
|
|
56
|
+
--> statement-breakpoint
|
|
57
|
+
CREATE TABLE "documents" (
|
|
58
|
+
"id" text NOT NULL,
|
|
59
|
+
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
60
|
+
"title" text NOT NULL,
|
|
61
|
+
"content" text,
|
|
62
|
+
"kind" text DEFAULT 'text' NOT NULL,
|
|
63
|
+
"metadata" jsonb,
|
|
64
|
+
"user_id" text NOT NULL,
|
|
65
|
+
"workspace_id" text NOT NULL,
|
|
66
|
+
CONSTRAINT "documents_id_created_at_pk" PRIMARY KEY("id","created_at")
|
|
67
|
+
);
|
|
68
|
+
--> statement-breakpoint
|
|
69
|
+
CREATE TABLE "messages" (
|
|
70
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
71
|
+
"conversation_id" text NOT NULL,
|
|
72
|
+
"role" text NOT NULL,
|
|
73
|
+
"content" text,
|
|
74
|
+
"parts" text NOT NULL,
|
|
75
|
+
"attachments" text,
|
|
76
|
+
"tool_invocations" text,
|
|
77
|
+
"token_count" integer,
|
|
78
|
+
"created_at" timestamp DEFAULT now() NOT NULL
|
|
79
|
+
);
|
|
80
|
+
--> statement-breakpoint
|
|
81
|
+
CREATE TABLE "votes" (
|
|
82
|
+
"chat_id" text NOT NULL,
|
|
83
|
+
"message_id" text NOT NULL,
|
|
84
|
+
"is_upvoted" boolean NOT NULL,
|
|
85
|
+
CONSTRAINT "votes_chat_id_message_id_pk" PRIMARY KEY("chat_id","message_id")
|
|
86
|
+
);
|
|
87
|
+
--> statement-breakpoint
|
|
88
|
+
CREATE TABLE "accounts" (
|
|
89
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
90
|
+
"user_id" text NOT NULL,
|
|
91
|
+
"account_id" text NOT NULL,
|
|
92
|
+
"provider_id" text NOT NULL,
|
|
93
|
+
"access_token" text,
|
|
94
|
+
"refresh_token" text,
|
|
95
|
+
"access_token_expires_at" timestamp,
|
|
96
|
+
"refresh_token_expires_at" timestamp,
|
|
97
|
+
"scope" text,
|
|
98
|
+
"id_token" text,
|
|
99
|
+
"password" text,
|
|
100
|
+
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
101
|
+
"updated_at" timestamp DEFAULT now() NOT NULL
|
|
102
|
+
);
|
|
103
|
+
--> statement-breakpoint
|
|
104
|
+
CREATE TABLE "invitation" (
|
|
105
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
106
|
+
"organization_id" text NOT NULL,
|
|
107
|
+
"email" text NOT NULL,
|
|
108
|
+
"role" text NOT NULL,
|
|
109
|
+
"status" text NOT NULL,
|
|
110
|
+
"expires_at" timestamp NOT NULL,
|
|
111
|
+
"inviter_id" text,
|
|
112
|
+
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
113
|
+
"updated_at" timestamp DEFAULT now() NOT NULL
|
|
114
|
+
);
|
|
115
|
+
--> statement-breakpoint
|
|
116
|
+
CREATE TABLE "member" (
|
|
117
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
118
|
+
"organization_id" text NOT NULL,
|
|
119
|
+
"user_id" text NOT NULL,
|
|
120
|
+
"role" text NOT NULL,
|
|
121
|
+
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
122
|
+
"updated_at" timestamp DEFAULT now() NOT NULL
|
|
123
|
+
);
|
|
124
|
+
--> statement-breakpoint
|
|
125
|
+
CREATE TABLE "organization" (
|
|
126
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
127
|
+
"name" text NOT NULL,
|
|
128
|
+
"slug" text,
|
|
129
|
+
"logo" text,
|
|
130
|
+
"metadata" text,
|
|
131
|
+
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
132
|
+
"updated_at" timestamp DEFAULT now() NOT NULL,
|
|
133
|
+
CONSTRAINT "organization_slug_unique" UNIQUE("slug")
|
|
134
|
+
);
|
|
135
|
+
--> statement-breakpoint
|
|
136
|
+
CREATE TABLE "sessions" (
|
|
137
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
138
|
+
"user_id" text NOT NULL,
|
|
139
|
+
"token" text NOT NULL,
|
|
140
|
+
"expires_at" timestamp NOT NULL,
|
|
141
|
+
"ip_address" text,
|
|
142
|
+
"user_agent" text,
|
|
143
|
+
"impersonated_by" text,
|
|
144
|
+
"active_organization_id" text,
|
|
145
|
+
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
146
|
+
"updated_at" timestamp DEFAULT now() NOT NULL,
|
|
147
|
+
CONSTRAINT "sessions_token_unique" UNIQUE("token")
|
|
148
|
+
);
|
|
149
|
+
--> statement-breakpoint
|
|
150
|
+
CREATE TABLE "users" (
|
|
151
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
152
|
+
"name" text NOT NULL,
|
|
153
|
+
"email" text NOT NULL,
|
|
154
|
+
"email_verified" boolean DEFAULT false NOT NULL,
|
|
155
|
+
"image" text,
|
|
156
|
+
"deleted_at" timestamp,
|
|
157
|
+
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
158
|
+
"updated_at" timestamp DEFAULT now() NOT NULL,
|
|
159
|
+
"onboarding_completed" boolean DEFAULT false NOT NULL,
|
|
160
|
+
"onboarding_step" text,
|
|
161
|
+
"preferred_language" text DEFAULT 'en' NOT NULL,
|
|
162
|
+
"role" text,
|
|
163
|
+
"banned" boolean DEFAULT false NOT NULL,
|
|
164
|
+
"ban_reason" text,
|
|
165
|
+
"ban_expires" timestamp,
|
|
166
|
+
CONSTRAINT "users_email_unique" UNIQUE("email")
|
|
167
|
+
);
|
|
168
|
+
--> statement-breakpoint
|
|
169
|
+
CREATE TABLE "verifications" (
|
|
170
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
171
|
+
"identifier" text NOT NULL,
|
|
172
|
+
"value" text NOT NULL,
|
|
173
|
+
"expires_at" timestamp NOT NULL,
|
|
174
|
+
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
175
|
+
"updated_at" timestamp DEFAULT now() NOT NULL
|
|
176
|
+
);
|
|
177
|
+
--> statement-breakpoint
|
|
178
|
+
CREATE TABLE "billing_settings" (
|
|
179
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
180
|
+
"currency" text DEFAULT 'USD' NOT NULL,
|
|
181
|
+
"usd_rate_micros" bigint DEFAULT 1000000 NOT NULL,
|
|
182
|
+
"margin_bp" integer DEFAULT 40000 NOT NULL,
|
|
183
|
+
"updated_at" timestamp DEFAULT now() NOT NULL
|
|
184
|
+
);
|
|
185
|
+
--> statement-breakpoint
|
|
186
|
+
CREATE TABLE "credit_balances" (
|
|
187
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
188
|
+
"workspace_id" text NOT NULL,
|
|
189
|
+
"balance_micros" bigint DEFAULT 0 NOT NULL,
|
|
190
|
+
"total_purchased_micros" bigint DEFAULT 0 NOT NULL,
|
|
191
|
+
"total_used_micros" bigint DEFAULT 0 NOT NULL,
|
|
192
|
+
"currency" text DEFAULT 'USD' NOT NULL,
|
|
193
|
+
"updated_at" timestamp DEFAULT now() NOT NULL,
|
|
194
|
+
CONSTRAINT "credit_balances_workspace_id_unique" UNIQUE("workspace_id")
|
|
195
|
+
);
|
|
196
|
+
--> statement-breakpoint
|
|
197
|
+
CREATE TABLE "credit_purchases" (
|
|
198
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
199
|
+
"workspace_id" text NOT NULL,
|
|
200
|
+
"price_minor" integer,
|
|
201
|
+
"price_currency" text,
|
|
202
|
+
"granted_micros" bigint,
|
|
203
|
+
"granted_currency" text,
|
|
204
|
+
"stripe_payment_intent_id" text,
|
|
205
|
+
"stripe_checkout_session_id" text,
|
|
206
|
+
"status" text DEFAULT 'pending' NOT NULL,
|
|
207
|
+
"created_at" timestamp DEFAULT now() NOT NULL
|
|
208
|
+
);
|
|
209
|
+
--> statement-breakpoint
|
|
210
|
+
CREATE TABLE "credit_reservations" (
|
|
211
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
212
|
+
"workspace_id" text NOT NULL,
|
|
213
|
+
"request_id" text NOT NULL,
|
|
214
|
+
"estimated_micros" bigint DEFAULT 0 NOT NULL,
|
|
215
|
+
"currency" text DEFAULT 'USD' NOT NULL,
|
|
216
|
+
"status" text DEFAULT 'active' NOT NULL,
|
|
217
|
+
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
218
|
+
"expires_at" timestamp NOT NULL,
|
|
219
|
+
"settled_at" timestamp,
|
|
220
|
+
CONSTRAINT "credit_reservations_request_id_unique" UNIQUE("request_id")
|
|
221
|
+
);
|
|
222
|
+
--> statement-breakpoint
|
|
223
|
+
CREATE TABLE "finance_events" (
|
|
224
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
225
|
+
"workspace_id" text,
|
|
226
|
+
"stripe_event_id" text NOT NULL,
|
|
227
|
+
"type" text NOT NULL,
|
|
228
|
+
"amount_minor" integer,
|
|
229
|
+
"currency" text DEFAULT 'USD',
|
|
230
|
+
"metadata" text,
|
|
231
|
+
"processed_at" timestamp,
|
|
232
|
+
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
233
|
+
CONSTRAINT "finance_events_stripe_event_id_unique" UNIQUE("stripe_event_id")
|
|
234
|
+
);
|
|
235
|
+
--> statement-breakpoint
|
|
236
|
+
CREATE TABLE "plans" (
|
|
237
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
238
|
+
"name" text NOT NULL,
|
|
239
|
+
"slug" text NOT NULL,
|
|
240
|
+
"description" text,
|
|
241
|
+
"price_monthly" integer NOT NULL,
|
|
242
|
+
"price_yearly" integer NOT NULL,
|
|
243
|
+
"stripe_price_id_monthly" text,
|
|
244
|
+
"stripe_price_id_yearly" text,
|
|
245
|
+
"features" text NOT NULL,
|
|
246
|
+
"limits" text NOT NULL,
|
|
247
|
+
"is_active" boolean DEFAULT true NOT NULL,
|
|
248
|
+
"sort_order" integer DEFAULT 0 NOT NULL,
|
|
249
|
+
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
250
|
+
"updated_at" timestamp DEFAULT now() NOT NULL,
|
|
251
|
+
CONSTRAINT "plans_slug_unique" UNIQUE("slug")
|
|
252
|
+
);
|
|
253
|
+
--> statement-breakpoint
|
|
254
|
+
CREATE TABLE "subscriptions" (
|
|
255
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
256
|
+
"workspace_id" text NOT NULL,
|
|
257
|
+
"plan_id" text NOT NULL,
|
|
258
|
+
"stripe_customer_id" text,
|
|
259
|
+
"stripe_subscription_id" text,
|
|
260
|
+
"status" text DEFAULT 'active' NOT NULL,
|
|
261
|
+
"billing_mode" text DEFAULT 'subscription' NOT NULL,
|
|
262
|
+
"current_period_start" timestamp,
|
|
263
|
+
"current_period_end" timestamp,
|
|
264
|
+
"cancel_at_period_end" boolean DEFAULT false NOT NULL,
|
|
265
|
+
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
266
|
+
"updated_at" timestamp DEFAULT now() NOT NULL,
|
|
267
|
+
CONSTRAINT "subscriptions_stripe_subscription_id_unique" UNIQUE("stripe_subscription_id"),
|
|
268
|
+
CONSTRAINT "subscriptions_workspace_id_unique" UNIQUE("workspace_id")
|
|
269
|
+
);
|
|
270
|
+
--> statement-breakpoint
|
|
271
|
+
CREATE TABLE "feature_flags" (
|
|
272
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
273
|
+
"name" text NOT NULL,
|
|
274
|
+
"description" text,
|
|
275
|
+
"enabled_plans" text NOT NULL,
|
|
276
|
+
"is_active" boolean DEFAULT true NOT NULL,
|
|
277
|
+
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
278
|
+
"updated_at" timestamp DEFAULT now() NOT NULL,
|
|
279
|
+
CONSTRAINT "feature_flags_name_unique" UNIQUE("name")
|
|
280
|
+
);
|
|
281
|
+
--> statement-breakpoint
|
|
282
|
+
CREATE TABLE "user_facts" (
|
|
283
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
284
|
+
"user_id" text NOT NULL,
|
|
285
|
+
"workspace_id" text NOT NULL,
|
|
286
|
+
"category" text NOT NULL,
|
|
287
|
+
"key" text NOT NULL,
|
|
288
|
+
"value" jsonb NOT NULL,
|
|
289
|
+
"confidence" double precision NOT NULL,
|
|
290
|
+
"importance" integer DEFAULT 5 NOT NULL,
|
|
291
|
+
"source_product" text,
|
|
292
|
+
"source_session_id" text,
|
|
293
|
+
"source_message_id" text,
|
|
294
|
+
"extraction_method" text,
|
|
295
|
+
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
296
|
+
"last_confirmed_at" timestamp,
|
|
297
|
+
"expires_at" timestamp
|
|
298
|
+
);
|
|
299
|
+
--> statement-breakpoint
|
|
300
|
+
CREATE TABLE "user_memories" (
|
|
301
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
302
|
+
"user_id" text NOT NULL,
|
|
303
|
+
"workspace_id" text NOT NULL,
|
|
304
|
+
"kind" text NOT NULL,
|
|
305
|
+
"content" text NOT NULL,
|
|
306
|
+
"embedding" vector(1536),
|
|
307
|
+
"source_product" text,
|
|
308
|
+
"source_session_id" text,
|
|
309
|
+
"source_message_ids" text[],
|
|
310
|
+
"importance" integer DEFAULT 5 NOT NULL,
|
|
311
|
+
"decay_factor" double precision DEFAULT 1 NOT NULL,
|
|
312
|
+
"metadata" jsonb,
|
|
313
|
+
"created_at" timestamp DEFAULT now() NOT NULL
|
|
314
|
+
);
|
|
315
|
+
--> statement-breakpoint
|
|
316
|
+
CREATE TABLE "user_memory_audit" (
|
|
317
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
318
|
+
"user_id" text NOT NULL,
|
|
319
|
+
"workspace_id" text NOT NULL,
|
|
320
|
+
"target_kind" text NOT NULL,
|
|
321
|
+
"target_id" text NOT NULL,
|
|
322
|
+
"action" text NOT NULL,
|
|
323
|
+
"actor_kind" text NOT NULL,
|
|
324
|
+
"actor_id" text,
|
|
325
|
+
"before_value" jsonb,
|
|
326
|
+
"after_value" jsonb,
|
|
327
|
+
"reason" text,
|
|
328
|
+
"created_at" timestamp DEFAULT now() NOT NULL
|
|
329
|
+
);
|
|
330
|
+
--> statement-breakpoint
|
|
331
|
+
CREATE TABLE "user_profile_snapshots" (
|
|
332
|
+
"user_id" text NOT NULL,
|
|
333
|
+
"workspace_id" text NOT NULL,
|
|
334
|
+
"version" integer NOT NULL,
|
|
335
|
+
"summary" text NOT NULL,
|
|
336
|
+
"summary_en" text,
|
|
337
|
+
"summary_mn" text,
|
|
338
|
+
"facts_digest" jsonb NOT NULL,
|
|
339
|
+
"active_goals" jsonb,
|
|
340
|
+
"personality_signals" jsonb,
|
|
341
|
+
"relationship_notes" jsonb,
|
|
342
|
+
"synthesized_by_model" text,
|
|
343
|
+
"synthesized_at" timestamp DEFAULT now() NOT NULL,
|
|
344
|
+
"next_synthesis_at" timestamp,
|
|
345
|
+
"trigger_reason" text,
|
|
346
|
+
CONSTRAINT "user_profile_snapshots_user_id_workspace_id_pk" PRIMARY KEY("user_id","workspace_id")
|
|
347
|
+
);
|
|
348
|
+
--> statement-breakpoint
|
|
349
|
+
CREATE TABLE "monthly_usage" (
|
|
350
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
351
|
+
"workspace_id" text NOT NULL,
|
|
352
|
+
"period_start" timestamp NOT NULL,
|
|
353
|
+
"period_end" timestamp NOT NULL,
|
|
354
|
+
"tokens_used" integer DEFAULT 0 NOT NULL,
|
|
355
|
+
"allowance_used_micros" bigint DEFAULT 0 NOT NULL,
|
|
356
|
+
"currency" text DEFAULT 'USD' NOT NULL,
|
|
357
|
+
"request_count" integer DEFAULT 0 NOT NULL,
|
|
358
|
+
"updated_at" timestamp DEFAULT now() NOT NULL,
|
|
359
|
+
CONSTRAINT "monthly_usage_workspace_period_unique" UNIQUE("workspace_id","period_start")
|
|
360
|
+
);
|
|
361
|
+
--> statement-breakpoint
|
|
362
|
+
CREATE TABLE "notification_history" (
|
|
363
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
364
|
+
"workspace_id" text NOT NULL,
|
|
365
|
+
"type" text NOT NULL,
|
|
366
|
+
"period_key" text NOT NULL,
|
|
367
|
+
"sent_at" timestamp DEFAULT now() NOT NULL,
|
|
368
|
+
"channel" text DEFAULT 'console' NOT NULL,
|
|
369
|
+
"metadata" text,
|
|
370
|
+
CONSTRAINT "notification_history_dedup_unique" UNIQUE("workspace_id","type","period_key")
|
|
371
|
+
);
|
|
372
|
+
--> statement-breakpoint
|
|
373
|
+
CREATE TABLE "rate_limit_entries" (
|
|
374
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
375
|
+
"workspace_id" text NOT NULL,
|
|
376
|
+
"endpoint" text DEFAULT 'chat' NOT NULL,
|
|
377
|
+
"requested_at" timestamp DEFAULT now() NOT NULL,
|
|
378
|
+
"minute_bucket" timestamp NOT NULL,
|
|
379
|
+
"count" integer DEFAULT 1 NOT NULL,
|
|
380
|
+
CONSTRAINT "rate_limit_entries_unique_bucket_idx" UNIQUE("workspace_id","endpoint","minute_bucket")
|
|
381
|
+
);
|
|
382
|
+
--> statement-breakpoint
|
|
383
|
+
CREATE TABLE "trial_credits" (
|
|
384
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
385
|
+
"workspace_id" text NOT NULL,
|
|
386
|
+
"initial_credits" integer DEFAULT 100000 NOT NULL,
|
|
387
|
+
"credits_used" integer DEFAULT 0 NOT NULL,
|
|
388
|
+
"credits_remaining" integer DEFAULT 100000 NOT NULL,
|
|
389
|
+
"initial_micros" bigint DEFAULT 0 NOT NULL,
|
|
390
|
+
"used_micros" bigint DEFAULT 0 NOT NULL,
|
|
391
|
+
"remaining_micros" bigint DEFAULT 0 NOT NULL,
|
|
392
|
+
"currency" text DEFAULT 'USD' NOT NULL,
|
|
393
|
+
"status" text DEFAULT 'active' NOT NULL,
|
|
394
|
+
"provisioned_at" timestamp DEFAULT now() NOT NULL,
|
|
395
|
+
"trial_end_date" timestamp,
|
|
396
|
+
"depleted_at" timestamp,
|
|
397
|
+
"converted_at" timestamp,
|
|
398
|
+
"created_by_ip" text,
|
|
399
|
+
"created_by_email" text,
|
|
400
|
+
"normalized_email" text,
|
|
401
|
+
CONSTRAINT "trial_credits_workspace_id_unique" UNIQUE("workspace_id")
|
|
402
|
+
);
|
|
403
|
+
--> statement-breakpoint
|
|
404
|
+
CREATE TABLE "usage_records" (
|
|
405
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
406
|
+
"workspace_id" text NOT NULL,
|
|
407
|
+
"user_id" text NOT NULL,
|
|
408
|
+
"type" text NOT NULL,
|
|
409
|
+
"model" text,
|
|
410
|
+
"agent" text,
|
|
411
|
+
"input_tokens" integer DEFAULT 0 NOT NULL,
|
|
412
|
+
"output_tokens" integer DEFAULT 0 NOT NULL,
|
|
413
|
+
"total_tokens" integer DEFAULT 0 NOT NULL,
|
|
414
|
+
"provider_cost_micros" bigint DEFAULT 0 NOT NULL,
|
|
415
|
+
"margin_bp" integer DEFAULT 0 NOT NULL,
|
|
416
|
+
"usd_rate_micros" bigint DEFAULT 0 NOT NULL,
|
|
417
|
+
"charged_micros" bigint DEFAULT 0 NOT NULL,
|
|
418
|
+
"currency" text DEFAULT 'USD' NOT NULL,
|
|
419
|
+
"request_id" text,
|
|
420
|
+
"execution_id" text,
|
|
421
|
+
"conversation_id" text,
|
|
422
|
+
"metadata" text,
|
|
423
|
+
"recorded_at" timestamp DEFAULT now() NOT NULL
|
|
424
|
+
);
|
|
425
|
+
--> statement-breakpoint
|
|
426
|
+
CREATE TABLE "user_quotas" (
|
|
427
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
428
|
+
"user_id" text NOT NULL,
|
|
429
|
+
"workspace_id" text NOT NULL,
|
|
430
|
+
"plan" text DEFAULT 'free' NOT NULL,
|
|
431
|
+
"usage" jsonb DEFAULT '{}'::jsonb NOT NULL,
|
|
432
|
+
"total_cost_usd" real DEFAULT 0 NOT NULL,
|
|
433
|
+
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
434
|
+
"updated_at" timestamp DEFAULT now() NOT NULL,
|
|
435
|
+
CONSTRAINT "user_quotas_user_workspace_unique" UNIQUE("user_id","workspace_id")
|
|
436
|
+
);
|
|
437
|
+
--> statement-breakpoint
|
|
438
|
+
CREATE TABLE "notifications" (
|
|
439
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
440
|
+
"user_id" text NOT NULL,
|
|
441
|
+
"workspace_id" text,
|
|
442
|
+
"type" text NOT NULL,
|
|
443
|
+
"title" text NOT NULL,
|
|
444
|
+
"message" text NOT NULL,
|
|
445
|
+
"is_read" boolean DEFAULT false NOT NULL,
|
|
446
|
+
"metadata" text,
|
|
447
|
+
"created_at" timestamp DEFAULT now() NOT NULL
|
|
448
|
+
);
|
|
449
|
+
--> statement-breakpoint
|
|
450
|
+
CREATE TABLE "audit_events" (
|
|
451
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
452
|
+
"workspace_id" text,
|
|
453
|
+
"actor_id" text,
|
|
454
|
+
"actor_kind" text DEFAULT 'user' NOT NULL,
|
|
455
|
+
"action" text NOT NULL,
|
|
456
|
+
"resource_kind" text NOT NULL,
|
|
457
|
+
"resource_id" text,
|
|
458
|
+
"outcome" text DEFAULT 'ok' NOT NULL,
|
|
459
|
+
"metadata" jsonb,
|
|
460
|
+
"created_at" timestamp DEFAULT now() NOT NULL
|
|
461
|
+
);
|
|
462
|
+
--> statement-breakpoint
|
|
463
|
+
CREATE TABLE "executions" (
|
|
464
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
465
|
+
"workspace_id" text NOT NULL,
|
|
466
|
+
"user_id" text,
|
|
467
|
+
"capability" text NOT NULL,
|
|
468
|
+
"request_id" text NOT NULL,
|
|
469
|
+
"status" text DEFAULT 'running' NOT NULL,
|
|
470
|
+
"model" text,
|
|
471
|
+
"input_tokens" integer,
|
|
472
|
+
"output_tokens" integer,
|
|
473
|
+
"total_tokens" integer,
|
|
474
|
+
"charged_micros" bigint,
|
|
475
|
+
"reserved_micros" bigint,
|
|
476
|
+
"currency" text,
|
|
477
|
+
"refusal_reason" text,
|
|
478
|
+
"error_message" text,
|
|
479
|
+
"started_at" timestamp DEFAULT now() NOT NULL,
|
|
480
|
+
"finished_at" timestamp,
|
|
481
|
+
"duration_ms" integer,
|
|
482
|
+
"metadata" jsonb,
|
|
483
|
+
CONSTRAINT "executions_request_id_unique" UNIQUE("request_id")
|
|
484
|
+
);
|
|
485
|
+
--> statement-breakpoint
|
|
486
|
+
CREATE TABLE "jobs" (
|
|
487
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
488
|
+
"workspace_id" text,
|
|
489
|
+
"kind" text NOT NULL,
|
|
490
|
+
"payload" jsonb,
|
|
491
|
+
"status" text DEFAULT 'pending' NOT NULL,
|
|
492
|
+
"attempts" integer DEFAULT 0 NOT NULL,
|
|
493
|
+
"max_attempts" integer DEFAULT 3 NOT NULL,
|
|
494
|
+
"run_at" timestamp DEFAULT now() NOT NULL,
|
|
495
|
+
"started_at" timestamp,
|
|
496
|
+
"finished_at" timestamp,
|
|
497
|
+
"last_error" text,
|
|
498
|
+
"created_at" timestamp DEFAULT now() NOT NULL
|
|
499
|
+
);
|
|
500
|
+
--> statement-breakpoint
|
|
501
|
+
ALTER TABLE "attachments" ADD CONSTRAINT "attachments_workspace_id_organization_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."organization"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
502
|
+
ALTER TABLE "attachments" ADD CONSTRAINT "attachments_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
503
|
+
ALTER TABLE "attachments" ADD CONSTRAINT "attachments_conversation_id_conversations_id_fk" FOREIGN KEY ("conversation_id") REFERENCES "public"."conversations"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
|
504
|
+
ALTER TABLE "conversations" ADD CONSTRAINT "conversations_workspace_id_organization_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."organization"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
505
|
+
ALTER TABLE "conversations" ADD CONSTRAINT "conversations_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
506
|
+
ALTER TABLE "documents" ADD CONSTRAINT "documents_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
507
|
+
ALTER TABLE "documents" ADD CONSTRAINT "documents_workspace_id_organization_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."organization"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
508
|
+
ALTER TABLE "messages" ADD CONSTRAINT "messages_conversation_id_conversations_id_fk" FOREIGN KEY ("conversation_id") REFERENCES "public"."conversations"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
509
|
+
ALTER TABLE "votes" ADD CONSTRAINT "votes_chat_id_conversations_id_fk" FOREIGN KEY ("chat_id") REFERENCES "public"."conversations"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
510
|
+
ALTER TABLE "votes" ADD CONSTRAINT "votes_message_id_messages_id_fk" FOREIGN KEY ("message_id") REFERENCES "public"."messages"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
511
|
+
ALTER TABLE "accounts" ADD CONSTRAINT "accounts_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
512
|
+
ALTER TABLE "invitation" ADD CONSTRAINT "invitation_organization_id_organization_id_fk" FOREIGN KEY ("organization_id") REFERENCES "public"."organization"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
513
|
+
ALTER TABLE "invitation" ADD CONSTRAINT "invitation_inviter_id_users_id_fk" FOREIGN KEY ("inviter_id") REFERENCES "public"."users"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
|
514
|
+
ALTER TABLE "member" ADD CONSTRAINT "member_organization_id_organization_id_fk" FOREIGN KEY ("organization_id") REFERENCES "public"."organization"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
515
|
+
ALTER TABLE "member" ADD CONSTRAINT "member_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
516
|
+
ALTER TABLE "sessions" ADD CONSTRAINT "sessions_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
517
|
+
ALTER TABLE "credit_balances" ADD CONSTRAINT "credit_balances_workspace_id_organization_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."organization"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
518
|
+
ALTER TABLE "credit_purchases" ADD CONSTRAINT "credit_purchases_workspace_id_organization_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."organization"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
519
|
+
ALTER TABLE "credit_reservations" ADD CONSTRAINT "credit_reservations_workspace_id_organization_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."organization"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
520
|
+
ALTER TABLE "finance_events" ADD CONSTRAINT "finance_events_workspace_id_organization_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."organization"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
|
521
|
+
ALTER TABLE "subscriptions" ADD CONSTRAINT "subscriptions_workspace_id_organization_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."organization"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
522
|
+
ALTER TABLE "subscriptions" ADD CONSTRAINT "subscriptions_plan_id_plans_id_fk" FOREIGN KEY ("plan_id") REFERENCES "public"."plans"("id") ON DELETE restrict ON UPDATE no action;--> statement-breakpoint
|
|
523
|
+
ALTER TABLE "user_facts" ADD CONSTRAINT "user_facts_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
524
|
+
ALTER TABLE "user_facts" ADD CONSTRAINT "user_facts_workspace_id_organization_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."organization"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
525
|
+
ALTER TABLE "user_memories" ADD CONSTRAINT "user_memories_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
526
|
+
ALTER TABLE "user_memories" ADD CONSTRAINT "user_memories_workspace_id_organization_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."organization"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
527
|
+
ALTER TABLE "user_memory_audit" ADD CONSTRAINT "user_memory_audit_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
528
|
+
ALTER TABLE "user_memory_audit" ADD CONSTRAINT "user_memory_audit_workspace_id_organization_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."organization"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
529
|
+
ALTER TABLE "user_profile_snapshots" ADD CONSTRAINT "user_profile_snapshots_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
530
|
+
ALTER TABLE "user_profile_snapshots" ADD CONSTRAINT "user_profile_snapshots_workspace_id_organization_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."organization"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
531
|
+
ALTER TABLE "monthly_usage" ADD CONSTRAINT "monthly_usage_workspace_id_organization_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."organization"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
532
|
+
ALTER TABLE "notification_history" ADD CONSTRAINT "notification_history_workspace_id_organization_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."organization"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
533
|
+
ALTER TABLE "rate_limit_entries" ADD CONSTRAINT "rate_limit_entries_workspace_id_organization_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."organization"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
534
|
+
ALTER TABLE "trial_credits" ADD CONSTRAINT "trial_credits_workspace_id_organization_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."organization"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
535
|
+
ALTER TABLE "usage_records" ADD CONSTRAINT "usage_records_workspace_id_organization_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."organization"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
536
|
+
ALTER TABLE "usage_records" ADD CONSTRAINT "usage_records_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
537
|
+
ALTER TABLE "user_quotas" ADD CONSTRAINT "user_quotas_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
538
|
+
ALTER TABLE "user_quotas" ADD CONSTRAINT "user_quotas_workspace_id_organization_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."organization"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
539
|
+
ALTER TABLE "audit_events" ADD CONSTRAINT "audit_events_workspace_id_organization_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."organization"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
|
540
|
+
ALTER TABLE "audit_events" ADD CONSTRAINT "audit_events_actor_id_users_id_fk" FOREIGN KEY ("actor_id") REFERENCES "public"."users"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
|
541
|
+
ALTER TABLE "executions" ADD CONSTRAINT "executions_workspace_id_organization_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."organization"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
542
|
+
ALTER TABLE "executions" ADD CONSTRAINT "executions_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
|
543
|
+
ALTER TABLE "jobs" ADD CONSTRAINT "jobs_workspace_id_organization_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."organization"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
544
|
+
CREATE INDEX "attachments_workspace_id_idx" ON "attachments" USING btree ("workspace_id");--> statement-breakpoint
|
|
545
|
+
CREATE INDEX "attachments_conversation_id_idx" ON "attachments" USING btree ("conversation_id");--> statement-breakpoint
|
|
546
|
+
CREATE UNIQUE INDEX "attachments_storage_key_idx" ON "attachments" USING btree ("storage_key");--> statement-breakpoint
|
|
547
|
+
CREATE INDEX "conversations_workspace_id_idx" ON "conversations" USING btree ("workspace_id");--> statement-breakpoint
|
|
548
|
+
CREATE INDEX "conversations_user_id_idx" ON "conversations" USING btree ("user_id");--> statement-breakpoint
|
|
549
|
+
CREATE INDEX "conversations_workspace_updated_idx" ON "conversations" USING btree ("workspace_id","updated_at");--> statement-breakpoint
|
|
550
|
+
CREATE INDEX "conversations_workspace_user_idx" ON "conversations" USING btree ("workspace_id","user_id");--> statement-breakpoint
|
|
551
|
+
CREATE INDEX "documents_workspace_id_idx" ON "documents" USING btree ("workspace_id");--> statement-breakpoint
|
|
552
|
+
CREATE INDEX "documents_user_id_idx" ON "documents" USING btree ("user_id");--> statement-breakpoint
|
|
553
|
+
CREATE INDEX "messages_conversation_id_idx" ON "messages" USING btree ("conversation_id");--> statement-breakpoint
|
|
554
|
+
CREATE INDEX "messages_conversation_created_idx" ON "messages" USING btree ("conversation_id","created_at");--> statement-breakpoint
|
|
555
|
+
CREATE INDEX "votes_message_id_idx" ON "votes" USING btree ("message_id");--> statement-breakpoint
|
|
556
|
+
CREATE INDEX "accounts_user_id_idx" ON "accounts" USING btree ("user_id");--> statement-breakpoint
|
|
557
|
+
CREATE INDEX "invitation_organization_id_idx" ON "invitation" USING btree ("organization_id");--> statement-breakpoint
|
|
558
|
+
CREATE INDEX "invitation_email_idx" ON "invitation" USING btree ("email");--> statement-breakpoint
|
|
559
|
+
CREATE INDEX "member_organization_id_idx" ON "member" USING btree ("organization_id");--> statement-breakpoint
|
|
560
|
+
CREATE INDEX "member_user_id_idx" ON "member" USING btree ("user_id");--> statement-breakpoint
|
|
561
|
+
CREATE UNIQUE INDEX "member_organization_user_uniq" ON "member" USING btree ("organization_id","user_id");--> statement-breakpoint
|
|
562
|
+
CREATE INDEX "sessions_user_id_idx" ON "sessions" USING btree ("user_id");--> statement-breakpoint
|
|
563
|
+
CREATE INDEX "users_role_idx" ON "users" USING btree ("role") WHERE "users"."role" IS NOT NULL;--> statement-breakpoint
|
|
564
|
+
CREATE INDEX "credit_purchases_workspace_id_idx" ON "credit_purchases" USING btree ("workspace_id");--> statement-breakpoint
|
|
565
|
+
CREATE INDEX "credit_reservations_active_idx" ON "credit_reservations" USING btree ("workspace_id","status","expires_at");--> statement-breakpoint
|
|
566
|
+
CREATE INDEX "subscriptions_workspace_id_idx" ON "subscriptions" USING btree ("workspace_id");--> statement-breakpoint
|
|
567
|
+
CREATE INDEX "user_facts_user_idx" ON "user_facts" USING btree ("user_id");--> statement-breakpoint
|
|
568
|
+
CREATE INDEX "user_facts_workspace_idx" ON "user_facts" USING btree ("workspace_id");--> statement-breakpoint
|
|
569
|
+
CREATE INDEX "user_facts_category_idx" ON "user_facts" USING btree ("workspace_id","category");--> statement-breakpoint
|
|
570
|
+
CREATE UNIQUE INDEX "user_facts_user_workspace_category_key_uniq" ON "user_facts" USING btree ("user_id","workspace_id","category","key");--> statement-breakpoint
|
|
571
|
+
CREATE INDEX "user_memories_user_idx" ON "user_memories" USING btree ("user_id");--> statement-breakpoint
|
|
572
|
+
CREATE INDEX "user_memories_workspace_idx" ON "user_memories" USING btree ("workspace_id");--> statement-breakpoint
|
|
573
|
+
CREATE INDEX "user_memories_kind_idx" ON "user_memories" USING btree ("workspace_id","kind");--> statement-breakpoint
|
|
574
|
+
CREATE INDEX "user_memory_audit_user_idx" ON "user_memory_audit" USING btree ("user_id");--> statement-breakpoint
|
|
575
|
+
CREATE INDEX "user_memory_audit_workspace_idx" ON "user_memory_audit" USING btree ("workspace_id");--> statement-breakpoint
|
|
576
|
+
CREATE INDEX "user_memory_audit_target_idx" ON "user_memory_audit" USING btree ("target_kind","target_id");--> statement-breakpoint
|
|
577
|
+
CREATE INDEX "user_profile_snapshots_workspace_idx" ON "user_profile_snapshots" USING btree ("workspace_id");--> statement-breakpoint
|
|
578
|
+
CREATE INDEX "monthly_usage_workspace_id_idx" ON "monthly_usage" USING btree ("workspace_id");--> statement-breakpoint
|
|
579
|
+
CREATE INDEX "notification_history_workspace_id_idx" ON "notification_history" USING btree ("workspace_id");--> statement-breakpoint
|
|
580
|
+
CREATE INDEX "rate_limit_entries_window_idx" ON "rate_limit_entries" USING btree ("workspace_id","endpoint","requested_at");--> statement-breakpoint
|
|
581
|
+
CREATE INDEX "trial_credits_expiry_idx" ON "trial_credits" USING btree ("status","trial_end_date");--> statement-breakpoint
|
|
582
|
+
CREATE INDEX "trial_credits_normalized_email_idx" ON "trial_credits" USING btree ("normalized_email");--> statement-breakpoint
|
|
583
|
+
CREATE INDEX "usage_records_workspace_id_idx" ON "usage_records" USING btree ("workspace_id");--> statement-breakpoint
|
|
584
|
+
CREATE INDEX "usage_records_workspace_recorded_at_idx" ON "usage_records" USING btree ("workspace_id","recorded_at");--> statement-breakpoint
|
|
585
|
+
CREATE INDEX "usage_records_workspace_type_idx" ON "usage_records" USING btree ("workspace_id","type");--> statement-breakpoint
|
|
586
|
+
CREATE INDEX "usage_records_conversation_id_idx" ON "usage_records" USING btree ("conversation_id");--> statement-breakpoint
|
|
587
|
+
CREATE INDEX "usage_records_execution_id_idx" ON "usage_records" USING btree ("execution_id");--> statement-breakpoint
|
|
588
|
+
CREATE INDEX "user_quotas_user_id_idx" ON "user_quotas" USING btree ("user_id");--> statement-breakpoint
|
|
589
|
+
CREATE INDEX "user_quotas_workspace_id_idx" ON "user_quotas" USING btree ("workspace_id");--> statement-breakpoint
|
|
590
|
+
CREATE INDEX "notifications_user_id_idx" ON "notifications" USING btree ("user_id");--> statement-breakpoint
|
|
591
|
+
CREATE INDEX "notifications_user_id_is_read_idx" ON "notifications" USING btree ("user_id","is_read");--> statement-breakpoint
|
|
592
|
+
CREATE INDEX "notifications_created_at_idx" ON "notifications" USING btree ("created_at");--> statement-breakpoint
|
|
593
|
+
CREATE INDEX "audit_events_workspace_created_idx" ON "audit_events" USING btree ("workspace_id","created_at");--> statement-breakpoint
|
|
594
|
+
CREATE INDEX "audit_events_action_idx" ON "audit_events" USING btree ("action","created_at");--> statement-breakpoint
|
|
595
|
+
CREATE INDEX "audit_events_resource_idx" ON "audit_events" USING btree ("resource_kind","resource_id");--> statement-breakpoint
|
|
596
|
+
CREATE INDEX "executions_workspace_started_idx" ON "executions" USING btree ("workspace_id","started_at");--> statement-breakpoint
|
|
597
|
+
CREATE INDEX "executions_status_idx" ON "executions" USING btree ("status","started_at");--> statement-breakpoint
|
|
598
|
+
CREATE INDEX "executions_capability_idx" ON "executions" USING btree ("capability","started_at");--> statement-breakpoint
|
|
599
|
+
CREATE INDEX "jobs_claim_idx" ON "jobs" USING btree ("status","run_at");--> statement-breakpoint
|
|
600
|
+
CREATE INDEX "jobs_kind_idx" ON "jobs" USING btree ("kind","status");--> statement-breakpoint
|
|
601
|
+
CREATE INDEX "jobs_workspace_idx" ON "jobs" USING btree ("workspace_id");
|
|
602
|
+
--> statement-breakpoint
|
|
603
|
+
-- Nearest-neighbour search over memory embeddings. HNSW keeps recall
|
|
604
|
+
-- good from the first row on, where IVFFlat needs a trained list count.
|
|
605
|
+
CREATE INDEX "user_memories_embedding_hnsw" ON "user_memories" USING hnsw ("embedding" vector_cosine_ops) WITH (m = 16, ef_construction = 64);
|
|
606
|
+
--> statement-breakpoint
|
|
607
|
+
-- The audit log is append-only. The one UPDATE that passes is the
|
|
608
|
+
-- database's own: ON DELETE SET NULL on workspace_id / actor_id runs as
|
|
609
|
+
-- an UPDATE of the row, so an update that only clears one or both of
|
|
610
|
+
-- those references, and touches nothing else, is allowed — otherwise a
|
|
611
|
+
-- workspace or user with any audit history could never be deleted.
|
|
612
|
+
CREATE OR REPLACE FUNCTION public.audit_events_block_mutation() RETURNS trigger
|
|
613
|
+
LANGUAGE plpgsql
|
|
614
|
+
AS $$
|
|
615
|
+
BEGIN
|
|
616
|
+
IF TG_OP = 'UPDATE'
|
|
617
|
+
AND (NEW.workspace_id IS NULL OR NEW.workspace_id = OLD.workspace_id)
|
|
618
|
+
AND (NEW.actor_id IS NULL OR NEW.actor_id = OLD.actor_id)
|
|
619
|
+
AND (NEW.workspace_id IS DISTINCT FROM OLD.workspace_id OR NEW.actor_id IS DISTINCT FROM OLD.actor_id)
|
|
620
|
+
AND NEW.id = OLD.id
|
|
621
|
+
AND NEW.actor_kind = OLD.actor_kind
|
|
622
|
+
AND NEW.action = OLD.action
|
|
623
|
+
AND NEW.resource_kind = OLD.resource_kind
|
|
624
|
+
AND NEW.resource_id IS NOT DISTINCT FROM OLD.resource_id
|
|
625
|
+
AND NEW.outcome = OLD.outcome
|
|
626
|
+
AND NEW.metadata IS NOT DISTINCT FROM OLD.metadata
|
|
627
|
+
AND NEW.created_at = OLD.created_at
|
|
628
|
+
THEN
|
|
629
|
+
RETURN NEW;
|
|
630
|
+
END IF;
|
|
631
|
+
RAISE EXCEPTION 'audit_events is append-only'
|
|
632
|
+
USING ERRCODE = 'P0001', HINT = 'INSERT new audit rows; do not UPDATE or DELETE existing ones.';
|
|
633
|
+
END;
|
|
634
|
+
$$;
|
|
635
|
+
--> statement-breakpoint
|
|
636
|
+
CREATE TRIGGER audit_events_no_update BEFORE UPDATE ON public.audit_events FOR EACH ROW EXECUTE FUNCTION public.audit_events_block_mutation();
|
|
637
|
+
--> statement-breakpoint
|
|
638
|
+
CREATE TRIGGER audit_events_no_delete BEFORE DELETE ON public.audit_events FOR EACH ROW EXECUTE FUNCTION public.audit_events_block_mutation();
|
|
639
|
+
--> statement-breakpoint
|
|
640
|
+
-- Memory audit rows are append-only, with no exception.
|
|
641
|
+
CREATE OR REPLACE FUNCTION public.user_memory_audit_block_mutation() RETURNS trigger
|
|
642
|
+
LANGUAGE plpgsql
|
|
643
|
+
AS $$
|
|
644
|
+
BEGIN
|
|
645
|
+
RAISE EXCEPTION 'user_memory_audit is append-only'
|
|
646
|
+
USING ERRCODE = 'P0001', HINT = 'INSERT new audit rows; do not UPDATE or DELETE existing ones.';
|
|
647
|
+
END;
|
|
648
|
+
$$;
|
|
649
|
+
--> statement-breakpoint
|
|
650
|
+
CREATE TRIGGER user_memory_audit_no_update BEFORE UPDATE ON public.user_memory_audit FOR EACH ROW EXECUTE FUNCTION public.user_memory_audit_block_mutation();
|
|
651
|
+
--> statement-breakpoint
|
|
652
|
+
CREATE TRIGGER user_memory_audit_no_delete BEFORE DELETE ON public.user_memory_audit FOR EACH ROW EXECUTE FUNCTION public.user_memory_audit_block_mutation();
|