@intelligo-dev/core 1.0.0-beta.1
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 +201 -0
- package/dist/conversations/errors.d.ts +31 -0
- package/dist/conversations/errors.d.ts.map +1 -0
- package/dist/conversations/errors.js +25 -0
- package/dist/conversations/errors.js.map +1 -0
- package/dist/conversations/index.d.ts +13 -0
- package/dist/conversations/index.d.ts.map +1 -0
- package/dist/conversations/index.js +12 -0
- package/dist/conversations/index.js.map +1 -0
- package/dist/conversations/service.d.ts +132 -0
- package/dist/conversations/service.d.ts.map +1 -0
- package/dist/conversations/service.js +347 -0
- package/dist/conversations/service.js.map +1 -0
- package/dist/conversations/types.d.ts +10 -0
- package/dist/conversations/types.d.ts.map +1 -0
- package/dist/conversations/types.js +5 -0
- package/dist/conversations/types.js.map +1 -0
- package/dist/db/client.d.ts +19 -0
- package/dist/db/client.d.ts.map +1 -0
- package/dist/db/client.js +52 -0
- package/dist/db/client.js.map +1 -0
- package/dist/db/index.d.ts +4 -0
- package/dist/db/index.d.ts.map +1 -0
- package/dist/db/index.js +8 -0
- package/dist/db/index.js.map +1 -0
- package/dist/db/schema/agents.d.ts +400 -0
- package/dist/db/schema/agents.d.ts.map +1 -0
- package/dist/db/schema/agents.js +39 -0
- package/dist/db/schema/agents.js.map +1 -0
- package/dist/db/schema/ai.d.ts +2222 -0
- package/dist/db/schema/ai.d.ts.map +1 -0
- package/dist/db/schema/ai.js +313 -0
- package/dist/db/schema/ai.js.map +1 -0
- package/dist/db/schema/auth.d.ts +1222 -0
- package/dist/db/schema/auth.d.ts.map +1 -0
- package/dist/db/schema/auth.js +162 -0
- package/dist/db/schema/auth.js.map +1 -0
- package/dist/db/schema/billing.d.ts +1199 -0
- package/dist/db/schema/billing.d.ts.map +1 -0
- package/dist/db/schema/billing.js +150 -0
- package/dist/db/schema/billing.js.map +1 -0
- package/dist/db/schema/feature-flags.d.ts +143 -0
- package/dist/db/schema/feature-flags.d.ts.map +1 -0
- package/dist/db/schema/feature-flags.js +25 -0
- package/dist/db/schema/feature-flags.js.map +1 -0
- package/dist/db/schema/identity.d.ts +1295 -0
- package/dist/db/schema/identity.d.ts.map +1 -0
- package/dist/db/schema/identity.js +258 -0
- package/dist/db/schema/identity.js.map +1 -0
- package/dist/db/schema/index.d.ts +16 -0
- package/dist/db/schema/index.d.ts.map +1 -0
- package/dist/db/schema/index.js +43 -0
- package/dist/db/schema/index.js.map +1 -0
- package/dist/db/schema/notifications.d.ts +182 -0
- package/dist/db/schema/notifications.d.ts.map +1 -0
- package/dist/db/schema/notifications.js +38 -0
- package/dist/db/schema/notifications.js.map +1 -0
- package/dist/db/schema/rag.d.ts +171 -0
- package/dist/db/schema/rag.d.ts.map +1 -0
- package/dist/db/schema/rag.js +42 -0
- package/dist/db/schema/rag.js.map +1 -0
- package/dist/db/schema/usage.d.ts +1193 -0
- package/dist/db/schema/usage.d.ts.map +1 -0
- package/dist/db/schema/usage.js +224 -0
- package/dist/db/schema/usage.js.map +1 -0
- package/dist/db/validate.d.ts +19 -0
- package/dist/db/validate.d.ts.map +1 -0
- package/dist/db/validate.js +58 -0
- package/dist/db/validate.js.map +1 -0
- package/dist/db/workspace-queries.d.ts +75 -0
- package/dist/db/workspace-queries.d.ts.map +1 -0
- package/dist/db/workspace-queries.js +78 -0
- package/dist/db/workspace-queries.js.map +1 -0
- package/dist/documents/classifier.d.ts +31 -0
- package/dist/documents/classifier.d.ts.map +1 -0
- package/dist/documents/classifier.js +41 -0
- package/dist/documents/classifier.js.map +1 -0
- package/dist/documents/errors.d.ts +32 -0
- package/dist/documents/errors.d.ts.map +1 -0
- package/dist/documents/errors.js +27 -0
- package/dist/documents/errors.js.map +1 -0
- package/dist/documents/index.d.ts +14 -0
- package/dist/documents/index.d.ts.map +1 -0
- package/dist/documents/index.js +13 -0
- package/dist/documents/index.js.map +1 -0
- package/dist/documents/service.d.ts +54 -0
- package/dist/documents/service.d.ts.map +1 -0
- package/dist/documents/service.js +146 -0
- package/dist/documents/service.js.map +1 -0
- package/dist/documents/types.d.ts +27 -0
- package/dist/documents/types.d.ts.map +1 -0
- package/dist/documents/types.js +5 -0
- package/dist/documents/types.js.map +1 -0
- package/dist/email/index.d.ts +5 -0
- package/dist/email/index.d.ts.map +1 -0
- package/dist/email/index.js +5 -0
- package/dist/email/index.js.map +1 -0
- package/dist/email/provider.d.ts +68 -0
- package/dist/email/provider.d.ts.map +1 -0
- package/dist/email/provider.js +199 -0
- package/dist/email/provider.js.map +1 -0
- package/dist/email/send.d.ts +47 -0
- package/dist/email/send.d.ts.map +1 -0
- package/dist/email/send.js +110 -0
- package/dist/email/send.js.map +1 -0
- package/dist/email/senders.d.ts +93 -0
- package/dist/email/senders.d.ts.map +1 -0
- package/dist/email/senders.js +232 -0
- package/dist/email/senders.js.map +1 -0
- package/dist/email/templates/base-layout.d.ts +7 -0
- package/dist/email/templates/base-layout.d.ts.map +1 -0
- package/dist/email/templates/base-layout.js +69 -0
- package/dist/email/templates/base-layout.js.map +1 -0
- package/dist/email/templates/index.d.ts +11 -0
- package/dist/email/templates/index.d.ts.map +1 -0
- package/dist/email/templates/index.js +17 -0
- package/dist/email/templates/index.js.map +1 -0
- package/dist/email/templates/password-reset.d.ts +7 -0
- package/dist/email/templates/password-reset.d.ts.map +1 -0
- package/dist/email/templates/password-reset.js +59 -0
- package/dist/email/templates/password-reset.js.map +1 -0
- package/dist/email/templates/payment-failed.d.ts +8 -0
- package/dist/email/templates/payment-failed.d.ts.map +1 -0
- package/dist/email/templates/payment-failed.js +62 -0
- package/dist/email/templates/payment-failed.js.map +1 -0
- package/dist/email/templates/quota-warning.d.ts +11 -0
- package/dist/email/templates/quota-warning.d.ts.map +1 -0
- package/dist/email/templates/quota-warning.js +82 -0
- package/dist/email/templates/quota-warning.js.map +1 -0
- package/dist/email/templates/subscription-confirmed.d.ts +9 -0
- package/dist/email/templates/subscription-confirmed.d.ts.map +1 -0
- package/dist/email/templates/subscription-confirmed.js +72 -0
- package/dist/email/templates/subscription-confirmed.js.map +1 -0
- package/dist/email/templates/trial-expiry.d.ts +9 -0
- package/dist/email/templates/trial-expiry.d.ts.map +1 -0
- package/dist/email/templates/trial-expiry.js +86 -0
- package/dist/email/templates/trial-expiry.js.map +1 -0
- package/dist/email/templates/trial-warning.d.ts +11 -0
- package/dist/email/templates/trial-warning.d.ts.map +1 -0
- package/dist/email/templates/trial-warning.js +70 -0
- package/dist/email/templates/trial-warning.js.map +1 -0
- package/dist/email/templates/verify-email.d.ts +7 -0
- package/dist/email/templates/verify-email.d.ts.map +1 -0
- package/dist/email/templates/verify-email.js +59 -0
- package/dist/email/templates/verify-email.js.map +1 -0
- package/dist/email/templates/welcome.d.ts +7 -0
- package/dist/email/templates/welcome.d.ts.map +1 -0
- package/dist/email/templates/welcome.js +51 -0
- package/dist/email/templates/welcome.js.map +1 -0
- package/dist/email/templates/workspace-invitation.d.ts +10 -0
- package/dist/email/templates/workspace-invitation.d.ts.map +1 -0
- package/dist/email/templates/workspace-invitation.js +79 -0
- package/dist/email/templates/workspace-invitation.js.map +1 -0
- package/dist/env.d.ts +21 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/env.js +129 -0
- package/dist/env.js.map +1 -0
- package/dist/identity/audit.d.ts +39 -0
- package/dist/identity/audit.d.ts.map +1 -0
- package/dist/identity/audit.js +51 -0
- package/dist/identity/audit.js.map +1 -0
- package/dist/identity/errors.d.ts +32 -0
- package/dist/identity/errors.d.ts.map +1 -0
- package/dist/identity/errors.js +25 -0
- package/dist/identity/errors.js.map +1 -0
- package/dist/identity/index.d.ts +16 -0
- package/dist/identity/index.d.ts.map +1 -0
- package/dist/identity/index.js +15 -0
- package/dist/identity/index.js.map +1 -0
- package/dist/identity/service.d.ts +70 -0
- package/dist/identity/service.d.ts.map +1 -0
- package/dist/identity/service.js +179 -0
- package/dist/identity/service.js.map +1 -0
- package/dist/identity/types.d.ts +27 -0
- package/dist/identity/types.d.ts.map +1 -0
- package/dist/identity/types.js +5 -0
- package/dist/identity/types.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +50 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +183 -0
- package/dist/logger.js.map +1 -0
- package/dist/notifications/index.d.ts +86 -0
- package/dist/notifications/index.d.ts.map +1 -0
- package/dist/notifications/index.js +112 -0
- package/dist/notifications/index.js.map +1 -0
- package/dist/notifications/triggers.d.ts +68 -0
- package/dist/notifications/triggers.d.ts.map +1 -0
- package/dist/notifications/triggers.js +145 -0
- package/dist/notifications/triggers.js.map +1 -0
- package/dist/notifications/types.d.ts +19 -0
- package/dist/notifications/types.d.ts.map +1 -0
- package/dist/notifications/types.js +11 -0
- package/dist/notifications/types.js.map +1 -0
- package/package.json +101 -0
- package/src/db/migrations/0000_sharp_night_nurse.sql +52 -0
- package/src/db/migrations/0001_hesitant_vapor.sql +40 -0
- package/src/db/migrations/0002_numerous_lady_vermin.sql +235 -0
- package/src/db/migrations/0003_mighty_jean_grey.sql +37 -0
- package/src/db/migrations/0004_cynical_grandmaster.sql +2 -0
- package/src/db/migrations/0005_careful_switch.sql +8 -0
- package/src/db/migrations/0006_tense_blue_marvel.sql +16 -0
- package/src/db/migrations/0007_next_squadron_sinister.sql +1 -0
- package/src/db/migrations/0008_powerful_scream.sql +39 -0
- package/src/db/migrations/0009_sad_ink.sql +1 -0
- package/src/db/migrations/0010_shocking_omega_flight.sql +2 -0
- package/src/db/migrations/0011_ambiguous_otto_octavius.sql +151 -0
- package/src/db/migrations/0011_hnsw_vector_index.sql +17 -0
- package/src/db/migrations/0012_user_profiles.sql +30 -0
- package/src/db/migrations/0013_trending_seasonal_columns.sql +9 -0
- package/src/db/migrations/0014_add_product_type_to_agents.sql +6 -0
- package/src/db/migrations/0015_new_v1_tables.sql +149 -0
- package/src/db/migrations/0016_document_types.sql +30 -0
- package/src/db/migrations/0017_document_metadata.sql +2 -0
- package/src/db/migrations/0018_identity_graph.sql +200 -0
- package/src/db/migrations/0019_db_driven_prompts.sql +20 -0
- package/src/db/migrations/0020_pending_extractions.sql +35 -0
- package/src/db/migrations/0021_rag_documents.sql +39 -0
- package/src/db/migrations/0022_user_quotas_usage_jsonb.sql +70 -0
- package/src/db/migrations/0023_user_facts_user_scoped_unique.sql +17 -0
- package/src/db/migrations/0024_user_memories_hnsw.sql +23 -0
- package/src/db/migrations/0025_audit_trigger_errcode.sql +21 -0
- package/src/db/migrations/0026_user_profile_snapshots_composite_pk.sql +17 -0
- package/src/db/migrations/0027_billing_settings_mnt_columns.sql +54 -0
- package/src/db/migrations/0028_trial_credits_normalized_email.sql +37 -0
- package/src/db/migrations/0029_usage_records_conversation_idx.sql +13 -0
- package/src/db/migrations/0030_pending_extractions_composite_idx.sql +11 -0
- package/src/db/migrations/0031_rag_documents_hnsw.sql +16 -0
- package/src/db/migrations/0032_rate_limit_unique_idx.sql +16 -0
- package/src/db/migrations/0033_pending_extractions_partial_idx.sql +18 -0
- package/src/db/migrations/0034_rate_limit_count.sql +9 -0
- package/src/db/migrations/0035_credit_reservations.sql +24 -0
- package/src/db/migrations/0036_executions_audit_jobs.sql +96 -0
- package/src/db/migrations/0037_rate_limit_minute_bucket.sql +46 -0
- package/src/db/migrations/0038_user_quotas_generic_usage.sql +25 -0
- package/src/db/migrations/0039_platform_admin_impersonation.sql +27 -0
- package/src/db/migrations/0040_ee_audit_chain.sql +23 -0
- package/src/db/migrations/README.md +57 -0
- package/src/db/migrations/meta/0000_snapshot.json +348 -0
- package/src/db/migrations/meta/0001_snapshot.json +631 -0
- package/src/db/migrations/meta/0002_snapshot.json +2269 -0
- package/src/db/migrations/meta/0003_snapshot.json +2488 -0
- package/src/db/migrations/meta/0004_snapshot.json +2500 -0
- package/src/db/migrations/meta/0005_snapshot.json +2548 -0
- package/src/db/migrations/meta/0006_snapshot.json +2650 -0
- package/src/db/migrations/meta/0007_snapshot.json +2657 -0
- package/src/db/migrations/meta/0008_snapshot.json +2719 -0
- package/src/db/migrations/meta/0009_snapshot.json +2726 -0
- package/src/db/migrations/meta/0010_snapshot.json +2739 -0
- package/src/db/migrations/meta/0011_snapshot.json +3886 -0
- package/src/db/migrations/meta/_journal.json +300 -0
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
-- Enable pgvector extension for vector embeddings (AI Phase 16)
|
|
2
|
+
CREATE EXTENSION IF NOT EXISTS vector;
|
|
3
|
+
--> statement-breakpoint
|
|
4
|
+
CREATE TABLE "conversations" (
|
|
5
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
6
|
+
"workspace_id" text NOT NULL,
|
|
7
|
+
"user_id" text NOT NULL,
|
|
8
|
+
"agent_id" text NOT NULL,
|
|
9
|
+
"title" text,
|
|
10
|
+
"model_id" text,
|
|
11
|
+
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
12
|
+
"updated_at" timestamp DEFAULT now() NOT NULL
|
|
13
|
+
);
|
|
14
|
+
--> statement-breakpoint
|
|
15
|
+
CREATE TABLE "knowledge_chunks" (
|
|
16
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
17
|
+
"document_id" text NOT NULL,
|
|
18
|
+
"workspace_id" text NOT NULL,
|
|
19
|
+
"content" text NOT NULL,
|
|
20
|
+
"embedding" vector(1536),
|
|
21
|
+
"metadata" text,
|
|
22
|
+
"chunk_index" integer NOT NULL,
|
|
23
|
+
"created_at" timestamp DEFAULT now() NOT NULL
|
|
24
|
+
);
|
|
25
|
+
--> statement-breakpoint
|
|
26
|
+
CREATE TABLE "knowledge_documents" (
|
|
27
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
28
|
+
"workspace_id" text NOT NULL,
|
|
29
|
+
"filename" text NOT NULL,
|
|
30
|
+
"mime_type" text NOT NULL,
|
|
31
|
+
"size_bytes" integer,
|
|
32
|
+
"chunk_count" integer DEFAULT 0,
|
|
33
|
+
"status" text DEFAULT 'processing' NOT NULL,
|
|
34
|
+
"product" text,
|
|
35
|
+
"metadata" text,
|
|
36
|
+
"created_at" timestamp DEFAULT now() NOT NULL
|
|
37
|
+
);
|
|
38
|
+
--> statement-breakpoint
|
|
39
|
+
CREATE TABLE "messages" (
|
|
40
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
41
|
+
"conversation_id" text NOT NULL,
|
|
42
|
+
"role" text NOT NULL,
|
|
43
|
+
"content" text NOT NULL,
|
|
44
|
+
"tool_invocations" text,
|
|
45
|
+
"token_count" integer,
|
|
46
|
+
"created_at" timestamp DEFAULT now() NOT NULL
|
|
47
|
+
);
|
|
48
|
+
--> statement-breakpoint
|
|
49
|
+
CREATE TABLE "credit_balances" (
|
|
50
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
51
|
+
"workspace_id" text NOT NULL,
|
|
52
|
+
"balance" integer DEFAULT 0 NOT NULL,
|
|
53
|
+
"total_purchased" integer DEFAULT 0 NOT NULL,
|
|
54
|
+
"total_used" integer DEFAULT 0 NOT NULL,
|
|
55
|
+
"updated_at" timestamp DEFAULT now() NOT NULL,
|
|
56
|
+
CONSTRAINT "credit_balances_workspace_id_unique" UNIQUE("workspace_id")
|
|
57
|
+
);
|
|
58
|
+
--> statement-breakpoint
|
|
59
|
+
CREATE TABLE "credit_purchases" (
|
|
60
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
61
|
+
"workspace_id" text NOT NULL,
|
|
62
|
+
"amount" integer NOT NULL,
|
|
63
|
+
"credits" integer NOT NULL,
|
|
64
|
+
"stripe_payment_intent_id" text,
|
|
65
|
+
"stripe_checkout_session_id" text,
|
|
66
|
+
"status" text DEFAULT 'pending' NOT NULL,
|
|
67
|
+
"created_at" timestamp DEFAULT now() NOT NULL
|
|
68
|
+
);
|
|
69
|
+
--> statement-breakpoint
|
|
70
|
+
CREATE TABLE "finance_events" (
|
|
71
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
72
|
+
"workspace_id" text,
|
|
73
|
+
"stripe_event_id" text NOT NULL,
|
|
74
|
+
"type" text NOT NULL,
|
|
75
|
+
"amount" integer,
|
|
76
|
+
"currency" text DEFAULT 'usd',
|
|
77
|
+
"metadata" text,
|
|
78
|
+
"processed_at" timestamp,
|
|
79
|
+
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
80
|
+
CONSTRAINT "finance_events_stripe_event_id_unique" UNIQUE("stripe_event_id")
|
|
81
|
+
);
|
|
82
|
+
--> statement-breakpoint
|
|
83
|
+
CREATE TABLE "plans" (
|
|
84
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
85
|
+
"name" text NOT NULL,
|
|
86
|
+
"slug" text NOT NULL,
|
|
87
|
+
"description" text,
|
|
88
|
+
"price_monthly" integer NOT NULL,
|
|
89
|
+
"price_yearly" integer NOT NULL,
|
|
90
|
+
"stripe_price_id_monthly" text,
|
|
91
|
+
"stripe_price_id_yearly" text,
|
|
92
|
+
"features" text NOT NULL,
|
|
93
|
+
"limits" text NOT NULL,
|
|
94
|
+
"is_active" boolean DEFAULT true NOT NULL,
|
|
95
|
+
"sort_order" integer DEFAULT 0 NOT NULL,
|
|
96
|
+
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
97
|
+
"updated_at" timestamp DEFAULT now() NOT NULL,
|
|
98
|
+
CONSTRAINT "plans_slug_unique" UNIQUE("slug")
|
|
99
|
+
);
|
|
100
|
+
--> statement-breakpoint
|
|
101
|
+
CREATE TABLE "subscriptions" (
|
|
102
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
103
|
+
"workspace_id" text NOT NULL,
|
|
104
|
+
"plan_id" text NOT NULL,
|
|
105
|
+
"stripe_customer_id" text,
|
|
106
|
+
"stripe_subscription_id" text,
|
|
107
|
+
"status" text DEFAULT 'active' NOT NULL,
|
|
108
|
+
"billing_mode" text DEFAULT 'subscription' NOT NULL,
|
|
109
|
+
"current_period_start" timestamp,
|
|
110
|
+
"current_period_end" timestamp,
|
|
111
|
+
"cancel_at_period_end" boolean DEFAULT false NOT NULL,
|
|
112
|
+
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
113
|
+
"updated_at" timestamp DEFAULT now() NOT NULL,
|
|
114
|
+
CONSTRAINT "subscriptions_stripe_subscription_id_unique" UNIQUE("stripe_subscription_id"),
|
|
115
|
+
CONSTRAINT "subscriptions_workspace_id_unique" UNIQUE("workspace_id")
|
|
116
|
+
);
|
|
117
|
+
--> statement-breakpoint
|
|
118
|
+
CREATE TABLE "feature_flags" (
|
|
119
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
120
|
+
"name" text NOT NULL,
|
|
121
|
+
"description" text,
|
|
122
|
+
"enabled_plans" text NOT NULL,
|
|
123
|
+
"is_active" boolean DEFAULT true NOT NULL,
|
|
124
|
+
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
125
|
+
"updated_at" timestamp DEFAULT now() NOT NULL,
|
|
126
|
+
CONSTRAINT "feature_flags_name_unique" UNIQUE("name")
|
|
127
|
+
);
|
|
128
|
+
--> statement-breakpoint
|
|
129
|
+
CREATE TABLE "monthly_usage" (
|
|
130
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
131
|
+
"workspace_id" text NOT NULL,
|
|
132
|
+
"period_start" timestamp NOT NULL,
|
|
133
|
+
"period_end" timestamp NOT NULL,
|
|
134
|
+
"tokens_used" integer DEFAULT 0 NOT NULL,
|
|
135
|
+
"request_count" integer DEFAULT 0 NOT NULL,
|
|
136
|
+
"updated_at" timestamp DEFAULT now() NOT NULL,
|
|
137
|
+
CONSTRAINT "monthly_usage_workspace_period_unique" UNIQUE("workspace_id","period_start")
|
|
138
|
+
);
|
|
139
|
+
--> statement-breakpoint
|
|
140
|
+
CREATE TABLE "notification_history" (
|
|
141
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
142
|
+
"workspace_id" text NOT NULL,
|
|
143
|
+
"type" text NOT NULL,
|
|
144
|
+
"period_key" text NOT NULL,
|
|
145
|
+
"sent_at" timestamp DEFAULT now() NOT NULL,
|
|
146
|
+
"channel" text DEFAULT 'console' NOT NULL,
|
|
147
|
+
"metadata" text,
|
|
148
|
+
CONSTRAINT "notification_history_dedup_unique" UNIQUE("workspace_id","type","period_key")
|
|
149
|
+
);
|
|
150
|
+
--> statement-breakpoint
|
|
151
|
+
CREATE TABLE "rate_limit_entries" (
|
|
152
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
153
|
+
"workspace_id" text NOT NULL,
|
|
154
|
+
"endpoint" text DEFAULT 'chat' NOT NULL,
|
|
155
|
+
"requested_at" timestamp DEFAULT now() NOT NULL
|
|
156
|
+
);
|
|
157
|
+
--> statement-breakpoint
|
|
158
|
+
CREATE TABLE "trial_credits" (
|
|
159
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
160
|
+
"workspace_id" text NOT NULL,
|
|
161
|
+
"initial_credits" integer DEFAULT 100000 NOT NULL,
|
|
162
|
+
"credits_used" integer DEFAULT 0 NOT NULL,
|
|
163
|
+
"credits_remaining" integer DEFAULT 100000 NOT NULL,
|
|
164
|
+
"status" text DEFAULT 'active' NOT NULL,
|
|
165
|
+
"provisioned_at" timestamp DEFAULT now() NOT NULL,
|
|
166
|
+
"depleted_at" timestamp,
|
|
167
|
+
"converted_at" timestamp,
|
|
168
|
+
"created_by_ip" text,
|
|
169
|
+
"created_by_email" text,
|
|
170
|
+
CONSTRAINT "trial_credits_workspace_id_unique" UNIQUE("workspace_id")
|
|
171
|
+
);
|
|
172
|
+
--> statement-breakpoint
|
|
173
|
+
CREATE TABLE "usage_records" (
|
|
174
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
175
|
+
"workspace_id" text NOT NULL,
|
|
176
|
+
"user_id" text NOT NULL,
|
|
177
|
+
"type" text NOT NULL,
|
|
178
|
+
"model" text,
|
|
179
|
+
"agent" text,
|
|
180
|
+
"input_tokens" integer DEFAULT 0 NOT NULL,
|
|
181
|
+
"output_tokens" integer DEFAULT 0 NOT NULL,
|
|
182
|
+
"total_tokens" integer DEFAULT 0 NOT NULL,
|
|
183
|
+
"metadata" text,
|
|
184
|
+
"recorded_at" timestamp DEFAULT now() NOT NULL
|
|
185
|
+
);
|
|
186
|
+
--> statement-breakpoint
|
|
187
|
+
CREATE TABLE "notifications" (
|
|
188
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
189
|
+
"user_id" text NOT NULL,
|
|
190
|
+
"workspace_id" text,
|
|
191
|
+
"type" text NOT NULL,
|
|
192
|
+
"title" text NOT NULL,
|
|
193
|
+
"message" text NOT NULL,
|
|
194
|
+
"is_read" boolean DEFAULT false NOT NULL,
|
|
195
|
+
"metadata" text,
|
|
196
|
+
"created_at" timestamp DEFAULT now() NOT NULL
|
|
197
|
+
);
|
|
198
|
+
--> statement-breakpoint
|
|
199
|
+
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
|
|
200
|
+
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
|
|
201
|
+
ALTER TABLE "knowledge_chunks" ADD CONSTRAINT "knowledge_chunks_document_id_knowledge_documents_id_fk" FOREIGN KEY ("document_id") REFERENCES "public"."knowledge_documents"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
202
|
+
ALTER TABLE "knowledge_chunks" ADD CONSTRAINT "knowledge_chunks_workspace_id_organization_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."organization"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
203
|
+
ALTER TABLE "knowledge_documents" ADD CONSTRAINT "knowledge_documents_workspace_id_organization_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."organization"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
204
|
+
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
|
|
205
|
+
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
|
|
206
|
+
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
|
|
207
|
+
ALTER TABLE "finance_events" ADD CONSTRAINT "finance_events_workspace_id_organization_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."organization"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
208
|
+
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
|
|
209
|
+
ALTER TABLE "subscriptions" ADD CONSTRAINT "subscriptions_plan_id_plans_id_fk" FOREIGN KEY ("plan_id") REFERENCES "public"."plans"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
210
|
+
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
|
|
211
|
+
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
|
|
212
|
+
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
|
|
213
|
+
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
|
|
214
|
+
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
|
|
215
|
+
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
|
|
216
|
+
CREATE INDEX "conversations_workspace_id_idx" ON "conversations" USING btree ("workspace_id");--> statement-breakpoint
|
|
217
|
+
CREATE INDEX "conversations_user_id_idx" ON "conversations" USING btree ("user_id");--> statement-breakpoint
|
|
218
|
+
CREATE INDEX "conversations_workspace_updated_idx" ON "conversations" USING btree ("workspace_id","updated_at");--> statement-breakpoint
|
|
219
|
+
CREATE INDEX "knowledge_chunks_document_id_idx" ON "knowledge_chunks" USING btree ("document_id");--> statement-breakpoint
|
|
220
|
+
CREATE INDEX "knowledge_chunks_workspace_id_idx" ON "knowledge_chunks" USING btree ("workspace_id");--> statement-breakpoint
|
|
221
|
+
CREATE INDEX IF NOT EXISTS "knowledge_chunks_embedding_hnsw_idx" ON "knowledge_chunks" USING hnsw ("embedding" vector_cosine_ops);--> statement-breakpoint
|
|
222
|
+
CREATE INDEX "knowledge_documents_workspace_id_idx" ON "knowledge_documents" USING btree ("workspace_id");--> statement-breakpoint
|
|
223
|
+
CREATE INDEX "messages_conversation_id_idx" ON "messages" USING btree ("conversation_id");--> statement-breakpoint
|
|
224
|
+
CREATE INDEX "messages_conversation_created_idx" ON "messages" USING btree ("conversation_id","created_at");--> statement-breakpoint
|
|
225
|
+
CREATE INDEX "credit_purchases_workspace_id_idx" ON "credit_purchases" USING btree ("workspace_id");--> statement-breakpoint
|
|
226
|
+
CREATE INDEX "subscriptions_workspace_id_idx" ON "subscriptions" USING btree ("workspace_id");--> statement-breakpoint
|
|
227
|
+
CREATE INDEX "monthly_usage_workspace_id_idx" ON "monthly_usage" USING btree ("workspace_id");--> statement-breakpoint
|
|
228
|
+
CREATE INDEX "notification_history_workspace_id_idx" ON "notification_history" USING btree ("workspace_id");--> statement-breakpoint
|
|
229
|
+
CREATE INDEX "rate_limit_entries_window_idx" ON "rate_limit_entries" USING btree ("workspace_id","endpoint","requested_at");--> statement-breakpoint
|
|
230
|
+
CREATE INDEX "usage_records_workspace_id_idx" ON "usage_records" USING btree ("workspace_id");--> statement-breakpoint
|
|
231
|
+
CREATE INDEX "usage_records_workspace_recorded_at_idx" ON "usage_records" USING btree ("workspace_id","recorded_at");--> statement-breakpoint
|
|
232
|
+
CREATE INDEX "usage_records_workspace_type_idx" ON "usage_records" USING btree ("workspace_id","type");--> statement-breakpoint
|
|
233
|
+
CREATE INDEX "notifications_user_id_idx" ON "notifications" USING btree ("user_id");--> statement-breakpoint
|
|
234
|
+
CREATE INDEX "notifications_user_id_is_read_idx" ON "notifications" USING btree ("user_id","is_read");--> statement-breakpoint
|
|
235
|
+
CREATE INDEX "notifications_created_at_idx" ON "notifications" USING btree ("created_at");
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
CREATE TABLE "documents" (
|
|
2
|
+
"id" text NOT NULL,
|
|
3
|
+
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
4
|
+
"title" text NOT NULL,
|
|
5
|
+
"content" text,
|
|
6
|
+
"kind" text DEFAULT 'text' NOT NULL,
|
|
7
|
+
"user_id" text NOT NULL,
|
|
8
|
+
CONSTRAINT "documents_id_created_at_pk" PRIMARY KEY("id","created_at")
|
|
9
|
+
);
|
|
10
|
+
--> statement-breakpoint
|
|
11
|
+
CREATE TABLE "suggestions" (
|
|
12
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
13
|
+
"document_id" text NOT NULL,
|
|
14
|
+
"document_created_at" timestamp NOT NULL,
|
|
15
|
+
"original_text" text NOT NULL,
|
|
16
|
+
"suggested_text" text NOT NULL,
|
|
17
|
+
"description" text,
|
|
18
|
+
"is_resolved" boolean DEFAULT false NOT NULL,
|
|
19
|
+
"user_id" text NOT NULL,
|
|
20
|
+
"created_at" timestamp DEFAULT now() NOT NULL
|
|
21
|
+
);
|
|
22
|
+
--> statement-breakpoint
|
|
23
|
+
CREATE TABLE "votes" (
|
|
24
|
+
"chat_id" text NOT NULL,
|
|
25
|
+
"message_id" text NOT NULL,
|
|
26
|
+
"is_upvoted" boolean NOT NULL,
|
|
27
|
+
CONSTRAINT "votes_chat_id_message_id_pk" PRIMARY KEY("chat_id","message_id")
|
|
28
|
+
);
|
|
29
|
+
--> statement-breakpoint
|
|
30
|
+
ALTER TABLE "messages" ALTER COLUMN "content" DROP NOT NULL;--> statement-breakpoint
|
|
31
|
+
ALTER TABLE "conversations" ADD COLUMN "visibility" text DEFAULT 'private' NOT NULL;--> statement-breakpoint
|
|
32
|
+
ALTER TABLE "messages" ADD COLUMN "parts" text NOT NULL;--> statement-breakpoint
|
|
33
|
+
ALTER TABLE "messages" ADD COLUMN "attachments" text;--> statement-breakpoint
|
|
34
|
+
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
|
|
35
|
+
ALTER TABLE "suggestions" ADD CONSTRAINT "suggestions_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
36
|
+
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
|
|
37
|
+
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;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
ALTER TABLE "subscriptions" DROP CONSTRAINT "subscriptions_plan_id_plans_id_fk";
|
|
2
|
+
--> statement-breakpoint
|
|
3
|
+
ALTER TABLE "users" ADD COLUMN "deleted_at" timestamp;--> statement-breakpoint
|
|
4
|
+
ALTER TABLE "users" ADD COLUMN "onboarding_completed" boolean DEFAULT false NOT NULL;--> statement-breakpoint
|
|
5
|
+
ALTER TABLE "users" ADD COLUMN "onboarding_step" text;--> statement-breakpoint
|
|
6
|
+
ALTER TABLE "users" ADD COLUMN "preferred_language" text DEFAULT 'en' NOT NULL;--> statement-breakpoint
|
|
7
|
+
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
|
|
8
|
+
CREATE INDEX "trial_credits_expiry_idx" ON "trial_credits" USING btree ("status","trial_end_date");
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
CREATE TABLE "agents" (
|
|
2
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
3
|
+
"name" jsonb NOT NULL,
|
|
4
|
+
"description" jsonb NOT NULL,
|
|
5
|
+
"system_prompt_key" text NOT NULL,
|
|
6
|
+
"icon" text NOT NULL,
|
|
7
|
+
"default_model" text NOT NULL,
|
|
8
|
+
"max_steps" integer NOT NULL,
|
|
9
|
+
"context_window_size" integer NOT NULL,
|
|
10
|
+
"tools" jsonb DEFAULT '[]'::jsonb NOT NULL,
|
|
11
|
+
"base_path" text NOT NULL,
|
|
12
|
+
"is_active" boolean DEFAULT true NOT NULL,
|
|
13
|
+
"is_system" boolean DEFAULT true NOT NULL,
|
|
14
|
+
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
15
|
+
"updated_at" timestamp DEFAULT now() NOT NULL
|
|
16
|
+
);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ALTER TABLE "agents" ADD COLUMN "suggestions" jsonb DEFAULT '[]'::jsonb NOT NULL;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
-- Step 1: Add workspace_id columns as NULLABLE first to allow backfill
|
|
2
|
+
ALTER TABLE "documents" ADD COLUMN "workspace_id" text;--> statement-breakpoint
|
|
3
|
+
ALTER TABLE "suggestions" ADD COLUMN "workspace_id" text;--> statement-breakpoint
|
|
4
|
+
|
|
5
|
+
-- Step 2: Backfill workspace_id for documents using the member table
|
|
6
|
+
-- Each document's user_id maps to an organization via the member table
|
|
7
|
+
-- We pick the user's first organization (LIMIT 1) in case of multiple memberships
|
|
8
|
+
UPDATE "documents" d
|
|
9
|
+
SET workspace_id = (
|
|
10
|
+
SELECT m.organization_id
|
|
11
|
+
FROM "member" m
|
|
12
|
+
WHERE m.user_id = d.user_id
|
|
13
|
+
ORDER BY m.created_at ASC
|
|
14
|
+
LIMIT 1
|
|
15
|
+
)
|
|
16
|
+
WHERE d.workspace_id IS NULL;--> statement-breakpoint
|
|
17
|
+
|
|
18
|
+
-- Step 3: Backfill workspace_id for suggestions using the member table
|
|
19
|
+
UPDATE "suggestions" s
|
|
20
|
+
SET workspace_id = (
|
|
21
|
+
SELECT m.organization_id
|
|
22
|
+
FROM "member" m
|
|
23
|
+
WHERE m.user_id = s.user_id
|
|
24
|
+
ORDER BY m.created_at ASC
|
|
25
|
+
LIMIT 1
|
|
26
|
+
)
|
|
27
|
+
WHERE s.workspace_id IS NULL;--> statement-breakpoint
|
|
28
|
+
|
|
29
|
+
-- Step 4: Set NOT NULL constraint (after backfill ensures no nulls remain)
|
|
30
|
+
ALTER TABLE "documents" ALTER COLUMN "workspace_id" SET NOT NULL;--> statement-breakpoint
|
|
31
|
+
ALTER TABLE "suggestions" ALTER COLUMN "workspace_id" SET NOT NULL;--> statement-breakpoint
|
|
32
|
+
|
|
33
|
+
-- Step 5: Add FK constraints
|
|
34
|
+
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
|
|
35
|
+
ALTER TABLE "suggestions" ADD CONSTRAINT "suggestions_workspace_id_organization_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."organization"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
36
|
+
|
|
37
|
+
-- Step 6: Create indexes for performance
|
|
38
|
+
CREATE INDEX "documents_workspace_id_idx" ON "documents" USING btree ("workspace_id");--> statement-breakpoint
|
|
39
|
+
CREATE INDEX "suggestions_workspace_id_idx" ON "suggestions" USING btree ("workspace_id");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ALTER TABLE "usage_records" ADD COLUMN "cost" real DEFAULT 0 NOT NULL;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
CREATE TABLE "competition_entries" (
|
|
2
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
3
|
+
"competition_id" text NOT NULL,
|
|
4
|
+
"workspace_id" text NOT NULL,
|
|
5
|
+
"school_name" text NOT NULL,
|
|
6
|
+
"class_name" text NOT NULL,
|
|
7
|
+
"assessment_count" integer DEFAULT 0 NOT NULL,
|
|
8
|
+
"total_score" integer DEFAULT 0 NOT NULL,
|
|
9
|
+
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
10
|
+
"updated_at" timestamp DEFAULT now() NOT NULL
|
|
11
|
+
);
|
|
12
|
+
--> statement-breakpoint
|
|
13
|
+
CREATE TABLE "competitions" (
|
|
14
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
15
|
+
"name" jsonb NOT NULL,
|
|
16
|
+
"description" jsonb NOT NULL,
|
|
17
|
+
"start_date" timestamp NOT NULL,
|
|
18
|
+
"end_date" timestamp NOT NULL,
|
|
19
|
+
"is_active" boolean DEFAULT false NOT NULL,
|
|
20
|
+
"prize_description" jsonb,
|
|
21
|
+
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
22
|
+
"updated_at" timestamp DEFAULT now() NOT NULL
|
|
23
|
+
);
|
|
24
|
+
--> statement-breakpoint
|
|
25
|
+
CREATE TABLE "image_generations" (
|
|
26
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
27
|
+
"user_id" text NOT NULL,
|
|
28
|
+
"workspace_id" text NOT NULL,
|
|
29
|
+
"tool_id" text NOT NULL,
|
|
30
|
+
"prompt" text NOT NULL,
|
|
31
|
+
"result_url" text,
|
|
32
|
+
"model" text DEFAULT 'gpt-image-1' NOT NULL,
|
|
33
|
+
"status" text DEFAULT 'pending' NOT NULL,
|
|
34
|
+
"error_message" text,
|
|
35
|
+
"created_at" timestamp DEFAULT now() NOT NULL
|
|
36
|
+
);
|
|
37
|
+
--> statement-breakpoint
|
|
38
|
+
CREATE TABLE "image_tools" (
|
|
39
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
40
|
+
"name" jsonb NOT NULL,
|
|
41
|
+
"description" jsonb NOT NULL,
|
|
42
|
+
"category" text NOT NULL,
|
|
43
|
+
"prompt_template" text NOT NULL,
|
|
44
|
+
"model" text DEFAULT 'gpt-image-1' NOT NULL,
|
|
45
|
+
"preview_image_url" text,
|
|
46
|
+
"is_active" boolean DEFAULT true NOT NULL,
|
|
47
|
+
"sort_order" integer DEFAULT 0 NOT NULL,
|
|
48
|
+
"is_trending" boolean DEFAULT false NOT NULL,
|
|
49
|
+
"is_seasonal" boolean DEFAULT false NOT NULL,
|
|
50
|
+
"active_months" integer[],
|
|
51
|
+
"season" text,
|
|
52
|
+
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
53
|
+
"updated_at" timestamp DEFAULT now() NOT NULL
|
|
54
|
+
);
|
|
55
|
+
--> statement-breakpoint
|
|
56
|
+
CREATE TABLE "knowledge_articles" (
|
|
57
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
58
|
+
"slug" text NOT NULL,
|
|
59
|
+
"category" text NOT NULL,
|
|
60
|
+
"title" jsonb NOT NULL,
|
|
61
|
+
"description" jsonb NOT NULL,
|
|
62
|
+
"content" jsonb NOT NULL,
|
|
63
|
+
"tags" text[],
|
|
64
|
+
"reading_time_minutes" integer DEFAULT 5 NOT NULL,
|
|
65
|
+
"sort_order" integer DEFAULT 0 NOT NULL,
|
|
66
|
+
"is_published" boolean DEFAULT false NOT NULL,
|
|
67
|
+
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
68
|
+
"updated_at" timestamp DEFAULT now() NOT NULL
|
|
69
|
+
);
|
|
70
|
+
--> statement-breakpoint
|
|
71
|
+
CREATE TABLE "referral_codes" (
|
|
72
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
73
|
+
"user_id" text NOT NULL,
|
|
74
|
+
"code" text NOT NULL,
|
|
75
|
+
"created_at" timestamp DEFAULT now() NOT NULL
|
|
76
|
+
);
|
|
77
|
+
--> statement-breakpoint
|
|
78
|
+
CREATE TABLE "referrals" (
|
|
79
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
80
|
+
"referrer_id" text NOT NULL,
|
|
81
|
+
"referred_user_id" text NOT NULL,
|
|
82
|
+
"referral_code_id" text NOT NULL,
|
|
83
|
+
"status" text DEFAULT 'pending' NOT NULL,
|
|
84
|
+
"completed_at" timestamp,
|
|
85
|
+
"created_at" timestamp DEFAULT now() NOT NULL
|
|
86
|
+
);
|
|
87
|
+
--> statement-breakpoint
|
|
88
|
+
CREATE TABLE "shared_reports" (
|
|
89
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
90
|
+
"user_id" text NOT NULL,
|
|
91
|
+
"workspace_id" text NOT NULL,
|
|
92
|
+
"report_type" text DEFAULT 'career' NOT NULL,
|
|
93
|
+
"report_data" jsonb NOT NULL,
|
|
94
|
+
"parent_report_id" text,
|
|
95
|
+
"conversation_id" text,
|
|
96
|
+
"is_public" boolean DEFAULT true NOT NULL,
|
|
97
|
+
"view_count" integer DEFAULT 0 NOT NULL,
|
|
98
|
+
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
99
|
+
"updated_at" timestamp DEFAULT now() NOT NULL
|
|
100
|
+
);
|
|
101
|
+
--> statement-breakpoint
|
|
102
|
+
CREATE TABLE "user_profiles" (
|
|
103
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
104
|
+
"user_id" text NOT NULL,
|
|
105
|
+
"workspace_id" text NOT NULL,
|
|
106
|
+
"product" text DEFAULT 'career' NOT NULL,
|
|
107
|
+
"interests" text,
|
|
108
|
+
"skills" text,
|
|
109
|
+
"education" text,
|
|
110
|
+
"goals" text,
|
|
111
|
+
"constraints" text,
|
|
112
|
+
"completed_phases" text,
|
|
113
|
+
"last_assessment_at" timestamp,
|
|
114
|
+
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
115
|
+
"updated_at" timestamp DEFAULT now() NOT NULL
|
|
116
|
+
);
|
|
117
|
+
--> statement-breakpoint
|
|
118
|
+
ALTER TABLE "agents" ADD COLUMN "product_type" text DEFAULT 'chat' NOT NULL;--> statement-breakpoint
|
|
119
|
+
ALTER TABLE "competition_entries" ADD CONSTRAINT "competition_entries_competition_id_competitions_id_fk" FOREIGN KEY ("competition_id") REFERENCES "public"."competitions"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
120
|
+
ALTER TABLE "competition_entries" ADD CONSTRAINT "competition_entries_workspace_id_organization_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."organization"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
121
|
+
ALTER TABLE "image_generations" ADD CONSTRAINT "image_generations_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
122
|
+
ALTER TABLE "image_generations" ADD CONSTRAINT "image_generations_workspace_id_organization_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."organization"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
123
|
+
ALTER TABLE "image_generations" ADD CONSTRAINT "image_generations_tool_id_image_tools_id_fk" FOREIGN KEY ("tool_id") REFERENCES "public"."image_tools"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
124
|
+
ALTER TABLE "referral_codes" ADD CONSTRAINT "referral_codes_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
125
|
+
ALTER TABLE "referrals" ADD CONSTRAINT "referrals_referrer_id_users_id_fk" FOREIGN KEY ("referrer_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
126
|
+
ALTER TABLE "referrals" ADD CONSTRAINT "referrals_referred_user_id_users_id_fk" FOREIGN KEY ("referred_user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
127
|
+
ALTER TABLE "referrals" ADD CONSTRAINT "referrals_referral_code_id_referral_codes_id_fk" FOREIGN KEY ("referral_code_id") REFERENCES "public"."referral_codes"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
128
|
+
ALTER TABLE "shared_reports" ADD CONSTRAINT "shared_reports_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
129
|
+
ALTER TABLE "shared_reports" ADD CONSTRAINT "shared_reports_workspace_id_organization_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."organization"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
130
|
+
ALTER TABLE "user_profiles" ADD CONSTRAINT "user_profiles_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
131
|
+
ALTER TABLE "user_profiles" ADD CONSTRAINT "user_profiles_workspace_id_organization_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."organization"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
132
|
+
CREATE INDEX "competition_entries_competition_id_idx" ON "competition_entries" USING btree ("competition_id");--> statement-breakpoint
|
|
133
|
+
CREATE INDEX "competition_entries_workspace_id_idx" ON "competition_entries" USING btree ("workspace_id");--> statement-breakpoint
|
|
134
|
+
CREATE UNIQUE INDEX "competition_entries_competition_workspace_idx" ON "competition_entries" USING btree ("competition_id","workspace_id");--> statement-breakpoint
|
|
135
|
+
CREATE INDEX "competitions_is_active_idx" ON "competitions" USING btree ("is_active");--> statement-breakpoint
|
|
136
|
+
CREATE INDEX "image_generations_user_id_idx" ON "image_generations" USING btree ("user_id");--> statement-breakpoint
|
|
137
|
+
CREATE INDEX "image_generations_workspace_id_idx" ON "image_generations" USING btree ("workspace_id");--> statement-breakpoint
|
|
138
|
+
CREATE INDEX "image_generations_tool_id_idx" ON "image_generations" USING btree ("tool_id");--> statement-breakpoint
|
|
139
|
+
CREATE INDEX "image_generations_created_at_idx" ON "image_generations" USING btree ("created_at");--> statement-breakpoint
|
|
140
|
+
CREATE UNIQUE INDEX "knowledge_articles_slug_idx" ON "knowledge_articles" USING btree ("slug");--> statement-breakpoint
|
|
141
|
+
CREATE INDEX "knowledge_articles_category_idx" ON "knowledge_articles" USING btree ("category");--> statement-breakpoint
|
|
142
|
+
CREATE UNIQUE INDEX "referral_codes_code_idx" ON "referral_codes" USING btree ("code");--> statement-breakpoint
|
|
143
|
+
CREATE UNIQUE INDEX "referral_codes_user_id_idx" ON "referral_codes" USING btree ("user_id");--> statement-breakpoint
|
|
144
|
+
CREATE INDEX "referrals_referrer_id_idx" ON "referrals" USING btree ("referrer_id");--> statement-breakpoint
|
|
145
|
+
CREATE INDEX "referrals_referred_user_id_idx" ON "referrals" USING btree ("referred_user_id");--> statement-breakpoint
|
|
146
|
+
CREATE UNIQUE INDEX "referrals_referred_user_id_unique_idx" ON "referrals" USING btree ("referred_user_id");--> statement-breakpoint
|
|
147
|
+
CREATE INDEX "shared_reports_user_id_idx" ON "shared_reports" USING btree ("user_id");--> statement-breakpoint
|
|
148
|
+
CREATE INDEX "shared_reports_workspace_id_idx" ON "shared_reports" USING btree ("workspace_id");--> statement-breakpoint
|
|
149
|
+
CREATE INDEX "user_profiles_user_id_idx" ON "user_profiles" USING btree ("user_id");--> statement-breakpoint
|
|
150
|
+
CREATE UNIQUE INDEX "user_profiles_workspace_user_product_idx" ON "user_profiles" USING btree ("workspace_id","user_id","product");--> statement-breakpoint
|
|
151
|
+
CREATE INDEX "votes_message_id_idx" ON "votes" USING btree ("message_id");
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
-- HNSW index for fast cosine similarity search on knowledge chunks
|
|
2
|
+
-- Required for knowledgeSearch tool to perform semantic vector search efficiently
|
|
3
|
+
-- Uses cosine distance operator (<=>) which is the default for text-embedding-3-small
|
|
4
|
+
--
|
|
5
|
+
-- Run with: psql $DATABASE_URL -f packages/core/src/db/migrations/0011_hnsw_vector_index.sql
|
|
6
|
+
-- Or via: cd packages/core && pnpm drizzle-kit push (if using Drizzle migration runner)
|
|
7
|
+
|
|
8
|
+
CREATE INDEX IF NOT EXISTS knowledge_chunks_embedding_hnsw_idx
|
|
9
|
+
ON knowledge_chunks
|
|
10
|
+
USING hnsw (embedding vector_cosine_ops)
|
|
11
|
+
WITH (m = 16, ef_construction = 64);
|
|
12
|
+
|
|
13
|
+
-- Composite index for product-scoped document lookups
|
|
14
|
+
-- Used by knowledgeSearch to filter chunks by product via knowledgeDocuments join
|
|
15
|
+
CREATE INDEX IF NOT EXISTS knowledge_documents_product_status_idx
|
|
16
|
+
ON knowledge_documents (product, status)
|
|
17
|
+
WHERE status = 'ready';
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
-- User profiles table for persistent career assessment data
|
|
2
|
+
-- Stores profile data that persists across conversations for returning user detection
|
|
3
|
+
-- and personalized experiences, scoped per user per workspace per product.
|
|
4
|
+
--
|
|
5
|
+
-- Run with: psql $DATABASE_URL -f packages/core/src/db/migrations/0012_user_profiles.sql
|
|
6
|
+
-- Or via the migration runner in the app bootstrap
|
|
7
|
+
|
|
8
|
+
CREATE TABLE IF NOT EXISTS "user_profiles" (
|
|
9
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
10
|
+
"user_id" text NOT NULL REFERENCES "users"("id") ON DELETE CASCADE,
|
|
11
|
+
"workspace_id" text NOT NULL REFERENCES "organization"("id") ON DELETE CASCADE,
|
|
12
|
+
"product" text NOT NULL DEFAULT 'career',
|
|
13
|
+
"interests" text,
|
|
14
|
+
"skills" text,
|
|
15
|
+
"education" text,
|
|
16
|
+
"goals" text,
|
|
17
|
+
"constraints" text,
|
|
18
|
+
"completed_phases" text,
|
|
19
|
+
"last_assessment_at" timestamp,
|
|
20
|
+
"created_at" timestamp NOT NULL DEFAULT now(),
|
|
21
|
+
"updated_at" timestamp NOT NULL DEFAULT now()
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
-- Unique composite index: one profile per user per workspace per product
|
|
25
|
+
CREATE UNIQUE INDEX IF NOT EXISTS "user_profiles_workspace_user_product_idx"
|
|
26
|
+
ON "user_profiles" ("workspace_id", "user_id", "product");
|
|
27
|
+
|
|
28
|
+
-- Index for user-based lookups (all profiles for a user)
|
|
29
|
+
CREATE INDEX IF NOT EXISTS "user_profiles_user_id_idx"
|
|
30
|
+
ON "user_profiles" ("user_id");
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
-- Add trending and seasonal columns to image_tools table
|
|
2
|
+
-- Phase 61: Schema foundation for trending engine (Phase 62) and seasonal templates (Phase 63)
|
|
3
|
+
--
|
|
4
|
+
-- Run with: psql $DATABASE_URL -f packages/core/src/db/migrations/0013_trending_seasonal_columns.sql
|
|
5
|
+
|
|
6
|
+
ALTER TABLE "image_tools" ADD COLUMN IF NOT EXISTS "is_trending" boolean NOT NULL DEFAULT false;
|
|
7
|
+
ALTER TABLE "image_tools" ADD COLUMN IF NOT EXISTS "is_seasonal" boolean NOT NULL DEFAULT false;
|
|
8
|
+
ALTER TABLE "image_tools" ADD COLUMN IF NOT EXISTS "active_months" integer[];
|
|
9
|
+
ALTER TABLE "image_tools" ADD COLUMN IF NOT EXISTS "season" text;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
-- Add product_type column to agents table
|
|
2
|
+
-- Required by Drizzle schema: agents.productType (text, not null, default 'chat')
|
|
3
|
+
--
|
|
4
|
+
-- Run with: psql $DATABASE_URL -f packages/core/src/db/migrations/0014_add_product_type_to_agents.sql
|
|
5
|
+
|
|
6
|
+
ALTER TABLE "agents" ADD COLUMN IF NOT EXISTS "product_type" text NOT NULL DEFAULT 'chat';
|