diff --git a/apps/backend/migrations-postgres/0053_add_memories_project_id.sql b/apps/backend/migrations-postgres/0053_add_memories_project_id.sql new file mode 100644 index 000000000..3f4e8ab79 --- /dev/null +++ b/apps/backend/migrations-postgres/0053_add_memories_project_id.sql @@ -0,0 +1,3 @@ +ALTER TABLE "memories" ADD COLUMN "project_id" text;--> statement-breakpoint +ALTER TABLE "memories" ADD CONSTRAINT "memories_project_id_project_id_fk" FOREIGN KEY ("project_id") REFERENCES "public"."project"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +CREATE INDEX "memories_projectId_idx" ON "memories" USING btree ("project_id"); \ No newline at end of file diff --git a/apps/backend/migrations-postgres/meta/0053_snapshot.json b/apps/backend/migrations-postgres/meta/0053_snapshot.json new file mode 100644 index 000000000..d7ebf5443 --- /dev/null +++ b/apps/backend/migrations-postgres/meta/0053_snapshot.json @@ -0,0 +1,6527 @@ +{ + "id": "5c33f68a-9b7d-4249-a164-0d8ae600dd01", + "prevId": "a16666c9-43a3-40d9-8e46-9e1bf8ad5ee7", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.account": { + "name": "account", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "account_id": { + "name": "account_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "provider_id": { + "name": "provider_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "access_token": { + "name": "access_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "refresh_token": { + "name": "refresh_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "id_token": { + "name": "id_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "access_token_expires_at": { + "name": "access_token_expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "refresh_token_expires_at": { + "name": "refresh_token_expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "scope": { + "name": "scope", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "password": { + "name": "password", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "account_userId_idx": { + "name": "account_userId_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "account_user_id_user_id_fk": { + "name": "account_user_id_user_id_fk", + "tableFrom": "account", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.activity": { + "name": "activity", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'completed'" + }, + "trigger": { + "name": "trigger", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'system'" + }, + "story_id": { + "name": "story_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "chat_id": { + "name": "chat_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "shared_story_id": { + "name": "shared_story_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "shared_chat_id": { + "name": "shared_chat_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "payload": { + "name": "payload", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "error_message": { + "name": "error_message", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "started_at": { + "name": "started_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "activity_projectId_idx": { + "name": "activity_projectId_idx", + "columns": [ + { + "expression": "project_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "activity_userId_idx": { + "name": "activity_userId_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "activity_type_idx": { + "name": "activity_type_idx", + "columns": [ + { + "expression": "type", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "activity_storyId_idx": { + "name": "activity_storyId_idx", + "columns": [ + { + "expression": "story_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "activity_chatId_idx": { + "name": "activity_chatId_idx", + "columns": [ + { + "expression": "chat_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "activity_sharedStoryId_idx": { + "name": "activity_sharedStoryId_idx", + "columns": [ + { + "expression": "shared_story_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "activity_sharedChatId_idx": { + "name": "activity_sharedChatId_idx", + "columns": [ + { + "expression": "shared_chat_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "activity_startedAt_idx": { + "name": "activity_startedAt_idx", + "columns": [ + { + "expression": "started_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "activity_project_id_project_id_fk": { + "name": "activity_project_id_project_id_fk", + "tableFrom": "activity", + "tableTo": "project", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "activity_user_id_user_id_fk": { + "name": "activity_user_id_user_id_fk", + "tableFrom": "activity", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "activity_story_id_story_id_fk": { + "name": "activity_story_id_story_id_fk", + "tableFrom": "activity", + "tableTo": "story", + "columnsFrom": [ + "story_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "activity_chat_id_chat_id_fk": { + "name": "activity_chat_id_chat_id_fk", + "tableFrom": "activity", + "tableTo": "chat", + "columnsFrom": [ + "chat_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "activity_shared_story_id_shared_story_id_fk": { + "name": "activity_shared_story_id_shared_story_id_fk", + "tableFrom": "activity", + "tableTo": "shared_story", + "columnsFrom": [ + "shared_story_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "activity_shared_chat_id_shared_chat_id_fk": { + "name": "activity_shared_chat_id_shared_chat_id_fk", + "tableFrom": "activity", + "tableTo": "shared_chat", + "columnsFrom": [ + "shared_chat_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.analytics_event": { + "name": "analytics_event", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "asset_type": { + "name": "asset_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "actor_user_id": { + "name": "actor_user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "chat_id": { + "name": "chat_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "story_id": { + "name": "story_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "shared_chat_id": { + "name": "shared_chat_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "shared_story_id": { + "name": "shared_story_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "analytics_event_projectId_idx": { + "name": "analytics_event_projectId_idx", + "columns": [ + { + "expression": "project_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "analytics_event_chatId_idx": { + "name": "analytics_event_chatId_idx", + "columns": [ + { + "expression": "chat_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "analytics_event_storyId_idx": { + "name": "analytics_event_storyId_idx", + "columns": [ + { + "expression": "story_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "analytics_event_sharedChatId_idx": { + "name": "analytics_event_sharedChatId_idx", + "columns": [ + { + "expression": "shared_chat_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "analytics_event_sharedStoryId_idx": { + "name": "analytics_event_sharedStoryId_idx", + "columns": [ + { + "expression": "shared_story_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "analytics_event_actorUserId_idx": { + "name": "analytics_event_actorUserId_idx", + "columns": [ + { + "expression": "actor_user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "analytics_event_type_createdAt_idx": { + "name": "analytics_event_type_createdAt_idx", + "columns": [ + { + "expression": "type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "analytics_event_project_id_project_id_fk": { + "name": "analytics_event_project_id_project_id_fk", + "tableFrom": "analytics_event", + "tableTo": "project", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "analytics_event_actor_user_id_user_id_fk": { + "name": "analytics_event_actor_user_id_user_id_fk", + "tableFrom": "analytics_event", + "tableTo": "user", + "columnsFrom": [ + "actor_user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "analytics_event_chat_id_chat_id_fk": { + "name": "analytics_event_chat_id_chat_id_fk", + "tableFrom": "analytics_event", + "tableTo": "chat", + "columnsFrom": [ + "chat_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "analytics_event_story_id_story_id_fk": { + "name": "analytics_event_story_id_story_id_fk", + "tableFrom": "analytics_event", + "tableTo": "story", + "columnsFrom": [ + "story_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "analytics_event_shared_chat_id_shared_chat_id_fk": { + "name": "analytics_event_shared_chat_id_shared_chat_id_fk", + "tableFrom": "analytics_event", + "tableTo": "shared_chat", + "columnsFrom": [ + "shared_chat_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "analytics_event_shared_story_id_shared_story_id_fk": { + "name": "analytics_event_shared_story_id_shared_story_id_fk", + "tableFrom": "analytics_event", + "tableTo": "shared_story", + "columnsFrom": [ + "shared_story_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "analytics_event_asset_id_required": { + "name": "analytics_event_asset_id_required", + "value": "CASE WHEN \"analytics_event\".\"asset_type\" = 'chat' THEN \"analytics_event\".\"chat_id\" IS NOT NULL WHEN \"analytics_event\".\"asset_type\" = 'story' THEN \"analytics_event\".\"story_id\" IS NOT NULL ELSE TRUE END" + } + }, + "isRLSEnabled": false + }, + "public.api_key": { + "name": "api_key", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "org_id": { + "name": "org_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "key_hash": { + "name": "key_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "key_prefix": { + "name": "key_prefix", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "last_used_at": { + "name": "last_used_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "api_key_orgId_idx": { + "name": "api_key_orgId_idx", + "columns": [ + { + "expression": "org_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "api_key_org_id_organization_id_fk": { + "name": "api_key_org_id_organization_id_fk", + "tableFrom": "api_key", + "tableTo": "organization", + "columnsFrom": [ + "org_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "api_key_created_by_user_id_fk": { + "name": "api_key_created_by_user_id_fk", + "tableFrom": "api_key", + "tableTo": "user", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "api_key_key_hash_unique": { + "name": "api_key_key_hash_unique", + "nullsNotDistinct": false, + "columns": [ + "key_hash" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.automation": { + "name": "automation", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "scheduled_job_id": { + "name": "scheduled_job_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "prompt": { + "name": "prompt", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "schedule_description": { + "name": "schedule_description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "timezone": { + "name": "timezone", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "model_provider": { + "name": "model_provider", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "model_id": { + "name": "model_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "mcp_enabled": { + "name": "mcp_enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "mcp_servers": { + "name": "mcp_servers", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "integrations": { + "name": "integrations", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "automation_projectId_idx": { + "name": "automation_projectId_idx", + "columns": [ + { + "expression": "project_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "automation_userId_idx": { + "name": "automation_userId_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "automation_scheduledJobId_idx": { + "name": "automation_scheduledJobId_idx", + "columns": [ + { + "expression": "scheduled_job_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "automation_project_id_project_id_fk": { + "name": "automation_project_id_project_id_fk", + "tableFrom": "automation", + "tableTo": "project", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "automation_user_id_user_id_fk": { + "name": "automation_user_id_user_id_fk", + "tableFrom": "automation", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "automation_scheduled_job_id_scheduled_job_id_fk": { + "name": "automation_scheduled_job_id_scheduled_job_id_fk", + "tableFrom": "automation", + "tableTo": "scheduled_job", + "columnsFrom": [ + "scheduled_job_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.automation_run": { + "name": "automation_run", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "automation_id": { + "name": "automation_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "chat_id": { + "name": "chat_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'running'" + }, + "started_at": { + "name": "started_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "error_message": { + "name": "error_message", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "integration_results": { + "name": "integration_results", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + } + }, + "indexes": { + "automation_run_automationId_idx": { + "name": "automation_run_automationId_idx", + "columns": [ + { + "expression": "automation_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "automation_run_chatId_idx": { + "name": "automation_run_chatId_idx", + "columns": [ + { + "expression": "chat_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "automation_run_status_idx": { + "name": "automation_run_status_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "automation_run_automation_id_automation_id_fk": { + "name": "automation_run_automation_id_automation_id_fk", + "tableFrom": "automation_run", + "tableTo": "automation", + "columnsFrom": [ + "automation_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "automation_run_chat_id_chat_id_fk": { + "name": "automation_run_chat_id_chat_id_fk", + "tableFrom": "automation_run", + "tableTo": "chat", + "columnsFrom": [ + "chat_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.branding_config": { + "name": "branding_config", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "app_name": { + "name": "app_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "tab_title": { + "name": "tab_title", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "logo_data": { + "name": "logo_data", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "logo_media_type": { + "name": "logo_media_type", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "favicon_data": { + "name": "favicon_data", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "favicon_media_type": { + "name": "favicon_media_type", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "brand_color": { + "name": "brand_color", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.chat": { + "name": "chat", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'New Conversation'" + }, + "is_starred": { + "name": "is_starred", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "slack_thread_id": { + "name": "slack_thread_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "teams_thread_id": { + "name": "teams_thread_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "telegram_thread_id": { + "name": "telegram_thread_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "whatsapp_thread_id": { + "name": "whatsapp_thread_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "fork_metadata": { + "name": "fork_metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "chat_userId_idx": { + "name": "chat_userId_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "chat_projectId_idx": { + "name": "chat_projectId_idx", + "columns": [ + { + "expression": "project_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "chat_slack_thread_idx": { + "name": "chat_slack_thread_idx", + "columns": [ + { + "expression": "slack_thread_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "chat_teams_thread_idx": { + "name": "chat_teams_thread_idx", + "columns": [ + { + "expression": "teams_thread_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "chat_telegram_thread_idx": { + "name": "chat_telegram_thread_idx", + "columns": [ + { + "expression": "telegram_thread_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "chat_whatsapp_thread_idx": { + "name": "chat_whatsapp_thread_idx", + "columns": [ + { + "expression": "whatsapp_thread_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "chat_user_id_user_id_fk": { + "name": "chat_user_id_user_id_fk", + "tableFrom": "chat", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "chat_project_id_project_id_fk": { + "name": "chat_project_id_project_id_fk", + "tableFrom": "chat", + "tableTo": "project", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.chat_message": { + "name": "chat_message", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "chat_id": { + "name": "chat_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "role": { + "name": "role", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "stop_reason": { + "name": "stop_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "error_message": { + "name": "error_message", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "llm_provider": { + "name": "llm_provider", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "llm_model_id": { + "name": "llm_model_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "superseded_at": { + "name": "superseded_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "version_group_id": { + "name": "version_group_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "isForked": { + "name": "isForked", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "citation": { + "name": "citation", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "input_total_tokens": { + "name": "input_total_tokens", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "input_no_cache_tokens": { + "name": "input_no_cache_tokens", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "input_cache_read_tokens": { + "name": "input_cache_read_tokens", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "input_cache_write_tokens": { + "name": "input_cache_write_tokens", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "output_total_tokens": { + "name": "output_total_tokens", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "output_text_tokens": { + "name": "output_text_tokens", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "output_reasoning_tokens": { + "name": "output_reasoning_tokens", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "total_tokens": { + "name": "total_tokens", + "type": "integer", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "chat_message_chatId_idx": { + "name": "chat_message_chatId_idx", + "columns": [ + { + "expression": "chat_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "chat_message_createdAt_idx": { + "name": "chat_message_createdAt_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "chat_message_versionGroupId_idx": { + "name": "chat_message_versionGroupId_idx", + "columns": [ + { + "expression": "version_group_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "chat_message_chat_id_chat_id_fk": { + "name": "chat_message_chat_id_chat_id_fk", + "tableFrom": "chat_message", + "tableTo": "chat", + "columnsFrom": [ + "chat_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.context_recommendation": { + "name": "context_recommendation", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "run_id": { + "name": "run_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "fingerprint": { + "name": "fingerprint", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "suggested_file": { + "name": "suggested_file", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "subject_key": { + "name": "subject_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'open'" + }, + "snoozed_until": { + "name": "snoozed_until", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "severity": { + "name": "severity", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'medium'" + }, + "impact_score": { + "name": "impact_score", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "impact": { + "name": "impact", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "insights": { + "name": "insights", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "summary": { + "name": "summary", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "suggested_action": { + "name": "suggested_action", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "fix_kind": { + "name": "fix_kind", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "proposed_edits": { + "name": "proposed_edits", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "fix_guidance": { + "name": "fix_guidance", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "fix_prompt": { + "name": "fix_prompt", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "pr_url": { + "name": "pr_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "pr_branch": { + "name": "pr_branch", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "pr_created_at": { + "name": "pr_created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "llm_provider": { + "name": "llm_provider", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "llm_model_id": { + "name": "llm_model_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "first_seen_at": { + "name": "first_seen_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "last_seen_at": { + "name": "last_seen_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "occurrence_count": { + "name": "occurrence_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "status_changed_at": { + "name": "status_changed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "status_changed_by": { + "name": "status_changed_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "context_recommendation_project_fingerprint_unique": { + "name": "context_recommendation_project_fingerprint_unique", + "columns": [ + { + "expression": "project_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "fingerprint", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "context_recommendation_projectId_status_idx": { + "name": "context_recommendation_projectId_status_idx", + "columns": [ + { + "expression": "project_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "context_recommendation_runId_idx": { + "name": "context_recommendation_runId_idx", + "columns": [ + { + "expression": "run_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "context_recommendation_project_id_project_id_fk": { + "name": "context_recommendation_project_id_project_id_fk", + "tableFrom": "context_recommendation", + "tableTo": "project", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "context_recommendation_status_changed_by_user_id_fk": { + "name": "context_recommendation_status_changed_by_user_id_fk", + "tableFrom": "context_recommendation", + "tableTo": "user", + "columnsFrom": [ + "status_changed_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "context_recommendation_run_fk": { + "name": "context_recommendation_run_fk", + "tableFrom": "context_recommendation", + "tableTo": "context_recommendation_run", + "columnsFrom": [ + "run_id", + "project_id" + ], + "columnsTo": [ + "id", + "project_id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.context_recommendation_config": { + "name": "context_recommendation_config", + "schema": "", + "columns": { + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "model_provider": { + "name": "model_provider", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "model_id": { + "name": "model_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "frequency": { + "name": "frequency", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "custom_system_prompt_instructions": { + "name": "custom_system_prompt_instructions", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "repo_full_name": { + "name": "repo_full_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "auto_create_prs": { + "name": "auto_create_prs", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "max_auto_prs_per_run": { + "name": "max_auto_prs_per_run", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "context_recommendation_config_project_id_project_id_fk": { + "name": "context_recommendation_config_project_id_project_id_fk", + "tableFrom": "context_recommendation_config", + "tableTo": "project", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.context_recommendation_run": { + "name": "context_recommendation_run", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "chat_id": { + "name": "chat_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "trigger": { + "name": "trigger", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'schedule'" + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'running'" + }, + "window_start": { + "name": "window_start", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "window_end": { + "name": "window_end", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "started_at": { + "name": "started_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "error_message": { + "name": "error_message", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "llm_provider": { + "name": "llm_provider", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "llm_model_id": { + "name": "llm_model_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "input_total_tokens": { + "name": "input_total_tokens", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "output_total_tokens": { + "name": "output_total_tokens", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "total_tokens": { + "name": "total_tokens", + "type": "integer", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "context_recommendation_run_projectId_idx": { + "name": "context_recommendation_run_projectId_idx", + "columns": [ + { + "expression": "project_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "context_recommendation_run_chatId_idx": { + "name": "context_recommendation_run_chatId_idx", + "columns": [ + { + "expression": "chat_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "context_recommendation_run_status_idx": { + "name": "context_recommendation_run_status_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "context_recommendation_run_project_id_project_id_fk": { + "name": "context_recommendation_run_project_id_project_id_fk", + "tableFrom": "context_recommendation_run", + "tableTo": "project", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "context_recommendation_run_chat_id_chat_id_fk": { + "name": "context_recommendation_run_chat_id_chat_id_fk", + "tableFrom": "context_recommendation_run", + "tableTo": "chat", + "columnsFrom": [ + "chat_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "context_recommendation_run_id_project_unique": { + "name": "context_recommendation_run_id_project_unique", + "nullsNotDistinct": false, + "columns": [ + "id", + "project_id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.favorite": { + "name": "favorite", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "story_id": { + "name": "story_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "folder_id": { + "name": "folder_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "favorite_user_id_idx": { + "name": "favorite_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "favorite_user_id_user_id_fk": { + "name": "favorite_user_id_user_id_fk", + "tableFrom": "favorite", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "favorite_story_id_story_id_fk": { + "name": "favorite_story_id_story_id_fk", + "tableFrom": "favorite", + "tableTo": "story", + "columnsFrom": [ + "story_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "favorite_folder_id_story_folder_id_fk": { + "name": "favorite_folder_id_story_folder_id_fk", + "tableFrom": "favorite", + "tableTo": "story_folder", + "columnsFrom": [ + "folder_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "favorite_user_id_story_id_unique": { + "name": "favorite_user_id_story_id_unique", + "nullsNotDistinct": false, + "columns": [ + "user_id", + "story_id" + ] + }, + "favorite_user_id_folder_id_unique": { + "name": "favorite_user_id_folder_id_unique", + "nullsNotDistinct": false, + "columns": [ + "user_id", + "folder_id" + ] + } + }, + "policies": {}, + "checkConstraints": { + "favorite_xor_target": { + "name": "favorite_xor_target", + "value": "(\"favorite\".\"story_id\" IS NOT NULL)::int + (\"favorite\".\"folder_id\" IS NOT NULL)::int = 1" + } + }, + "isRLSEnabled": false + }, + "public.jwks": { + "name": "jwks", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "public_key": { + "name": "public_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "private_key": { + "name": "private_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.llm_inference": { + "name": "llm_inference", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "chat_id": { + "name": "chat_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "llm_provider": { + "name": "llm_provider", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "llm_model_id": { + "name": "llm_model_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "input_total_tokens": { + "name": "input_total_tokens", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "input_no_cache_tokens": { + "name": "input_no_cache_tokens", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "input_cache_read_tokens": { + "name": "input_cache_read_tokens", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "input_cache_write_tokens": { + "name": "input_cache_write_tokens", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "output_total_tokens": { + "name": "output_total_tokens", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "output_text_tokens": { + "name": "output_text_tokens", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "output_reasoning_tokens": { + "name": "output_reasoning_tokens", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "total_tokens": { + "name": "total_tokens", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "llm_inference_projectId_idx": { + "name": "llm_inference_projectId_idx", + "columns": [ + { + "expression": "project_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "llm_inference_userId_idx": { + "name": "llm_inference_userId_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "llm_inference_type_idx": { + "name": "llm_inference_type_idx", + "columns": [ + { + "expression": "type", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "llm_inference_project_id_project_id_fk": { + "name": "llm_inference_project_id_project_id_fk", + "tableFrom": "llm_inference", + "tableTo": "project", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "llm_inference_user_id_user_id_fk": { + "name": "llm_inference_user_id_user_id_fk", + "tableFrom": "llm_inference", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "llm_inference_chat_id_chat_id_fk": { + "name": "llm_inference_chat_id_chat_id_fk", + "tableFrom": "llm_inference", + "tableTo": "chat", + "columnsFrom": [ + "chat_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.log": { + "name": "log", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "level": { + "name": "level", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "message": { + "name": "message", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "context": { + "name": "context", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "log_createdAt_idx": { + "name": "log_createdAt_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "log_level_idx": { + "name": "log_level_idx", + "columns": [ + { + "expression": "level", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "log_projectId_idx": { + "name": "log_projectId_idx", + "columns": [ + { + "expression": "project_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "log_project_id_project_id_fk": { + "name": "log_project_id_project_id_fk", + "tableFrom": "log", + "tableTo": "project", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.mcp_call_log": { + "name": "mcp_call_log", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "tool_name": { + "name": "tool_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "duration_ms": { + "name": "duration_ms", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "success": { + "name": "success", + "type": "boolean", + "primaryKey": false, + "notNull": true + }, + "tool_input": { + "name": "tool_input", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "tool_output": { + "name": "tool_output", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "called_at": { + "name": "called_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "mcp_call_log_projectId_idx": { + "name": "mcp_call_log_projectId_idx", + "columns": [ + { + "expression": "project_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "mcp_call_log_userId_idx": { + "name": "mcp_call_log_userId_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "mcp_call_log_calledAt_idx": { + "name": "mcp_call_log_calledAt_idx", + "columns": [ + { + "expression": "called_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "mcp_call_log_project_id_project_id_fk": { + "name": "mcp_call_log_project_id_project_id_fk", + "tableFrom": "mcp_call_log", + "tableTo": "project", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "mcp_call_log_user_id_user_id_fk": { + "name": "mcp_call_log_user_id_user_id_fk", + "tableFrom": "mcp_call_log", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.mcp_chart_embed": { + "name": "mcp_chart_embed", + "schema": "", + "columns": { + "chart_embed_id": { + "name": "chart_embed_id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "query_id": { + "name": "query_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "chart_config": { + "name": "chart_config", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "source_chat_id": { + "name": "source_chat_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "mcp_chart_embed_query_id_idx": { + "name": "mcp_chart_embed_query_id_idx", + "columns": [ + { + "expression": "query_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "mcp_chart_embed_query_id_mcp_query_data_query_id_fk": { + "name": "mcp_chart_embed_query_id_mcp_query_data_query_id_fk", + "tableFrom": "mcp_chart_embed", + "tableTo": "mcp_query_data", + "columnsFrom": [ + "query_id" + ], + "columnsTo": [ + "query_id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.mcp_query_data": { + "name": "mcp_query_data", + "schema": "", + "columns": { + "query_id": { + "name": "query_id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "call_log_id": { + "name": "call_log_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "source_chat_id": { + "name": "source_chat_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "columns": { + "name": "columns", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "data": { + "name": "data", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "mcp_query_data_project_id_idx": { + "name": "mcp_query_data_project_id_idx", + "columns": [ + { + "expression": "project_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "mcp_query_data_callLogId_idx": { + "name": "mcp_query_data_callLogId_idx", + "columns": [ + { + "expression": "call_log_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "mcp_query_data_project_id_project_id_fk": { + "name": "mcp_query_data_project_id_project_id_fk", + "tableFrom": "mcp_query_data", + "tableTo": "project", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.memories": { + "name": "memories", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "content": { + "name": "content", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "category": { + "name": "category", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "chat_id": { + "name": "chat_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "superseded_by": { + "name": "superseded_by", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "memories_userId_idx": { + "name": "memories_userId_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "memories_chatId_idx": { + "name": "memories_chatId_idx", + "columns": [ + { + "expression": "chat_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "memories_projectId_idx": { + "name": "memories_projectId_idx", + "columns": [ + { + "expression": "project_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "memories_supersededBy_idx": { + "name": "memories_supersededBy_idx", + "columns": [ + { + "expression": "superseded_by", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "memories_user_id_user_id_fk": { + "name": "memories_user_id_user_id_fk", + "tableFrom": "memories", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "memories_chat_id_chat_id_fk": { + "name": "memories_chat_id_chat_id_fk", + "tableFrom": "memories", + "tableTo": "chat", + "columnsFrom": [ + "chat_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "memories_project_id_project_id_fk": { + "name": "memories_project_id_project_id_fk", + "tableFrom": "memories", + "tableTo": "project", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.message_feedback": { + "name": "message_feedback", + "schema": "", + "columns": { + "message_id": { + "name": "message_id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "vote": { + "name": "vote", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "explanation": { + "name": "explanation", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "message_feedback_message_id_chat_message_id_fk": { + "name": "message_feedback_message_id_chat_message_id_fk", + "tableFrom": "message_feedback", + "tableTo": "chat_message", + "columnsFrom": [ + "message_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.message_image": { + "name": "message_image", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "data": { + "name": "data", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "media_type": { + "name": "media_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.message_part": { + "name": "message_part", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "message_id": { + "name": "message_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "order": { + "name": "order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "text": { + "name": "text", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "reasoning_text": { + "name": "reasoning_text", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "tool_call_id": { + "name": "tool_call_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "tool_name": { + "name": "tool_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "tool_state": { + "name": "tool_state", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "tool_error_text": { + "name": "tool_error_text", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "tool_input": { + "name": "tool_input", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "tool_raw_input": { + "name": "tool_raw_input", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "tool_output": { + "name": "tool_output", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "tool_approval_id": { + "name": "tool_approval_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "tool_approval_approved": { + "name": "tool_approval_approved", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "tool_approval_reason": { + "name": "tool_approval_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "tool_provider_metadata": { + "name": "tool_provider_metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "provider_metadata": { + "name": "provider_metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "media_type": { + "name": "media_type", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "image_id": { + "name": "image_id", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "parts_message_id_idx": { + "name": "parts_message_id_idx", + "columns": [ + { + "expression": "message_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "parts_message_id_order_idx": { + "name": "parts_message_id_order_idx", + "columns": [ + { + "expression": "message_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "message_part_message_id_chat_message_id_fk": { + "name": "message_part_message_id_chat_message_id_fk", + "tableFrom": "message_part", + "tableTo": "chat_message", + "columnsFrom": [ + "message_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "message_part_image_id_message_image_id_fk": { + "name": "message_part_image_id_message_image_id_fk", + "tableFrom": "message_part", + "tableTo": "message_image", + "columnsFrom": [ + "image_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "message_part_tool_call_id_unique": { + "name": "message_part_tool_call_id_unique", + "nullsNotDistinct": false, + "columns": [ + "tool_call_id" + ] + } + }, + "policies": {}, + "checkConstraints": { + "text_required_if_type_is_text": { + "name": "text_required_if_type_is_text", + "value": "CASE WHEN \"message_part\".\"type\" = 'text' THEN \"message_part\".\"text\" IS NOT NULL ELSE TRUE END" + }, + "reasoning_text_required_if_type_is_reasoning": { + "name": "reasoning_text_required_if_type_is_reasoning", + "value": "CASE WHEN \"message_part\".\"type\" = 'reasoning' THEN \"message_part\".\"reasoning_text\" IS NOT NULL ELSE TRUE END" + }, + "tool_call_fields_required": { + "name": "tool_call_fields_required", + "value": "CASE WHEN \"message_part\".\"type\" LIKE 'tool-%' THEN \"message_part\".\"tool_call_id\" IS NOT NULL AND \"message_part\".\"tool_state\" IS NOT NULL ELSE TRUE END" + }, + "file_fields_required": { + "name": "file_fields_required", + "value": "CASE WHEN \"message_part\".\"type\" = 'file' THEN \"message_part\".\"media_type\" IS NOT NULL AND \"message_part\".\"image_id\" IS NOT NULL ELSE TRUE END" + } + }, + "isRLSEnabled": false + }, + "public.chart_image": { + "name": "chart_image", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "tool_call_id": { + "name": "tool_call_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "data": { + "name": "data", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "chart_image_tool_call_id_unique": { + "name": "chart_image_tool_call_id_unique", + "nullsNotDistinct": false, + "columns": [ + "tool_call_id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.oauth_access_token": { + "name": "oauth_access_token", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "client_id": { + "name": "client_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "session_id": { + "name": "session_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "reference_id": { + "name": "reference_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "refresh_id": { + "name": "refresh_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "scopes": { + "name": "scopes", + "type": "jsonb", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "oauth_access_token_clientId_idx": { + "name": "oauth_access_token_clientId_idx", + "columns": [ + { + "expression": "client_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "oauth_access_token_userId_idx": { + "name": "oauth_access_token_userId_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "oauth_access_token_refreshId_idx": { + "name": "oauth_access_token_refreshId_idx", + "columns": [ + { + "expression": "refresh_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "oauth_access_token_client_id_oauth_client_client_id_fk": { + "name": "oauth_access_token_client_id_oauth_client_client_id_fk", + "tableFrom": "oauth_access_token", + "tableTo": "oauth_client", + "columnsFrom": [ + "client_id" + ], + "columnsTo": [ + "client_id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "oauth_access_token_session_id_session_id_fk": { + "name": "oauth_access_token_session_id_session_id_fk", + "tableFrom": "oauth_access_token", + "tableTo": "session", + "columnsFrom": [ + "session_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "oauth_access_token_user_id_user_id_fk": { + "name": "oauth_access_token_user_id_user_id_fk", + "tableFrom": "oauth_access_token", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "oauth_access_token_refresh_id_oauth_refresh_token_id_fk": { + "name": "oauth_access_token_refresh_id_oauth_refresh_token_id_fk", + "tableFrom": "oauth_access_token", + "tableTo": "oauth_refresh_token", + "columnsFrom": [ + "refresh_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "oauth_access_token_token_unique": { + "name": "oauth_access_token_token_unique", + "nullsNotDistinct": false, + "columns": [ + "token" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.oauth_client": { + "name": "oauth_client", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "client_id": { + "name": "client_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "client_secret": { + "name": "client_secret", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "disabled": { + "name": "disabled", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "skip_consent": { + "name": "skip_consent", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "enable_end_session": { + "name": "enable_end_session", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "subject_type": { + "name": "subject_type", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "scopes": { + "name": "scopes", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "uri": { + "name": "uri", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "icon": { + "name": "icon", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "contacts": { + "name": "contacts", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "tos": { + "name": "tos", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "policy": { + "name": "policy", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "software_id": { + "name": "software_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "software_version": { + "name": "software_version", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "software_statement": { + "name": "software_statement", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "redirect_uris": { + "name": "redirect_uris", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "post_logout_redirect_uris": { + "name": "post_logout_redirect_uris", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "token_endpoint_auth_method": { + "name": "token_endpoint_auth_method", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "grant_types": { + "name": "grant_types", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "response_types": { + "name": "response_types", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "public": { + "name": "public", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "require_pkce": { + "name": "require_pkce", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "reference_id": { + "name": "reference_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "oauth_client_userId_idx": { + "name": "oauth_client_userId_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "oauth_client_user_id_user_id_fk": { + "name": "oauth_client_user_id_user_id_fk", + "tableFrom": "oauth_client", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "oauth_client_client_id_unique": { + "name": "oauth_client_client_id_unique", + "nullsNotDistinct": false, + "columns": [ + "client_id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.oauth_consent": { + "name": "oauth_consent", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "client_id": { + "name": "client_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "reference_id": { + "name": "reference_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "scopes": { + "name": "scopes", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "oauth_consent_clientId_idx": { + "name": "oauth_consent_clientId_idx", + "columns": [ + { + "expression": "client_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "oauth_consent_userId_idx": { + "name": "oauth_consent_userId_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "oauth_consent_client_id_oauth_client_client_id_fk": { + "name": "oauth_consent_client_id_oauth_client_client_id_fk", + "tableFrom": "oauth_consent", + "tableTo": "oauth_client", + "columnsFrom": [ + "client_id" + ], + "columnsTo": [ + "client_id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "oauth_consent_user_id_user_id_fk": { + "name": "oauth_consent_user_id_user_id_fk", + "tableFrom": "oauth_consent", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.oauth_refresh_token": { + "name": "oauth_refresh_token", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "client_id": { + "name": "client_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "session_id": { + "name": "session_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "reference_id": { + "name": "reference_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "revoked": { + "name": "revoked", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "auth_time": { + "name": "auth_time", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "scopes": { + "name": "scopes", + "type": "jsonb", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "oauth_refresh_token_clientId_idx": { + "name": "oauth_refresh_token_clientId_idx", + "columns": [ + { + "expression": "client_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "oauth_refresh_token_userId_idx": { + "name": "oauth_refresh_token_userId_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "oauth_refresh_token_sessionId_idx": { + "name": "oauth_refresh_token_sessionId_idx", + "columns": [ + { + "expression": "session_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "oauth_refresh_token_client_id_oauth_client_client_id_fk": { + "name": "oauth_refresh_token_client_id_oauth_client_client_id_fk", + "tableFrom": "oauth_refresh_token", + "tableTo": "oauth_client", + "columnsFrom": [ + "client_id" + ], + "columnsTo": [ + "client_id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "oauth_refresh_token_session_id_session_id_fk": { + "name": "oauth_refresh_token_session_id_session_id_fk", + "tableFrom": "oauth_refresh_token", + "tableTo": "session", + "columnsFrom": [ + "session_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "oauth_refresh_token_user_id_user_id_fk": { + "name": "oauth_refresh_token_user_id_user_id_fk", + "tableFrom": "oauth_refresh_token", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "oauth_refresh_token_token_unique": { + "name": "oauth_refresh_token_token_unique", + "nullsNotDistinct": false, + "columns": [ + "token" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.org_member": { + "name": "org_member", + "schema": "", + "columns": { + "org_id": { + "name": "org_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "role": { + "name": "role", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "org_member_userId_idx": { + "name": "org_member_userId_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "org_member_org_id_organization_id_fk": { + "name": "org_member_org_id_organization_id_fk", + "tableFrom": "org_member", + "tableTo": "organization", + "columnsFrom": [ + "org_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "org_member_user_id_user_id_fk": { + "name": "org_member_user_id_user_id_fk", + "tableFrom": "org_member", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "org_member_org_id_user_id_pk": { + "name": "org_member_org_id_user_id_pk", + "columns": [ + "org_id", + "user_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.organization": { + "name": "organization", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "slug": { + "name": "slug", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "google_client_id": { + "name": "google_client_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "google_client_secret": { + "name": "google_client_secret", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "google_auth_domains": { + "name": "google_auth_domains", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "organization_slug_unique": { + "name": "organization_slug_unique", + "nullsNotDistinct": false, + "columns": [ + "slug" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.project": { + "name": "project", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "org_id": { + "name": "org_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "path": { + "name": "path", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "agent_settings": { + "name": "agent_settings", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "enabled_tools": { + "name": "enabled_tools", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "known_mcp_servers": { + "name": "known_mcp_servers", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "env_vars": { + "name": "env_vars", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "slack_settings": { + "name": "slack_settings", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "teams_settings": { + "name": "teams_settings", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "telegram_settings": { + "name": "telegram_settings", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "whatsapp_settings": { + "name": "whatsapp_settings", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "mcp_endpoint_settings": { + "name": "mcp_endpoint_settings", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "display_settings": { + "name": "display_settings", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "project_orgId_idx": { + "name": "project_orgId_idx", + "columns": [ + { + "expression": "org_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "project_org_id_organization_id_fk": { + "name": "project_org_id_organization_id_fk", + "tableFrom": "project", + "tableTo": "organization", + "columnsFrom": [ + "org_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "local_project_path_required": { + "name": "local_project_path_required", + "value": "CASE WHEN \"type\" = 'local' THEN \"path\" IS NOT NULL ELSE TRUE END" + } + }, + "isRLSEnabled": false + }, + "public.project_llm_config": { + "name": "project_llm_config", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "api_key": { + "name": "api_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "credentials": { + "name": "credentials", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "enabled_models": { + "name": "enabled_models", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "custom_models": { + "name": "custom_models", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "base_url": { + "name": "base_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "project_llm_config_projectId_idx": { + "name": "project_llm_config_projectId_idx", + "columns": [ + { + "expression": "project_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "project_llm_config_project_id_project_id_fk": { + "name": "project_llm_config_project_id_project_id_fk", + "tableFrom": "project_llm_config", + "tableTo": "project", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "project_llm_config_project_provider": { + "name": "project_llm_config_project_provider", + "nullsNotDistinct": false, + "columns": [ + "project_id", + "provider" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.project_member": { + "name": "project_member", + "schema": "", + "columns": { + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "role": { + "name": "role", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "project_member_userId_idx": { + "name": "project_member_userId_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "project_member_project_id_project_id_fk": { + "name": "project_member_project_id_project_id_fk", + "tableFrom": "project_member", + "tableTo": "project", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "project_member_user_id_user_id_fk": { + "name": "project_member_user_id_user_id_fk", + "tableFrom": "project_member", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "project_member_project_id_user_id_pk": { + "name": "project_member_project_id_user_id_pk", + "columns": [ + "project_id", + "user_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.project_provider_budget": { + "name": "project_provider_budget", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "limit_usd": { + "name": "limit_usd", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "period": { + "name": "period", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "current_period_start": { + "name": "current_period_start", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "notified_at": { + "name": "notified_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "project_provider_budget_projectId_idx": { + "name": "project_provider_budget_projectId_idx", + "columns": [ + { + "expression": "project_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "project_provider_budget_project_id_project_id_fk": { + "name": "project_provider_budget_project_id_project_id_fk", + "tableFrom": "project_provider_budget", + "tableTo": "project", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "project_provider_budget_project_provider": { + "name": "project_provider_budget_project_provider", + "nullsNotDistinct": false, + "columns": [ + "project_id", + "provider" + ] + } + }, + "policies": {}, + "checkConstraints": { + "budget_period_valid": { + "name": "budget_period_valid", + "value": "\"project_provider_budget\".\"period\" IN ('day', 'week', 'month')" + } + }, + "isRLSEnabled": false + }, + "public.project_saved_prompt": { + "name": "project_saved_prompt", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "prompt": { + "name": "prompt", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "project_saved_prompt_projectId_idx": { + "name": "project_saved_prompt_projectId_idx", + "columns": [ + { + "expression": "project_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "project_saved_prompt_project_id_project_id_fk": { + "name": "project_saved_prompt_project_id_project_id_fk", + "tableFrom": "project_saved_prompt", + "tableTo": "project", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.project_whatsapp_link": { + "name": "project_whatsapp_link", + "schema": "", + "columns": { + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "whatsapp_user_id": { + "name": "whatsapp_user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "project_whatsapp_link_userId_idx": { + "name": "project_whatsapp_link_userId_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "project_whatsapp_link_project_id_project_id_fk": { + "name": "project_whatsapp_link_project_id_project_id_fk", + "tableFrom": "project_whatsapp_link", + "tableTo": "project", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "project_whatsapp_link_user_id_user_id_fk": { + "name": "project_whatsapp_link_user_id_user_id_fk", + "tableFrom": "project_whatsapp_link", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "project_whatsapp_link_project_id_whatsapp_user_id_pk": { + "name": "project_whatsapp_link_project_id_whatsapp_user_id_pk", + "columns": [ + "project_id", + "whatsapp_user_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.scheduled_job": { + "name": "scheduled_job", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "payload": { + "name": "payload", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "run_at": { + "name": "run_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "cron": { + "name": "cron", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "attempts": { + "name": "attempts", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "max_attempts": { + "name": "max_attempts", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 5 + }, + "last_error": { + "name": "last_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "locked_at": { + "name": "locked_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "locked_by": { + "name": "locked_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "unique_key": { + "name": "unique_key", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "scheduled_job_status_runAt_idx": { + "name": "scheduled_job_status_runAt_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "run_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "scheduled_job_name_idx": { + "name": "scheduled_job_name_idx", + "columns": [ + { + "expression": "name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "scheduled_job_unique_key_unique": { + "name": "scheduled_job_unique_key_unique", + "nullsNotDistinct": false, + "columns": [ + "unique_key" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.session": { + "name": "session", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "ip_address": { + "name": "ip_address", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_agent": { + "name": "user_agent", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "session_userId_idx": { + "name": "session_userId_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "session_user_id_user_id_fk": { + "name": "session_user_id_user_id_fk", + "tableFrom": "session", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "session_token_unique": { + "name": "session_token_unique", + "nullsNotDistinct": false, + "columns": [ + "token" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.shared_chat": { + "name": "shared_chat", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "chat_id": { + "name": "chat_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "visibility": { + "name": "visibility", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'project'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "shared_chat_chat_id_chat_id_fk": { + "name": "shared_chat_chat_id_chat_id_fk", + "tableFrom": "shared_chat", + "tableTo": "chat", + "columnsFrom": [ + "chat_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "shared_chat_chatId_unique": { + "name": "shared_chat_chatId_unique", + "nullsNotDistinct": false, + "columns": [ + "chat_id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.shared_chat_access": { + "name": "shared_chat_access", + "schema": "", + "columns": { + "shared_chat_id": { + "name": "shared_chat_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "shared_chat_access_shared_chat_id_shared_chat_id_fk": { + "name": "shared_chat_access_shared_chat_id_shared_chat_id_fk", + "tableFrom": "shared_chat_access", + "tableTo": "shared_chat", + "columnsFrom": [ + "shared_chat_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "shared_chat_access_user_id_user_id_fk": { + "name": "shared_chat_access_user_id_user_id_fk", + "tableFrom": "shared_chat_access", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "shared_chat_access_shared_chat_id_user_id_pk": { + "name": "shared_chat_access_shared_chat_id_user_id_pk", + "columns": [ + "shared_chat_id", + "user_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.shared_story": { + "name": "shared_story", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "story_id": { + "name": "story_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "visibility": { + "name": "visibility", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'project'" + }, + "is_pinned": { + "name": "is_pinned", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "shared_story_projectId_idx": { + "name": "shared_story_projectId_idx", + "columns": [ + { + "expression": "project_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "shared_story_storyId_idx": { + "name": "shared_story_storyId_idx", + "columns": [ + { + "expression": "story_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "shared_story_project_story_unique": { + "name": "shared_story_project_story_unique", + "columns": [ + { + "expression": "project_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "story_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "shared_story_story_id_story_id_fk": { + "name": "shared_story_story_id_story_id_fk", + "tableFrom": "shared_story", + "tableTo": "story", + "columnsFrom": [ + "story_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "shared_story_project_id_project_id_fk": { + "name": "shared_story_project_id_project_id_fk", + "tableFrom": "shared_story", + "tableTo": "project", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "shared_story_user_id_user_id_fk": { + "name": "shared_story_user_id_user_id_fk", + "tableFrom": "shared_story", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.shared_story_access": { + "name": "shared_story_access", + "schema": "", + "columns": { + "shared_story_id": { + "name": "shared_story_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "shared_story_access_shared_story_id_shared_story_id_fk": { + "name": "shared_story_access_shared_story_id_shared_story_id_fk", + "tableFrom": "shared_story_access", + "tableTo": "shared_story", + "columnsFrom": [ + "shared_story_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "shared_story_access_user_id_user_id_fk": { + "name": "shared_story_access_user_id_user_id_fk", + "tableFrom": "shared_story_access", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "shared_story_access_shared_story_id_user_id_pk": { + "name": "shared_story_access_shared_story_id_user_id_pk", + "columns": [ + "shared_story_id", + "user_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.story": { + "name": "story", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "chat_id": { + "name": "chat_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "slug": { + "name": "slug", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "is_live": { + "name": "is_live", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "is_live_text_dynamic": { + "name": "is_live_text_dynamic", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "cache_schedule": { + "name": "cache_schedule", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "cache_schedule_description": { + "name": "cache_schedule_description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "scheduled_job_id": { + "name": "scheduled_job_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "archived_at": { + "name": "archived_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "story_standalone_slug_unique": { + "name": "story_standalone_slug_unique", + "columns": [ + { + "expression": "project_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "slug", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"story\".\"chat_id\" IS NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "story_chatId_idx": { + "name": "story_chatId_idx", + "columns": [ + { + "expression": "chat_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "story_projectId_idx": { + "name": "story_projectId_idx", + "columns": [ + { + "expression": "project_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "story_userId_idx": { + "name": "story_userId_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "story_scheduledJobId_idx": { + "name": "story_scheduledJobId_idx", + "columns": [ + { + "expression": "scheduled_job_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "story_chat_id_chat_id_fk": { + "name": "story_chat_id_chat_id_fk", + "tableFrom": "story", + "tableTo": "chat", + "columnsFrom": [ + "chat_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "story_project_id_project_id_fk": { + "name": "story_project_id_project_id_fk", + "tableFrom": "story", + "tableTo": "project", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "story_user_id_user_id_fk": { + "name": "story_user_id_user_id_fk", + "tableFrom": "story", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "story_scheduled_job_id_scheduled_job_id_fk": { + "name": "story_scheduled_job_id_scheduled_job_id_fk", + "tableFrom": "story", + "tableTo": "scheduled_job", + "columnsFrom": [ + "scheduled_job_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "story_chat_slug_unique": { + "name": "story_chat_slug_unique", + "nullsNotDistinct": false, + "columns": [ + "chat_id", + "slug" + ] + } + }, + "policies": {}, + "checkConstraints": { + "story_owner_required": { + "name": "story_owner_required", + "value": "\"story\".\"chat_id\" IS NOT NULL OR (\"story\".\"project_id\" IS NOT NULL AND \"story\".\"user_id\" IS NOT NULL)" + } + }, + "isRLSEnabled": false + }, + "public.story_data_cache": { + "name": "story_data_cache", + "schema": "", + "columns": { + "story_id": { + "name": "story_id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "query_data": { + "name": "query_data", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "analysis_results": { + "name": "analysis_results", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "cached_at": { + "name": "cached_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "story_data_cache_story_id_story_id_fk": { + "name": "story_data_cache_story_id_story_id_fk", + "tableFrom": "story_data_cache", + "tableTo": "story", + "columnsFrom": [ + "story_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.story_folder": { + "name": "story_folder", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "owner_id": { + "name": "owner_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "parent_id": { + "name": "parent_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "visibility": { + "name": "visibility", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'public'" + }, + "system_type": { + "name": "system_type", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "archived_at": { + "name": "archived_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "story_folder_private_root_unique": { + "name": "story_folder_private_root_unique", + "columns": [ + { + "expression": "project_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "owner_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"story_folder\".\"system_type\" = 'private_folder'", + "concurrently": false, + "method": "btree", + "with": {} + }, + "story_folder_ownerProjectParent_idx": { + "name": "story_folder_ownerProjectParent_idx", + "columns": [ + { + "expression": "owner_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "project_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "story_folder_projectId_idx": { + "name": "story_folder_projectId_idx", + "columns": [ + { + "expression": "project_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "story_folder_owner_id_user_id_fk": { + "name": "story_folder_owner_id_user_id_fk", + "tableFrom": "story_folder", + "tableTo": "user", + "columnsFrom": [ + "owner_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "story_folder_project_id_project_id_fk": { + "name": "story_folder_project_id_project_id_fk", + "tableFrom": "story_folder", + "tableTo": "project", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "story_folder_parent_id_story_folder_id_fk": { + "name": "story_folder_parent_id_story_folder_id_fk", + "tableFrom": "story_folder", + "tableTo": "story_folder", + "columnsFrom": [ + "parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.story_folder_item": { + "name": "story_folder_item", + "schema": "", + "columns": { + "story_id": { + "name": "story_id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "folder_id": { + "name": "folder_id", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "story_folder_item_folderId_idx": { + "name": "story_folder_item_folderId_idx", + "columns": [ + { + "expression": "folder_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "story_folder_item_story_id_story_id_fk": { + "name": "story_folder_item_story_id_story_id_fk", + "tableFrom": "story_folder_item", + "tableTo": "story", + "columnsFrom": [ + "story_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "story_folder_item_folder_id_story_folder_id_fk": { + "name": "story_folder_item_folder_id_story_folder_id_fk", + "tableFrom": "story_folder_item", + "tableTo": "story_folder", + "columnsFrom": [ + "folder_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.story_version": { + "name": "story_version", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "story_id": { + "name": "story_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "code": { + "name": "code", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "action": { + "name": "action", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "story_version_storyId_idx": { + "name": "story_version_storyId_idx", + "columns": [ + { + "expression": "story_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "story_version_story_id_story_id_fk": { + "name": "story_version_story_id_story_id_fk", + "tableFrom": "story_version", + "tableTo": "story", + "columnsFrom": [ + "story_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "story_version_story_version_unique": { + "name": "story_version_story_version_unique", + "nullsNotDistinct": false, + "columns": [ + "story_id", + "version" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.user": { + "name": "user", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "email_verified": { + "name": "email_verified", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "image": { + "name": "image", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "requires_password_reset": { + "name": "requires_password_reset", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "memory_enabled": { + "name": "memory_enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "messaging_provider_code": { + "name": "messaging_provider_code", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "github_access_token": { + "name": "github_access_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "user_email_unique": { + "name": "user_email_unique", + "nullsNotDistinct": false, + "columns": [ + "email" + ] + }, + "user_messaging_provider_code_unique": { + "name": "user_messaging_provider_code_unique", + "nullsNotDistinct": false, + "columns": [ + "messaging_provider_code" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.user_preference": { + "name": "user_preference", + "schema": "", + "columns": { + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "preferences": { + "name": "preferences", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "user_preference_user_id_user_id_fk": { + "name": "user_preference_user_id_user_id_fk", + "tableFrom": "user_preference", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.verification": { + "name": "verification", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "identifier": { + "name": "identifier", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "value": { + "name": "value", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "verification_identifier_idx": { + "name": "verification_identifier_idx", + "columns": [ + { + "expression": "identifier", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": {}, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/apps/backend/migrations-postgres/meta/_journal.json b/apps/backend/migrations-postgres/meta/_journal.json index 16073a739..6117d0a7f 100644 --- a/apps/backend/migrations-postgres/meta/_journal.json +++ b/apps/backend/migrations-postgres/meta/_journal.json @@ -372,6 +372,13 @@ "when": 1782391314716, "tag": "0052_add_brand_color", "breakpoints": true + }, + { + "idx": 53, + "version": "7", + "when": 1782762526841, + "tag": "0053_add_memories_project_id", + "breakpoints": true } ] } \ No newline at end of file diff --git a/apps/backend/migrations-sqlite/0053_add_memories_project_id.sql b/apps/backend/migrations-sqlite/0053_add_memories_project_id.sql new file mode 100644 index 000000000..083b71b7c --- /dev/null +++ b/apps/backend/migrations-sqlite/0053_add_memories_project_id.sql @@ -0,0 +1,2 @@ +ALTER TABLE `memories` ADD `project_id` text REFERENCES project(id);--> statement-breakpoint +CREATE INDEX `memories_projectId_idx` ON `memories` (`project_id`); \ No newline at end of file diff --git a/apps/backend/migrations-sqlite/meta/0053_snapshot.json b/apps/backend/migrations-sqlite/meta/0053_snapshot.json new file mode 100644 index 000000000..a44ea9c32 --- /dev/null +++ b/apps/backend/migrations-sqlite/meta/0053_snapshot.json @@ -0,0 +1,6069 @@ +{ + "version": "6", + "dialect": "sqlite", + "id": "e04f07f1-e2b1-4413-98ca-1f01d5135851", + "prevId": "f497fd8a-2aec-49c0-9b94-9ef5f8a0bb71", + "tables": { + "account": { + "name": "account", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "account_id": { + "name": "account_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "provider_id": { + "name": "provider_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "access_token": { + "name": "access_token", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "refresh_token": { + "name": "refresh_token", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "id_token": { + "name": "id_token", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "access_token_expires_at": { + "name": "access_token_expires_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "refresh_token_expires_at": { + "name": "refresh_token_expires_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "scope": { + "name": "scope", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "password": { + "name": "password", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "account_userId_idx": { + "name": "account_userId_idx", + "columns": [ + "user_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "account_user_id_user_id_fk": { + "name": "account_user_id_user_id_fk", + "tableFrom": "account", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "activity": { + "name": "activity", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'completed'" + }, + "trigger": { + "name": "trigger", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'system'" + }, + "story_id": { + "name": "story_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "chat_id": { + "name": "chat_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "shared_story_id": { + "name": "shared_story_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "shared_chat_id": { + "name": "shared_chat_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "payload": { + "name": "payload", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "error_message": { + "name": "error_message", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "started_at": { + "name": "started_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + }, + "completed_at": { + "name": "completed_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "activity_projectId_idx": { + "name": "activity_projectId_idx", + "columns": [ + "project_id" + ], + "isUnique": false + }, + "activity_userId_idx": { + "name": "activity_userId_idx", + "columns": [ + "user_id" + ], + "isUnique": false + }, + "activity_type_idx": { + "name": "activity_type_idx", + "columns": [ + "type" + ], + "isUnique": false + }, + "activity_storyId_idx": { + "name": "activity_storyId_idx", + "columns": [ + "story_id" + ], + "isUnique": false + }, + "activity_chatId_idx": { + "name": "activity_chatId_idx", + "columns": [ + "chat_id" + ], + "isUnique": false + }, + "activity_sharedStoryId_idx": { + "name": "activity_sharedStoryId_idx", + "columns": [ + "shared_story_id" + ], + "isUnique": false + }, + "activity_sharedChatId_idx": { + "name": "activity_sharedChatId_idx", + "columns": [ + "shared_chat_id" + ], + "isUnique": false + }, + "activity_startedAt_idx": { + "name": "activity_startedAt_idx", + "columns": [ + "started_at" + ], + "isUnique": false + } + }, + "foreignKeys": { + "activity_project_id_project_id_fk": { + "name": "activity_project_id_project_id_fk", + "tableFrom": "activity", + "tableTo": "project", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "activity_user_id_user_id_fk": { + "name": "activity_user_id_user_id_fk", + "tableFrom": "activity", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "activity_story_id_story_id_fk": { + "name": "activity_story_id_story_id_fk", + "tableFrom": "activity", + "tableTo": "story", + "columnsFrom": [ + "story_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "activity_chat_id_chat_id_fk": { + "name": "activity_chat_id_chat_id_fk", + "tableFrom": "activity", + "tableTo": "chat", + "columnsFrom": [ + "chat_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "activity_shared_story_id_shared_story_id_fk": { + "name": "activity_shared_story_id_shared_story_id_fk", + "tableFrom": "activity", + "tableTo": "shared_story", + "columnsFrom": [ + "shared_story_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "activity_shared_chat_id_shared_chat_id_fk": { + "name": "activity_shared_chat_id_shared_chat_id_fk", + "tableFrom": "activity", + "tableTo": "shared_chat", + "columnsFrom": [ + "shared_chat_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "analytics_event": { + "name": "analytics_event", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "asset_type": { + "name": "asset_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "actor_user_id": { + "name": "actor_user_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "chat_id": { + "name": "chat_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "story_id": { + "name": "story_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "shared_chat_id": { + "name": "shared_chat_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "shared_story_id": { + "name": "shared_story_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "metadata": { + "name": "metadata", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + } + }, + "indexes": { + "analytics_event_projectId_idx": { + "name": "analytics_event_projectId_idx", + "columns": [ + "project_id" + ], + "isUnique": false + }, + "analytics_event_chatId_idx": { + "name": "analytics_event_chatId_idx", + "columns": [ + "chat_id" + ], + "isUnique": false + }, + "analytics_event_storyId_idx": { + "name": "analytics_event_storyId_idx", + "columns": [ + "story_id" + ], + "isUnique": false + }, + "analytics_event_sharedChatId_idx": { + "name": "analytics_event_sharedChatId_idx", + "columns": [ + "shared_chat_id" + ], + "isUnique": false + }, + "analytics_event_sharedStoryId_idx": { + "name": "analytics_event_sharedStoryId_idx", + "columns": [ + "shared_story_id" + ], + "isUnique": false + }, + "analytics_event_actorUserId_idx": { + "name": "analytics_event_actorUserId_idx", + "columns": [ + "actor_user_id" + ], + "isUnique": false + }, + "analytics_event_type_createdAt_idx": { + "name": "analytics_event_type_createdAt_idx", + "columns": [ + "type", + "created_at" + ], + "isUnique": false + } + }, + "foreignKeys": { + "analytics_event_project_id_project_id_fk": { + "name": "analytics_event_project_id_project_id_fk", + "tableFrom": "analytics_event", + "tableTo": "project", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "analytics_event_actor_user_id_user_id_fk": { + "name": "analytics_event_actor_user_id_user_id_fk", + "tableFrom": "analytics_event", + "tableTo": "user", + "columnsFrom": [ + "actor_user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "analytics_event_chat_id_chat_id_fk": { + "name": "analytics_event_chat_id_chat_id_fk", + "tableFrom": "analytics_event", + "tableTo": "chat", + "columnsFrom": [ + "chat_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "analytics_event_story_id_story_id_fk": { + "name": "analytics_event_story_id_story_id_fk", + "tableFrom": "analytics_event", + "tableTo": "story", + "columnsFrom": [ + "story_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "analytics_event_shared_chat_id_shared_chat_id_fk": { + "name": "analytics_event_shared_chat_id_shared_chat_id_fk", + "tableFrom": "analytics_event", + "tableTo": "shared_chat", + "columnsFrom": [ + "shared_chat_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "analytics_event_shared_story_id_shared_story_id_fk": { + "name": "analytics_event_shared_story_id_shared_story_id_fk", + "tableFrom": "analytics_event", + "tableTo": "shared_story", + "columnsFrom": [ + "shared_story_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": { + "analytics_event_asset_id_required": { + "name": "analytics_event_asset_id_required", + "value": "CASE WHEN asset_type = 'chat' THEN chat_id IS NOT NULL WHEN asset_type = 'story' THEN story_id IS NOT NULL ELSE TRUE END" + } + } + }, + "api_key": { + "name": "api_key", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "org_id": { + "name": "org_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "key_hash": { + "name": "key_hash", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "key_prefix": { + "name": "key_prefix", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "last_used_at": { + "name": "last_used_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + } + }, + "indexes": { + "api_key_key_hash_unique": { + "name": "api_key_key_hash_unique", + "columns": [ + "key_hash" + ], + "isUnique": true + }, + "api_key_orgId_idx": { + "name": "api_key_orgId_idx", + "columns": [ + "org_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "api_key_org_id_organization_id_fk": { + "name": "api_key_org_id_organization_id_fk", + "tableFrom": "api_key", + "tableTo": "organization", + "columnsFrom": [ + "org_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "api_key_created_by_user_id_fk": { + "name": "api_key_created_by_user_id_fk", + "tableFrom": "api_key", + "tableTo": "user", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "automation": { + "name": "automation", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "scheduled_job_id": { + "name": "scheduled_job_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "prompt": { + "name": "prompt", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "schedule_description": { + "name": "schedule_description", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "timezone": { + "name": "timezone", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "model_provider": { + "name": "model_provider", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "model_id": { + "name": "model_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "mcp_enabled": { + "name": "mcp_enabled", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": true + }, + "mcp_servers": { + "name": "mcp_servers", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "integrations": { + "name": "integrations", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'{}'" + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + } + }, + "indexes": { + "automation_projectId_idx": { + "name": "automation_projectId_idx", + "columns": [ + "project_id" + ], + "isUnique": false + }, + "automation_userId_idx": { + "name": "automation_userId_idx", + "columns": [ + "user_id" + ], + "isUnique": false + }, + "automation_scheduledJobId_idx": { + "name": "automation_scheduledJobId_idx", + "columns": [ + "scheduled_job_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "automation_project_id_project_id_fk": { + "name": "automation_project_id_project_id_fk", + "tableFrom": "automation", + "tableTo": "project", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "automation_user_id_user_id_fk": { + "name": "automation_user_id_user_id_fk", + "tableFrom": "automation", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "automation_scheduled_job_id_scheduled_job_id_fk": { + "name": "automation_scheduled_job_id_scheduled_job_id_fk", + "tableFrom": "automation", + "tableTo": "scheduled_job", + "columnsFrom": [ + "scheduled_job_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "automation_run": { + "name": "automation_run", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "automation_id": { + "name": "automation_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "chat_id": { + "name": "chat_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'running'" + }, + "started_at": { + "name": "started_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + }, + "completed_at": { + "name": "completed_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "error_message": { + "name": "error_message", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "integration_results": { + "name": "integration_results", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'[]'" + } + }, + "indexes": { + "automation_run_automationId_idx": { + "name": "automation_run_automationId_idx", + "columns": [ + "automation_id" + ], + "isUnique": false + }, + "automation_run_chatId_idx": { + "name": "automation_run_chatId_idx", + "columns": [ + "chat_id" + ], + "isUnique": false + }, + "automation_run_status_idx": { + "name": "automation_run_status_idx", + "columns": [ + "status" + ], + "isUnique": false + } + }, + "foreignKeys": { + "automation_run_automation_id_automation_id_fk": { + "name": "automation_run_automation_id_automation_id_fk", + "tableFrom": "automation_run", + "tableTo": "automation", + "columnsFrom": [ + "automation_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "automation_run_chat_id_chat_id_fk": { + "name": "automation_run_chat_id_chat_id_fk", + "tableFrom": "automation_run", + "tableTo": "chat", + "columnsFrom": [ + "chat_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "branding_config": { + "name": "branding_config", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "app_name": { + "name": "app_name", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tab_title": { + "name": "tab_title", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "logo_data": { + "name": "logo_data", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "logo_media_type": { + "name": "logo_media_type", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "favicon_data": { + "name": "favicon_data", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "favicon_media_type": { + "name": "favicon_media_type", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "brand_color": { + "name": "brand_color", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "chat": { + "name": "chat", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'New Conversation'" + }, + "is_starred": { + "name": "is_starred", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": false + }, + "deleted_at": { + "name": "deleted_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "slack_thread_id": { + "name": "slack_thread_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "teams_thread_id": { + "name": "teams_thread_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "telegram_thread_id": { + "name": "telegram_thread_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "whatsapp_thread_id": { + "name": "whatsapp_thread_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "fork_metadata": { + "name": "fork_metadata", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + } + }, + "indexes": { + "chat_userId_idx": { + "name": "chat_userId_idx", + "columns": [ + "user_id" + ], + "isUnique": false + }, + "chat_projectId_idx": { + "name": "chat_projectId_idx", + "columns": [ + "project_id" + ], + "isUnique": false + }, + "chat_slack_thread_idx": { + "name": "chat_slack_thread_idx", + "columns": [ + "slack_thread_id" + ], + "isUnique": false + }, + "chat_teams_thread_idx": { + "name": "chat_teams_thread_idx", + "columns": [ + "teams_thread_id" + ], + "isUnique": false + }, + "chat_telegram_thread_idx": { + "name": "chat_telegram_thread_idx", + "columns": [ + "telegram_thread_id" + ], + "isUnique": false + }, + "chat_whatsapp_thread_idx": { + "name": "chat_whatsapp_thread_idx", + "columns": [ + "whatsapp_thread_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "chat_user_id_user_id_fk": { + "name": "chat_user_id_user_id_fk", + "tableFrom": "chat", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "chat_project_id_project_id_fk": { + "name": "chat_project_id_project_id_fk", + "tableFrom": "chat", + "tableTo": "project", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "chat_message": { + "name": "chat_message", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "chat_id": { + "name": "chat_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "role": { + "name": "role", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "stop_reason": { + "name": "stop_reason", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "error_message": { + "name": "error_message", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "llm_provider": { + "name": "llm_provider", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "llm_model_id": { + "name": "llm_model_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "superseded_at": { + "name": "superseded_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "version_group_id": { + "name": "version_group_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "isForked": { + "name": "isForked", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "citation": { + "name": "citation", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + }, + "input_total_tokens": { + "name": "input_total_tokens", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "input_no_cache_tokens": { + "name": "input_no_cache_tokens", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "input_cache_read_tokens": { + "name": "input_cache_read_tokens", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "input_cache_write_tokens": { + "name": "input_cache_write_tokens", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "output_total_tokens": { + "name": "output_total_tokens", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "output_text_tokens": { + "name": "output_text_tokens", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "output_reasoning_tokens": { + "name": "output_reasoning_tokens", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "total_tokens": { + "name": "total_tokens", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "chat_message_chatId_idx": { + "name": "chat_message_chatId_idx", + "columns": [ + "chat_id" + ], + "isUnique": false + }, + "chat_message_createdAt_idx": { + "name": "chat_message_createdAt_idx", + "columns": [ + "created_at" + ], + "isUnique": false + }, + "chat_message_versionGroupId_idx": { + "name": "chat_message_versionGroupId_idx", + "columns": [ + "version_group_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "chat_message_chat_id_chat_id_fk": { + "name": "chat_message_chat_id_chat_id_fk", + "tableFrom": "chat_message", + "tableTo": "chat", + "columnsFrom": [ + "chat_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "context_recommendation": { + "name": "context_recommendation", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "run_id": { + "name": "run_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "fingerprint": { + "name": "fingerprint", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "suggested_file": { + "name": "suggested_file", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "subject_key": { + "name": "subject_key", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'open'" + }, + "snoozed_until": { + "name": "snoozed_until", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "severity": { + "name": "severity", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'medium'" + }, + "impact_score": { + "name": "impact_score", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "impact": { + "name": "impact", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "insights": { + "name": "insights", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'[]'" + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "summary": { + "name": "summary", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "suggested_action": { + "name": "suggested_action", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "fix_kind": { + "name": "fix_kind", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "proposed_edits": { + "name": "proposed_edits", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "fix_guidance": { + "name": "fix_guidance", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "fix_prompt": { + "name": "fix_prompt", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "pr_url": { + "name": "pr_url", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "pr_branch": { + "name": "pr_branch", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "pr_created_at": { + "name": "pr_created_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "llm_provider": { + "name": "llm_provider", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "llm_model_id": { + "name": "llm_model_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "first_seen_at": { + "name": "first_seen_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + }, + "last_seen_at": { + "name": "last_seen_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + }, + "occurrence_count": { + "name": "occurrence_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 1 + }, + "status_changed_at": { + "name": "status_changed_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "status_changed_by": { + "name": "status_changed_by", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + } + }, + "indexes": { + "context_recommendation_project_fingerprint_unique": { + "name": "context_recommendation_project_fingerprint_unique", + "columns": [ + "project_id", + "fingerprint" + ], + "isUnique": true + }, + "context_recommendation_projectId_status_idx": { + "name": "context_recommendation_projectId_status_idx", + "columns": [ + "project_id", + "status" + ], + "isUnique": false + }, + "context_recommendation_runId_idx": { + "name": "context_recommendation_runId_idx", + "columns": [ + "run_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "context_recommendation_project_id_project_id_fk": { + "name": "context_recommendation_project_id_project_id_fk", + "tableFrom": "context_recommendation", + "tableTo": "project", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "context_recommendation_status_changed_by_user_id_fk": { + "name": "context_recommendation_status_changed_by_user_id_fk", + "tableFrom": "context_recommendation", + "tableTo": "user", + "columnsFrom": [ + "status_changed_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "context_recommendation_run_fk": { + "name": "context_recommendation_run_fk", + "tableFrom": "context_recommendation", + "tableTo": "context_recommendation_run", + "columnsFrom": [ + "run_id", + "project_id" + ], + "columnsTo": [ + "id", + "project_id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "context_recommendation_config": { + "name": "context_recommendation_config", + "columns": { + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "model_provider": { + "name": "model_provider", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "model_id": { + "name": "model_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "frequency": { + "name": "frequency", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "custom_system_prompt_instructions": { + "name": "custom_system_prompt_instructions", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "repo_full_name": { + "name": "repo_full_name", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "auto_create_prs": { + "name": "auto_create_prs", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "max_auto_prs_per_run": { + "name": "max_auto_prs_per_run", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + } + }, + "indexes": {}, + "foreignKeys": { + "context_recommendation_config_project_id_project_id_fk": { + "name": "context_recommendation_config_project_id_project_id_fk", + "tableFrom": "context_recommendation_config", + "tableTo": "project", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "context_recommendation_run": { + "name": "context_recommendation_run", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "chat_id": { + "name": "chat_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "trigger": { + "name": "trigger", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'schedule'" + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'running'" + }, + "window_start": { + "name": "window_start", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "window_end": { + "name": "window_end", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "started_at": { + "name": "started_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + }, + "completed_at": { + "name": "completed_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "error_message": { + "name": "error_message", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "llm_provider": { + "name": "llm_provider", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "llm_model_id": { + "name": "llm_model_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "input_total_tokens": { + "name": "input_total_tokens", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "output_total_tokens": { + "name": "output_total_tokens", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "total_tokens": { + "name": "total_tokens", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "context_recommendation_run_projectId_idx": { + "name": "context_recommendation_run_projectId_idx", + "columns": [ + "project_id" + ], + "isUnique": false + }, + "context_recommendation_run_chatId_idx": { + "name": "context_recommendation_run_chatId_idx", + "columns": [ + "chat_id" + ], + "isUnique": false + }, + "context_recommendation_run_status_idx": { + "name": "context_recommendation_run_status_idx", + "columns": [ + "status" + ], + "isUnique": false + }, + "context_recommendation_run_id_project_unique": { + "name": "context_recommendation_run_id_project_unique", + "columns": [ + "id", + "project_id" + ], + "isUnique": true + } + }, + "foreignKeys": { + "context_recommendation_run_project_id_project_id_fk": { + "name": "context_recommendation_run_project_id_project_id_fk", + "tableFrom": "context_recommendation_run", + "tableTo": "project", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "context_recommendation_run_chat_id_chat_id_fk": { + "name": "context_recommendation_run_chat_id_chat_id_fk", + "tableFrom": "context_recommendation_run", + "tableTo": "chat", + "columnsFrom": [ + "chat_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "favorite": { + "name": "favorite", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "story_id": { + "name": "story_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "folder_id": { + "name": "folder_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + } + }, + "indexes": { + "favorite_user_id_idx": { + "name": "favorite_user_id_idx", + "columns": [ + "user_id" + ], + "isUnique": false + }, + "favorite_user_id_story_id_unique": { + "name": "favorite_user_id_story_id_unique", + "columns": [ + "user_id", + "story_id" + ], + "isUnique": true + }, + "favorite_user_id_folder_id_unique": { + "name": "favorite_user_id_folder_id_unique", + "columns": [ + "user_id", + "folder_id" + ], + "isUnique": true + } + }, + "foreignKeys": { + "favorite_user_id_user_id_fk": { + "name": "favorite_user_id_user_id_fk", + "tableFrom": "favorite", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "favorite_story_id_story_id_fk": { + "name": "favorite_story_id_story_id_fk", + "tableFrom": "favorite", + "tableTo": "story", + "columnsFrom": [ + "story_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "favorite_folder_id_story_folder_id_fk": { + "name": "favorite_folder_id_story_folder_id_fk", + "tableFrom": "favorite", + "tableTo": "story_folder", + "columnsFrom": [ + "folder_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": { + "favorite_xor_target": { + "name": "favorite_xor_target", + "value": "(\"favorite\".\"story_id\" IS NOT NULL) + (\"favorite\".\"folder_id\" IS NOT NULL) = 1" + } + } + }, + "jwks": { + "name": "jwks", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "public_key": { + "name": "public_key", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "private_key": { + "name": "private_key", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + }, + "expires_at": { + "name": "expires_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "llm_inference": { + "name": "llm_inference", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "chat_id": { + "name": "chat_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "llm_provider": { + "name": "llm_provider", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "llm_model_id": { + "name": "llm_model_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "input_total_tokens": { + "name": "input_total_tokens", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "input_no_cache_tokens": { + "name": "input_no_cache_tokens", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "input_cache_read_tokens": { + "name": "input_cache_read_tokens", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "input_cache_write_tokens": { + "name": "input_cache_write_tokens", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "output_total_tokens": { + "name": "output_total_tokens", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "output_text_tokens": { + "name": "output_text_tokens", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "output_reasoning_tokens": { + "name": "output_reasoning_tokens", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "total_tokens": { + "name": "total_tokens", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + } + }, + "indexes": { + "llm_inference_projectId_idx": { + "name": "llm_inference_projectId_idx", + "columns": [ + "project_id" + ], + "isUnique": false + }, + "llm_inference_userId_idx": { + "name": "llm_inference_userId_idx", + "columns": [ + "user_id" + ], + "isUnique": false + }, + "llm_inference_type_idx": { + "name": "llm_inference_type_idx", + "columns": [ + "type" + ], + "isUnique": false + } + }, + "foreignKeys": { + "llm_inference_project_id_project_id_fk": { + "name": "llm_inference_project_id_project_id_fk", + "tableFrom": "llm_inference", + "tableTo": "project", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "llm_inference_user_id_user_id_fk": { + "name": "llm_inference_user_id_user_id_fk", + "tableFrom": "llm_inference", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "llm_inference_chat_id_chat_id_fk": { + "name": "llm_inference_chat_id_chat_id_fk", + "tableFrom": "llm_inference", + "tableTo": "chat", + "columnsFrom": [ + "chat_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "log": { + "name": "log", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "level": { + "name": "level", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "message": { + "name": "message", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "context": { + "name": "context", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + } + }, + "indexes": { + "log_createdAt_idx": { + "name": "log_createdAt_idx", + "columns": [ + "created_at" + ], + "isUnique": false + }, + "log_level_idx": { + "name": "log_level_idx", + "columns": [ + "level" + ], + "isUnique": false + }, + "log_projectId_idx": { + "name": "log_projectId_idx", + "columns": [ + "project_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "log_project_id_project_id_fk": { + "name": "log_project_id_project_id_fk", + "tableFrom": "log", + "tableTo": "project", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "mcp_call_log": { + "name": "mcp_call_log", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "tool_name": { + "name": "tool_name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "duration_ms": { + "name": "duration_ms", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "success": { + "name": "success", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "tool_input": { + "name": "tool_input", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tool_output": { + "name": "tool_output", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "called_at": { + "name": "called_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + } + }, + "indexes": { + "mcp_call_log_projectId_idx": { + "name": "mcp_call_log_projectId_idx", + "columns": [ + "project_id" + ], + "isUnique": false + }, + "mcp_call_log_userId_idx": { + "name": "mcp_call_log_userId_idx", + "columns": [ + "user_id" + ], + "isUnique": false + }, + "mcp_call_log_calledAt_idx": { + "name": "mcp_call_log_calledAt_idx", + "columns": [ + "called_at" + ], + "isUnique": false + } + }, + "foreignKeys": { + "mcp_call_log_project_id_project_id_fk": { + "name": "mcp_call_log_project_id_project_id_fk", + "tableFrom": "mcp_call_log", + "tableTo": "project", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "mcp_call_log_user_id_user_id_fk": { + "name": "mcp_call_log_user_id_user_id_fk", + "tableFrom": "mcp_call_log", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "mcp_chart_embed": { + "name": "mcp_chart_embed", + "columns": { + "chart_embed_id": { + "name": "chart_embed_id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "query_id": { + "name": "query_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "chart_config": { + "name": "chart_config", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "source_chat_id": { + "name": "source_chat_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + } + }, + "indexes": { + "mcp_chart_embed_query_id_idx": { + "name": "mcp_chart_embed_query_id_idx", + "columns": [ + "query_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "mcp_chart_embed_query_id_mcp_query_data_query_id_fk": { + "name": "mcp_chart_embed_query_id_mcp_query_data_query_id_fk", + "tableFrom": "mcp_chart_embed", + "tableTo": "mcp_query_data", + "columnsFrom": [ + "query_id" + ], + "columnsTo": [ + "query_id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "mcp_query_data": { + "name": "mcp_query_data", + "columns": { + "query_id": { + "name": "query_id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "call_log_id": { + "name": "call_log_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "source_chat_id": { + "name": "source_chat_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "columns": { + "name": "columns", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "data": { + "name": "data", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "expires_at": { + "name": "expires_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + } + }, + "indexes": { + "mcp_query_data_project_id_idx": { + "name": "mcp_query_data_project_id_idx", + "columns": [ + "project_id" + ], + "isUnique": false + }, + "mcp_query_data_callLogId_idx": { + "name": "mcp_query_data_callLogId_idx", + "columns": [ + "call_log_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "mcp_query_data_project_id_project_id_fk": { + "name": "mcp_query_data_project_id_project_id_fk", + "tableFrom": "mcp_query_data", + "tableTo": "project", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "memories": { + "name": "memories", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "content": { + "name": "content", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "category": { + "name": "category", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + }, + "chat_id": { + "name": "chat_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "superseded_by": { + "name": "superseded_by", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "memories_userId_idx": { + "name": "memories_userId_idx", + "columns": [ + "user_id" + ], + "isUnique": false + }, + "memories_chatId_idx": { + "name": "memories_chatId_idx", + "columns": [ + "chat_id" + ], + "isUnique": false + }, + "memories_projectId_idx": { + "name": "memories_projectId_idx", + "columns": [ + "project_id" + ], + "isUnique": false + }, + "memories_supersededBy_idx": { + "name": "memories_supersededBy_idx", + "columns": [ + "superseded_by" + ], + "isUnique": false + } + }, + "foreignKeys": { + "memories_user_id_user_id_fk": { + "name": "memories_user_id_user_id_fk", + "tableFrom": "memories", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "memories_chat_id_chat_id_fk": { + "name": "memories_chat_id_chat_id_fk", + "tableFrom": "memories", + "tableTo": "chat", + "columnsFrom": [ + "chat_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "memories_project_id_project_id_fk": { + "name": "memories_project_id_project_id_fk", + "tableFrom": "memories", + "tableTo": "project", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "message_feedback": { + "name": "message_feedback", + "columns": { + "message_id": { + "name": "message_id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "vote": { + "name": "vote", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "explanation": { + "name": "explanation", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + } + }, + "indexes": {}, + "foreignKeys": { + "message_feedback_message_id_chat_message_id_fk": { + "name": "message_feedback_message_id_chat_message_id_fk", + "tableFrom": "message_feedback", + "tableTo": "chat_message", + "columnsFrom": [ + "message_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "message_image": { + "name": "message_image", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "data": { + "name": "data", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "media_type": { + "name": "media_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "message_part": { + "name": "message_part", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "message_id": { + "name": "message_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "order": { + "name": "order", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "text": { + "name": "text", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "reasoning_text": { + "name": "reasoning_text", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tool_call_id": { + "name": "tool_call_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tool_name": { + "name": "tool_name", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tool_state": { + "name": "tool_state", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tool_error_text": { + "name": "tool_error_text", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tool_input": { + "name": "tool_input", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tool_raw_input": { + "name": "tool_raw_input", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tool_output": { + "name": "tool_output", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tool_approval_id": { + "name": "tool_approval_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tool_approval_approved": { + "name": "tool_approval_approved", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tool_approval_reason": { + "name": "tool_approval_reason", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tool_provider_metadata": { + "name": "tool_provider_metadata", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "provider_metadata": { + "name": "provider_metadata", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "media_type": { + "name": "media_type", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "image_id": { + "name": "image_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "message_part_tool_call_id_unique": { + "name": "message_part_tool_call_id_unique", + "columns": [ + "tool_call_id" + ], + "isUnique": true + }, + "parts_message_id_idx": { + "name": "parts_message_id_idx", + "columns": [ + "message_id" + ], + "isUnique": false + }, + "parts_message_id_order_idx": { + "name": "parts_message_id_order_idx", + "columns": [ + "message_id", + "order" + ], + "isUnique": false + } + }, + "foreignKeys": { + "message_part_message_id_chat_message_id_fk": { + "name": "message_part_message_id_chat_message_id_fk", + "tableFrom": "message_part", + "tableTo": "chat_message", + "columnsFrom": [ + "message_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "message_part_image_id_message_image_id_fk": { + "name": "message_part_image_id_message_image_id_fk", + "tableFrom": "message_part", + "tableTo": "message_image", + "columnsFrom": [ + "image_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": { + "text_required_if_type_is_text": { + "name": "text_required_if_type_is_text", + "value": "CASE WHEN type = 'text' THEN text IS NOT NULL ELSE TRUE END" + }, + "reasoning_text_required_if_type_is_reasoning": { + "name": "reasoning_text_required_if_type_is_reasoning", + "value": "CASE WHEN type = 'reasoning' THEN reasoning_text IS NOT NULL ELSE TRUE END" + }, + "tool_call_fields_required": { + "name": "tool_call_fields_required", + "value": "CASE WHEN type LIKE 'tool-%' THEN tool_call_id IS NOT NULL AND tool_state IS NOT NULL ELSE TRUE END" + }, + "file_fields_required": { + "name": "file_fields_required", + "value": "CASE WHEN type = 'file' THEN media_type IS NOT NULL ELSE TRUE END" + } + } + }, + "chart_image": { + "name": "chart_image", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "tool_call_id": { + "name": "tool_call_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "data": { + "name": "data", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + } + }, + "indexes": { + "chart_image_tool_call_id_unique": { + "name": "chart_image_tool_call_id_unique", + "columns": [ + "tool_call_id" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "oauth_access_token": { + "name": "oauth_access_token", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "client_id": { + "name": "client_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "session_id": { + "name": "session_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "reference_id": { + "name": "reference_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "refresh_id": { + "name": "refresh_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "expires_at": { + "name": "expires_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + }, + "scopes": { + "name": "scopes", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "oauth_access_token_token_unique": { + "name": "oauth_access_token_token_unique", + "columns": [ + "token" + ], + "isUnique": true + }, + "oauth_access_token_clientId_idx": { + "name": "oauth_access_token_clientId_idx", + "columns": [ + "client_id" + ], + "isUnique": false + }, + "oauth_access_token_userId_idx": { + "name": "oauth_access_token_userId_idx", + "columns": [ + "user_id" + ], + "isUnique": false + }, + "oauth_access_token_refreshId_idx": { + "name": "oauth_access_token_refreshId_idx", + "columns": [ + "refresh_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "oauth_access_token_client_id_oauth_client_client_id_fk": { + "name": "oauth_access_token_client_id_oauth_client_client_id_fk", + "tableFrom": "oauth_access_token", + "tableTo": "oauth_client", + "columnsFrom": [ + "client_id" + ], + "columnsTo": [ + "client_id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "oauth_access_token_session_id_session_id_fk": { + "name": "oauth_access_token_session_id_session_id_fk", + "tableFrom": "oauth_access_token", + "tableTo": "session", + "columnsFrom": [ + "session_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "oauth_access_token_user_id_user_id_fk": { + "name": "oauth_access_token_user_id_user_id_fk", + "tableFrom": "oauth_access_token", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "oauth_access_token_refresh_id_oauth_refresh_token_id_fk": { + "name": "oauth_access_token_refresh_id_oauth_refresh_token_id_fk", + "tableFrom": "oauth_access_token", + "tableTo": "oauth_refresh_token", + "columnsFrom": [ + "refresh_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "oauth_client": { + "name": "oauth_client", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "client_id": { + "name": "client_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "client_secret": { + "name": "client_secret", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "disabled": { + "name": "disabled", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": false + }, + "skip_consent": { + "name": "skip_consent", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "enable_end_session": { + "name": "enable_end_session", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "subject_type": { + "name": "subject_type", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "scopes": { + "name": "scopes", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "uri": { + "name": "uri", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "icon": { + "name": "icon", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "contacts": { + "name": "contacts", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tos": { + "name": "tos", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "policy": { + "name": "policy", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "software_id": { + "name": "software_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "software_version": { + "name": "software_version", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "software_statement": { + "name": "software_statement", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "redirect_uris": { + "name": "redirect_uris", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "post_logout_redirect_uris": { + "name": "post_logout_redirect_uris", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "token_endpoint_auth_method": { + "name": "token_endpoint_auth_method", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "grant_types": { + "name": "grant_types", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "response_types": { + "name": "response_types", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "public": { + "name": "public", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "require_pkce": { + "name": "require_pkce", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "reference_id": { + "name": "reference_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "metadata": { + "name": "metadata", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + } + }, + "indexes": { + "oauth_client_client_id_unique": { + "name": "oauth_client_client_id_unique", + "columns": [ + "client_id" + ], + "isUnique": true + }, + "oauth_client_userId_idx": { + "name": "oauth_client_userId_idx", + "columns": [ + "user_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "oauth_client_user_id_user_id_fk": { + "name": "oauth_client_user_id_user_id_fk", + "tableFrom": "oauth_client", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "oauth_consent": { + "name": "oauth_consent", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "client_id": { + "name": "client_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "reference_id": { + "name": "reference_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "scopes": { + "name": "scopes", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + } + }, + "indexes": { + "oauth_consent_clientId_idx": { + "name": "oauth_consent_clientId_idx", + "columns": [ + "client_id" + ], + "isUnique": false + }, + "oauth_consent_userId_idx": { + "name": "oauth_consent_userId_idx", + "columns": [ + "user_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "oauth_consent_client_id_oauth_client_client_id_fk": { + "name": "oauth_consent_client_id_oauth_client_client_id_fk", + "tableFrom": "oauth_consent", + "tableTo": "oauth_client", + "columnsFrom": [ + "client_id" + ], + "columnsTo": [ + "client_id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "oauth_consent_user_id_user_id_fk": { + "name": "oauth_consent_user_id_user_id_fk", + "tableFrom": "oauth_consent", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "oauth_refresh_token": { + "name": "oauth_refresh_token", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "client_id": { + "name": "client_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "session_id": { + "name": "session_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "reference_id": { + "name": "reference_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "expires_at": { + "name": "expires_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + }, + "revoked": { + "name": "revoked", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "auth_time": { + "name": "auth_time", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "scopes": { + "name": "scopes", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "oauth_refresh_token_token_unique": { + "name": "oauth_refresh_token_token_unique", + "columns": [ + "token" + ], + "isUnique": true + }, + "oauth_refresh_token_clientId_idx": { + "name": "oauth_refresh_token_clientId_idx", + "columns": [ + "client_id" + ], + "isUnique": false + }, + "oauth_refresh_token_userId_idx": { + "name": "oauth_refresh_token_userId_idx", + "columns": [ + "user_id" + ], + "isUnique": false + }, + "oauth_refresh_token_sessionId_idx": { + "name": "oauth_refresh_token_sessionId_idx", + "columns": [ + "session_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "oauth_refresh_token_client_id_oauth_client_client_id_fk": { + "name": "oauth_refresh_token_client_id_oauth_client_client_id_fk", + "tableFrom": "oauth_refresh_token", + "tableTo": "oauth_client", + "columnsFrom": [ + "client_id" + ], + "columnsTo": [ + "client_id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "oauth_refresh_token_session_id_session_id_fk": { + "name": "oauth_refresh_token_session_id_session_id_fk", + "tableFrom": "oauth_refresh_token", + "tableTo": "session", + "columnsFrom": [ + "session_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "oauth_refresh_token_user_id_user_id_fk": { + "name": "oauth_refresh_token_user_id_user_id_fk", + "tableFrom": "oauth_refresh_token", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "org_member": { + "name": "org_member", + "columns": { + "org_id": { + "name": "org_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "role": { + "name": "role", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + } + }, + "indexes": { + "org_member_userId_idx": { + "name": "org_member_userId_idx", + "columns": [ + "user_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "org_member_org_id_organization_id_fk": { + "name": "org_member_org_id_organization_id_fk", + "tableFrom": "org_member", + "tableTo": "organization", + "columnsFrom": [ + "org_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "org_member_user_id_user_id_fk": { + "name": "org_member_user_id_user_id_fk", + "tableFrom": "org_member", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "org_member_org_id_user_id_pk": { + "columns": [ + "org_id", + "user_id" + ], + "name": "org_member_org_id_user_id_pk" + } + }, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "organization": { + "name": "organization", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "slug": { + "name": "slug", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "google_client_id": { + "name": "google_client_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "google_client_secret": { + "name": "google_client_secret", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "google_auth_domains": { + "name": "google_auth_domains", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + } + }, + "indexes": { + "organization_slug_unique": { + "name": "organization_slug_unique", + "columns": [ + "slug" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "project": { + "name": "project", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "org_id": { + "name": "org_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "path": { + "name": "path", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "agent_settings": { + "name": "agent_settings", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "enabled_tools": { + "name": "enabled_tools", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'[]'" + }, + "known_mcp_servers": { + "name": "known_mcp_servers", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'[]'" + }, + "env_vars": { + "name": "env_vars", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'{}'" + }, + "slack_settings": { + "name": "slack_settings", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "teams_settings": { + "name": "teams_settings", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "telegram_settings": { + "name": "telegram_settings", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "whatsapp_settings": { + "name": "whatsapp_settings", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "mcp_endpoint_settings": { + "name": "mcp_endpoint_settings", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "display_settings": { + "name": "display_settings", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + } + }, + "indexes": { + "project_orgId_idx": { + "name": "project_orgId_idx", + "columns": [ + "org_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "project_org_id_organization_id_fk": { + "name": "project_org_id_organization_id_fk", + "tableFrom": "project", + "tableTo": "organization", + "columnsFrom": [ + "org_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": { + "local_project_path_required": { + "name": "local_project_path_required", + "value": "CASE WHEN \"type\" = 'local' THEN \"path\" IS NOT NULL ELSE TRUE END" + } + } + }, + "project_llm_config": { + "name": "project_llm_config", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "api_key": { + "name": "api_key", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "credentials": { + "name": "credentials", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "enabled_models": { + "name": "enabled_models", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'[]'" + }, + "custom_models": { + "name": "custom_models", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'[]'" + }, + "base_url": { + "name": "base_url", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + } + }, + "indexes": { + "project_llm_config_projectId_idx": { + "name": "project_llm_config_projectId_idx", + "columns": [ + "project_id" + ], + "isUnique": false + }, + "project_llm_config_project_provider": { + "name": "project_llm_config_project_provider", + "columns": [ + "project_id", + "provider" + ], + "isUnique": true + } + }, + "foreignKeys": { + "project_llm_config_project_id_project_id_fk": { + "name": "project_llm_config_project_id_project_id_fk", + "tableFrom": "project_llm_config", + "tableTo": "project", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "project_member": { + "name": "project_member", + "columns": { + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "role": { + "name": "role", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + } + }, + "indexes": { + "project_member_userId_idx": { + "name": "project_member_userId_idx", + "columns": [ + "user_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "project_member_project_id_project_id_fk": { + "name": "project_member_project_id_project_id_fk", + "tableFrom": "project_member", + "tableTo": "project", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "project_member_user_id_user_id_fk": { + "name": "project_member_user_id_user_id_fk", + "tableFrom": "project_member", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "project_member_project_id_user_id_pk": { + "columns": [ + "project_id", + "user_id" + ], + "name": "project_member_project_id_user_id_pk" + } + }, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "project_provider_budget": { + "name": "project_provider_budget", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "limit_usd": { + "name": "limit_usd", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "period": { + "name": "period", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "current_period_start": { + "name": "current_period_start", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + }, + "notified_at": { + "name": "notified_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + } + }, + "indexes": { + "project_provider_budget_projectId_idx": { + "name": "project_provider_budget_projectId_idx", + "columns": [ + "project_id" + ], + "isUnique": false + }, + "project_provider_budget_project_provider": { + "name": "project_provider_budget_project_provider", + "columns": [ + "project_id", + "provider" + ], + "isUnique": true + } + }, + "foreignKeys": { + "project_provider_budget_project_id_project_id_fk": { + "name": "project_provider_budget_project_id_project_id_fk", + "tableFrom": "project_provider_budget", + "tableTo": "project", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": { + "budget_period_valid": { + "name": "budget_period_valid", + "value": "period IN ('day', 'week', 'month')" + } + } + }, + "project_saved_prompt": { + "name": "project_saved_prompt", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "prompt": { + "name": "prompt", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + } + }, + "indexes": { + "project_saved_prompt_projectId_idx": { + "name": "project_saved_prompt_projectId_idx", + "columns": [ + "project_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "project_saved_prompt_project_id_project_id_fk": { + "name": "project_saved_prompt_project_id_project_id_fk", + "tableFrom": "project_saved_prompt", + "tableTo": "project", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "project_whatsapp_link": { + "name": "project_whatsapp_link", + "columns": { + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "whatsapp_user_id": { + "name": "whatsapp_user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + } + }, + "indexes": { + "project_whatsapp_link_userId_idx": { + "name": "project_whatsapp_link_userId_idx", + "columns": [ + "user_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "project_whatsapp_link_project_id_project_id_fk": { + "name": "project_whatsapp_link_project_id_project_id_fk", + "tableFrom": "project_whatsapp_link", + "tableTo": "project", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "project_whatsapp_link_user_id_user_id_fk": { + "name": "project_whatsapp_link_user_id_user_id_fk", + "tableFrom": "project_whatsapp_link", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "project_whatsapp_link_project_id_whatsapp_user_id_pk": { + "columns": [ + "project_id", + "whatsapp_user_id" + ], + "name": "project_whatsapp_link_project_id_whatsapp_user_id_pk" + } + }, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "scheduled_job": { + "name": "scheduled_job", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "payload": { + "name": "payload", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "run_at": { + "name": "run_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "cron": { + "name": "cron", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'pending'" + }, + "attempts": { + "name": "attempts", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "max_attempts": { + "name": "max_attempts", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 5 + }, + "last_error": { + "name": "last_error", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "locked_at": { + "name": "locked_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "locked_by": { + "name": "locked_by", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "unique_key": { + "name": "unique_key", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + } + }, + "indexes": { + "scheduled_job_unique_key_unique": { + "name": "scheduled_job_unique_key_unique", + "columns": [ + "unique_key" + ], + "isUnique": true + }, + "scheduled_job_status_runAt_idx": { + "name": "scheduled_job_status_runAt_idx", + "columns": [ + "status", + "run_at" + ], + "isUnique": false + }, + "scheduled_job_name_idx": { + "name": "scheduled_job_name_idx", + "columns": [ + "name" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "session": { + "name": "session", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "expires_at": { + "name": "expires_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "ip_address": { + "name": "ip_address", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "user_agent": { + "name": "user_agent", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "session_token_unique": { + "name": "session_token_unique", + "columns": [ + "token" + ], + "isUnique": true + }, + "session_userId_idx": { + "name": "session_userId_idx", + "columns": [ + "user_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "session_user_id_user_id_fk": { + "name": "session_user_id_user_id_fk", + "tableFrom": "session", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "shared_chat": { + "name": "shared_chat", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "chat_id": { + "name": "chat_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "visibility": { + "name": "visibility", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'project'" + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + } + }, + "indexes": { + "shared_chat_chatId_unique": { + "name": "shared_chat_chatId_unique", + "columns": [ + "chat_id" + ], + "isUnique": true + } + }, + "foreignKeys": { + "shared_chat_chat_id_chat_id_fk": { + "name": "shared_chat_chat_id_chat_id_fk", + "tableFrom": "shared_chat", + "tableTo": "chat", + "columnsFrom": [ + "chat_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "shared_chat_access": { + "name": "shared_chat_access", + "columns": { + "shared_chat_id": { + "name": "shared_chat_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "shared_chat_access_shared_chat_id_shared_chat_id_fk": { + "name": "shared_chat_access_shared_chat_id_shared_chat_id_fk", + "tableFrom": "shared_chat_access", + "tableTo": "shared_chat", + "columnsFrom": [ + "shared_chat_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "shared_chat_access_user_id_user_id_fk": { + "name": "shared_chat_access_user_id_user_id_fk", + "tableFrom": "shared_chat_access", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "shared_chat_access_shared_chat_id_user_id_pk": { + "columns": [ + "shared_chat_id", + "user_id" + ], + "name": "shared_chat_access_shared_chat_id_user_id_pk" + } + }, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "shared_story": { + "name": "shared_story", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "story_id": { + "name": "story_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "visibility": { + "name": "visibility", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'project'" + }, + "is_pinned": { + "name": "is_pinned", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + } + }, + "indexes": { + "shared_story_projectId_idx": { + "name": "shared_story_projectId_idx", + "columns": [ + "project_id" + ], + "isUnique": false + }, + "shared_story_storyId_idx": { + "name": "shared_story_storyId_idx", + "columns": [ + "story_id" + ], + "isUnique": false + }, + "shared_story_project_story_unique": { + "name": "shared_story_project_story_unique", + "columns": [ + "project_id", + "story_id" + ], + "isUnique": true + } + }, + "foreignKeys": { + "shared_story_story_id_story_id_fk": { + "name": "shared_story_story_id_story_id_fk", + "tableFrom": "shared_story", + "tableTo": "story", + "columnsFrom": [ + "story_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "shared_story_project_id_project_id_fk": { + "name": "shared_story_project_id_project_id_fk", + "tableFrom": "shared_story", + "tableTo": "project", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "shared_story_user_id_user_id_fk": { + "name": "shared_story_user_id_user_id_fk", + "tableFrom": "shared_story", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "shared_story_access": { + "name": "shared_story_access", + "columns": { + "shared_story_id": { + "name": "shared_story_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "shared_story_access_shared_story_id_shared_story_id_fk": { + "name": "shared_story_access_shared_story_id_shared_story_id_fk", + "tableFrom": "shared_story_access", + "tableTo": "shared_story", + "columnsFrom": [ + "shared_story_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "shared_story_access_user_id_user_id_fk": { + "name": "shared_story_access_user_id_user_id_fk", + "tableFrom": "shared_story_access", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "shared_story_access_shared_story_id_user_id_pk": { + "columns": [ + "shared_story_id", + "user_id" + ], + "name": "shared_story_access_shared_story_id_user_id_pk" + } + }, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "story": { + "name": "story", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "chat_id": { + "name": "chat_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "slug": { + "name": "slug", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "is_live": { + "name": "is_live", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": false + }, + "is_live_text_dynamic": { + "name": "is_live_text_dynamic", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": true + }, + "cache_schedule": { + "name": "cache_schedule", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "cache_schedule_description": { + "name": "cache_schedule_description", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "scheduled_job_id": { + "name": "scheduled_job_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "archived_at": { + "name": "archived_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + } + }, + "indexes": { + "story_standalone_slug_unique": { + "name": "story_standalone_slug_unique", + "columns": [ + "project_id", + "user_id", + "slug" + ], + "isUnique": true, + "where": "chat_id IS NULL" + }, + "story_chatId_idx": { + "name": "story_chatId_idx", + "columns": [ + "chat_id" + ], + "isUnique": false + }, + "story_projectId_idx": { + "name": "story_projectId_idx", + "columns": [ + "project_id" + ], + "isUnique": false + }, + "story_userId_idx": { + "name": "story_userId_idx", + "columns": [ + "user_id" + ], + "isUnique": false + }, + "story_scheduledJobId_idx": { + "name": "story_scheduledJobId_idx", + "columns": [ + "scheduled_job_id" + ], + "isUnique": false + }, + "story_chat_slug_unique": { + "name": "story_chat_slug_unique", + "columns": [ + "chat_id", + "slug" + ], + "isUnique": true + } + }, + "foreignKeys": { + "story_chat_id_chat_id_fk": { + "name": "story_chat_id_chat_id_fk", + "tableFrom": "story", + "tableTo": "chat", + "columnsFrom": [ + "chat_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "story_project_id_project_id_fk": { + "name": "story_project_id_project_id_fk", + "tableFrom": "story", + "tableTo": "project", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "story_user_id_user_id_fk": { + "name": "story_user_id_user_id_fk", + "tableFrom": "story", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "story_scheduled_job_id_scheduled_job_id_fk": { + "name": "story_scheduled_job_id_scheduled_job_id_fk", + "tableFrom": "story", + "tableTo": "scheduled_job", + "columnsFrom": [ + "scheduled_job_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": { + "story_owner_required": { + "name": "story_owner_required", + "value": "chat_id IS NOT NULL OR (project_id IS NOT NULL AND user_id IS NOT NULL)" + } + } + }, + "story_data_cache": { + "name": "story_data_cache", + "columns": { + "story_id": { + "name": "story_id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "query_data": { + "name": "query_data", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "analysis_results": { + "name": "analysis_results", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "cached_at": { + "name": "cached_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + } + }, + "indexes": {}, + "foreignKeys": { + "story_data_cache_story_id_story_id_fk": { + "name": "story_data_cache_story_id_story_id_fk", + "tableFrom": "story_data_cache", + "tableTo": "story", + "columnsFrom": [ + "story_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "story_folder": { + "name": "story_folder", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "owner_id": { + "name": "owner_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "parent_id": { + "name": "parent_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "visibility": { + "name": "visibility", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'public'" + }, + "system_type": { + "name": "system_type", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "archived_at": { + "name": "archived_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + } + }, + "indexes": { + "story_folder_private_root_unique": { + "name": "story_folder_private_root_unique", + "columns": [ + "project_id", + "owner_id" + ], + "isUnique": true, + "where": "\"story_folder\".\"system_type\" = 'private_folder'" + }, + "story_folder_ownerProjectParent_idx": { + "name": "story_folder_ownerProjectParent_idx", + "columns": [ + "owner_id", + "project_id", + "parent_id" + ], + "isUnique": false + }, + "story_folder_projectId_idx": { + "name": "story_folder_projectId_idx", + "columns": [ + "project_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "story_folder_owner_id_user_id_fk": { + "name": "story_folder_owner_id_user_id_fk", + "tableFrom": "story_folder", + "tableTo": "user", + "columnsFrom": [ + "owner_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "story_folder_project_id_project_id_fk": { + "name": "story_folder_project_id_project_id_fk", + "tableFrom": "story_folder", + "tableTo": "project", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "story_folder_parent_id_story_folder_id_fk": { + "name": "story_folder_parent_id_story_folder_id_fk", + "tableFrom": "story_folder", + "tableTo": "story_folder", + "columnsFrom": [ + "parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "story_folder_item": { + "name": "story_folder_item", + "columns": { + "story_id": { + "name": "story_id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "folder_id": { + "name": "folder_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "story_folder_item_folderId_idx": { + "name": "story_folder_item_folderId_idx", + "columns": [ + "folder_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "story_folder_item_story_id_story_id_fk": { + "name": "story_folder_item_story_id_story_id_fk", + "tableFrom": "story_folder_item", + "tableTo": "story", + "columnsFrom": [ + "story_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "story_folder_item_folder_id_story_folder_id_fk": { + "name": "story_folder_item_folder_id_story_folder_id_fk", + "tableFrom": "story_folder_item", + "tableTo": "story_folder", + "columnsFrom": [ + "folder_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "story_version": { + "name": "story_version", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "story_id": { + "name": "story_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "code": { + "name": "code", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "action": { + "name": "action", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + } + }, + "indexes": { + "story_version_storyId_idx": { + "name": "story_version_storyId_idx", + "columns": [ + "story_id" + ], + "isUnique": false + }, + "story_version_story_version_unique": { + "name": "story_version_story_version_unique", + "columns": [ + "story_id", + "version" + ], + "isUnique": true + } + }, + "foreignKeys": { + "story_version_story_id_story_id_fk": { + "name": "story_version_story_id_story_id_fk", + "tableFrom": "story_version", + "tableTo": "story", + "columnsFrom": [ + "story_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "user": { + "name": "user", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "email_verified": { + "name": "email_verified", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": false + }, + "image": { + "name": "image", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "requires_password_reset": { + "name": "requires_password_reset", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": false + }, + "memory_enabled": { + "name": "memory_enabled", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": true + }, + "messaging_provider_code": { + "name": "messaging_provider_code", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "github_access_token": { + "name": "github_access_token", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + } + }, + "indexes": { + "user_email_unique": { + "name": "user_email_unique", + "columns": [ + "email" + ], + "isUnique": true + }, + "user_messaging_provider_code_unique": { + "name": "user_messaging_provider_code_unique", + "columns": [ + "messaging_provider_code" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "user_preference": { + "name": "user_preference", + "columns": { + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "preferences": { + "name": "preferences", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'{}'" + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + } + }, + "indexes": {}, + "foreignKeys": { + "user_preference_user_id_user_id_fk": { + "name": "user_preference_user_id_user_id_fk", + "tableFrom": "user_preference", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "verification": { + "name": "verification", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "identifier": { + "name": "identifier", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "value": { + "name": "value", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "expires_at": { + "name": "expires_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + } + }, + "indexes": { + "verification_identifier_idx": { + "name": "verification_identifier_idx", + "columns": [ + "identifier" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + } + }, + "views": {}, + "enums": {}, + "_meta": { + "schemas": {}, + "tables": {}, + "columns": {} + }, + "internal": { + "indexes": {} + } +} \ No newline at end of file diff --git a/apps/backend/migrations-sqlite/meta/_journal.json b/apps/backend/migrations-sqlite/meta/_journal.json index 6dc18189b..ec726417c 100644 --- a/apps/backend/migrations-sqlite/meta/_journal.json +++ b/apps/backend/migrations-sqlite/meta/_journal.json @@ -372,6 +372,13 @@ "when": 1782391309531, "tag": "0052_add_brand_color", "breakpoints": true + }, + { + "idx": 53, + "version": "6", + "when": 1782762525897, + "tag": "0053_add_memories_project_id", + "breakpoints": true } ] } \ No newline at end of file diff --git a/apps/backend/src/components/ai/context-recommendations-prompt.tsx b/apps/backend/src/components/ai/context-recommendations-prompt.tsx index 099f9a1ae..c6c462896 100644 --- a/apps/backend/src/components/ai/context-recommendations-prompt.tsx +++ b/apps/backend/src/components/ai/context-recommendations-prompt.tsx @@ -50,6 +50,11 @@ function ContextRecommendationsPrompt({ Repeated corrections: v_memories where category = "global_rule" — each is a rule users had to teach; it likely belongs in RULES.md or semantics/*.md. + + De-facto rules: v_memories where category = "personal_rule" — these are personal rules + users defined for themselves. Cluster by user_id and content; when several users independently + defined a similar rule, it is a strong candidate to promote into RULES.md as shared context. + Downvote themes: v_messages where vote = "down" (+ explanation). Regeneration / friction: v_messages where superseded_at is not null. diff --git a/apps/backend/src/components/ai/system-prompt.tsx b/apps/backend/src/components/ai/system-prompt.tsx index 390ec8ee7..e346e6d82 100644 --- a/apps/backend/src/components/ai/system-prompt.tsx +++ b/apps/backend/src/components/ai/system-prompt.tsx @@ -31,7 +31,9 @@ export function SystemPrompt({ timezone, testMode, }: SystemPromptProps) { - const visibleMemories = getMemoriesInTokenRange(memories, MEMORY_TOKEN_LIMIT); + const personalRules = memories.filter((memory) => memory.category === 'personal_rule'); + const otherMemories = memories.filter((memory) => memory.category !== 'personal_rule'); + const visibleMemories = getMemoriesInTokenRange(otherMemories, MEMORY_TOKEN_LIMIT); const hasClickHouse = connections.some((connection) => connection.type.toLowerCase() === 'clickhouse'); const hasTSQL = connections.some((connection) => ['mssql', 'fabric'].includes(connection.type.toLowerCase())); const hasBigQuery = connections.some((connection) => connection.type.toLowerCase() === 'bigquery'); @@ -186,10 +188,21 @@ export function SystemPrompt({ - {userRules && ( + {(userRules || personalRules.length > 0) && ( User Rules {userRules} + {personalRules.length > 0 && ( + <> + Personal Rules + These rules were defined by the user in their settings. Always follow them. + + {personalRules.map((rule) => ( + {rule.content} + ))} + + + )} )} @@ -249,6 +262,7 @@ function getMemoriesInTokenRange(memories: UserMemory[], limit: number): UserMem } const CATEGORY_LABEL: Record = { + personal_rule: 'Personal Rules', global_rule: 'Global User Rules', personal_fact: 'User Profile', }; diff --git a/apps/backend/src/db/app-db-views.ts b/apps/backend/src/db/app-db-views.ts index 173d51b41..5f80478bd 100644 --- a/apps/backend/src/db/app-db-views.ts +++ b/apps/backend/src/db/app-db-views.ts @@ -1,4 +1,4 @@ -import { asc, eq, inArray } from 'drizzle-orm'; +import { asc, eq, inArray, or } from 'drizzle-orm'; import { pgTable, QueryBuilder as PgQueryBuilder, text as pgText } from 'drizzle-orm/pg-core'; import { QueryBuilder as SqliteQueryBuilder, sqliteTable, text as sqliteText } from 'drizzle-orm/sqlite-core'; @@ -77,6 +77,7 @@ function buildScopedViews(schema: ViewSchema, scope: ScopeTable, qb: SqliteQuery content: memories.content, category: memories.category, chat_id: memories.chatId, + project_id: memories.projectId, superseded_by: memories.supersededBy, created_at: memories.createdAt, }; @@ -118,9 +119,12 @@ function buildScopedViews(schema: ViewSchema, scope: ScopeTable, qb: SqliteQuery .select(memoriesSelection) .from(memories) .where( - inArray( - memories.chatId, - qb.select({ id: chat.id }).from(chat).where(inArray(chat.projectId, scopedProjectIds())), + or( + inArray( + memories.chatId, + qb.select({ id: chat.id }).from(chat).where(inArray(chat.projectId, scopedProjectIds())), + ), + inArray(memories.projectId, scopedProjectIds()), ), ), ), diff --git a/apps/backend/src/db/pg-schema.ts b/apps/backend/src/db/pg-schema.ts index e22d0f84e..8a471def4 100644 --- a/apps/backend/src/db/pg-schema.ts +++ b/apps/backend/src/db/pg-schema.ts @@ -874,11 +874,13 @@ export const memories = pgTable( .$onUpdate(() => new Date()) .notNull(), chatId: text('chat_id').references(() => chat.id, { onDelete: 'set null' }), + projectId: text('project_id').references(() => project.id, { onDelete: 'cascade' }), supersededBy: text('superseded_by'), }, (t) => [ index('memories_userId_idx').on(t.userId), index('memories_chatId_idx').on(t.chatId), + index('memories_projectId_idx').on(t.projectId), index('memories_supersededBy_idx').on(t.supersededBy), ], ); diff --git a/apps/backend/src/db/sqlite-schema.ts b/apps/backend/src/db/sqlite-schema.ts index 45c4c21ed..aee40450a 100644 --- a/apps/backend/src/db/sqlite-schema.ts +++ b/apps/backend/src/db/sqlite-schema.ts @@ -940,11 +940,13 @@ export const memories = sqliteTable( .$onUpdate(() => new Date()) .notNull(), chatId: text('chat_id').references(() => chat.id, { onDelete: 'set null' }), + projectId: text('project_id').references(() => project.id, { onDelete: 'cascade' }), supersededBy: text('superseded_by'), }, (t) => [ index('memories_userId_idx').on(t.userId), index('memories_chatId_idx').on(t.chatId), + index('memories_projectId_idx').on(t.projectId), index('memories_supersededBy_idx').on(t.supersededBy), ], ); diff --git a/apps/backend/src/queries/memory.ts b/apps/backend/src/queries/memory.ts index 161025f21..ecd698b8a 100644 --- a/apps/backend/src/queries/memory.ts +++ b/apps/backend/src/queries/memory.ts @@ -2,20 +2,24 @@ import { and, desc, eq, isNull, ne, or } from 'drizzle-orm'; import s, { DBMemory, DBNewMemory } from '../db/abstractSchema'; import { db } from '../db/db'; +import { PERSONAL_RULE_CATEGORY } from '../types/memory'; import { conflictUpdateSet, takeFirstOrThrow } from '../utils/queries'; +const memorySelection = { + id: s.memories.id, + userId: s.memories.userId, + chatId: s.memories.chatId, + projectId: s.memories.projectId, + content: s.memories.content, + category: s.memories.category, + supersededBy: s.memories.supersededBy, + createdAt: s.memories.createdAt, + updatedAt: s.memories.updatedAt, +}; + export const getUserMemories = async (userId: string, excludeChatId?: string): Promise => { const memories = await db - .select({ - id: s.memories.id, - userId: s.memories.userId, - chatId: s.memories.chatId, - content: s.memories.content, - category: s.memories.category, - supersededBy: s.memories.supersededBy, - createdAt: s.memories.createdAt, - updatedAt: s.memories.updatedAt, - }) + .select(memorySelection) .from(s.memories) .where( and( @@ -30,6 +34,73 @@ export const getUserMemories = async (userId: string, excludeChatId?: string): P return memories; }; +/** + * Memories to inject into the system prompt: extracted memories (project-agnostic) + * plus personal rules authored for the current project. + */ +export const getUserMemoriesForPrompt = async ( + userId: string, + projectId: string, + excludeChatId?: string, +): Promise => { + return db + .select(memorySelection) + .from(s.memories) + .where( + and( + eq(s.memories.userId, userId), + isNull(s.memories.supersededBy), + or(isNull(s.memories.projectId), eq(s.memories.projectId, projectId)), + excludeChatId ? or(ne(s.memories.chatId, excludeChatId), isNull(s.memories.chatId)) : undefined, + ), + ) + .orderBy(desc(s.memories.createdAt)) + .execute(); +}; + +/** Memories shown on the Memory settings page (excludes user-authored personal rules). */ +export const getUserSavedMemories = async (userId: string): Promise => { + return db + .select(memorySelection) + .from(s.memories) + .where( + and( + eq(s.memories.userId, userId), + isNull(s.memories.supersededBy), + ne(s.memories.category, PERSONAL_RULE_CATEGORY), + ), + ) + .orderBy(desc(s.memories.createdAt)) + .execute(); +}; + +/** User-authored personal rules for a given project. */ +export const getUserRules = async (userId: string, projectId: string): Promise => { + return db + .select(memorySelection) + .from(s.memories) + .where( + and( + eq(s.memories.userId, userId), + eq(s.memories.category, PERSONAL_RULE_CATEGORY), + eq(s.memories.projectId, projectId), + isNull(s.memories.supersededBy), + ), + ) + .orderBy(desc(s.memories.createdAt)) + .execute(); +}; + +export const createUserRule = async (userId: string, projectId: string, content: string): Promise => { + return takeFirstOrThrow( + db + .insert(s.memories) + .values({ userId, projectId, content, category: PERSONAL_RULE_CATEGORY }) + .returning() + .execute(), + ); +}; + export const getIsMemoryEnabledForUserAndProject = async (userId: string, projectId: string): Promise => { const [settings] = await db .select({ diff --git a/apps/backend/src/services/memory.ts b/apps/backend/src/services/memory.ts index 697af8bd4..1ce5dcf4b 100644 --- a/apps/backend/src/services/memory.ts +++ b/apps/backend/src/services/memory.ts @@ -30,7 +30,7 @@ class MemoryService { if (!isEnabled) { return []; } - const memories = await memoryQueries.getUserMemories(userId, excludeChatId); + const memories = await memoryQueries.getUserMemoriesForPrompt(userId, projectId, excludeChatId); return memories.map((memory) => ({ category: memory.category, content: memory.content, diff --git a/apps/backend/src/trpc/router.ts b/apps/backend/src/trpc/router.ts index 99d41e9f1..dae83379b 100644 --- a/apps/backend/src/trpc/router.ts +++ b/apps/backend/src/trpc/router.ts @@ -23,6 +23,7 @@ import { memoryRoutes } from './memory.routes'; import { organizationRoutes } from './organization.routes'; import { posthogRoutes } from './posthog.routes'; import { projectRoutes } from './project.routes'; +import { ruleRoutes } from './rule.routes'; import { sharedChatRoutes } from './shared-chat.routes'; import { sharedStoryRoutes } from './shared-story.routes'; import { skillRoutes } from './skill.routes'; @@ -60,6 +61,7 @@ export const trpcRouter = router({ usage: usageRoutes, user: userRoutes, memory: memoryRoutes, + rule: ruleRoutes, organization: organizationRoutes, authConfig: authConfigRoutes, account: accountRoutes, diff --git a/apps/backend/src/trpc/rule.routes.ts b/apps/backend/src/trpc/rule.routes.ts new file mode 100644 index 000000000..de762ae57 --- /dev/null +++ b/apps/backend/src/trpc/rule.routes.ts @@ -0,0 +1,62 @@ +import { TRPCError } from '@trpc/server'; +import { z } from 'zod/v4'; + +import * as memoryQueries from '../queries/memory'; +import { memoryService } from '../services/memory'; +import { posthog, PostHogEvent } from '../services/posthog'; +import { projectProtectedProcedure } from './trpc'; + +const MAX_RULE_LENGTH = 1000; + +export const ruleRoutes = { + list: projectProtectedProcedure.query(async ({ ctx }) => { + return memoryQueries.getUserRules(ctx.user.id, ctx.project.id); + }), + + create: projectProtectedProcedure + .input(z.object({ content: z.string().trim().min(1).max(MAX_RULE_LENGTH) })) + .mutation(async ({ ctx, input }) => { + const content = memoryService.normalizeMemoryContent(input.content); + if (!content) { + throw new TRPCError({ code: 'BAD_REQUEST', message: 'Rule content cannot be empty.' }); + } + const rule = await memoryQueries.createUserRule(ctx.user.id, ctx.project.id, content); + posthog.capture(ctx.user.id, PostHogEvent.AgentMemoryUpdated, { + project_id: ctx.project.id, + memory_id: rule.id, + memory_category: rule.category, + }); + return rule; + }), + + update: projectProtectedProcedure + .input(z.object({ ruleId: z.string(), content: z.string().trim().min(1).max(MAX_RULE_LENGTH) })) + .mutation(async ({ ctx, input }) => { + const content = memoryService.normalizeMemoryContent(input.content); + if (!content) { + throw new TRPCError({ code: 'BAD_REQUEST', message: 'Rule content cannot be empty.' }); + } + const updated = await memoryQueries.updateUserMemoryContent(ctx.user.id, input.ruleId, content); + if (!updated) { + throw new TRPCError({ code: 'NOT_FOUND', message: 'Rule not found.' }); + } + posthog.capture(ctx.user.id, PostHogEvent.AgentMemoryUpdated, { + project_id: ctx.project.id, + memory_id: input.ruleId, + memory_category: updated.category, + }); + return updated; + }), + + delete: projectProtectedProcedure.input(z.object({ ruleId: z.string() })).mutation(async ({ ctx, input }) => { + const deleted = await memoryQueries.deleteUserMemory(ctx.user.id, input.ruleId); + if (!deleted) { + throw new TRPCError({ code: 'NOT_FOUND', message: 'Rule not found.' }); + } + posthog.capture(ctx.user.id, PostHogEvent.AgentMemoryDeleted, { + project_id: ctx.project.id, + memory_id: input.ruleId, + memory_category: deleted.category, + }); + }), +}; diff --git a/apps/backend/src/trpc/user.routes.ts b/apps/backend/src/trpc/user.routes.ts index 6f63a059a..d47b74e3f 100644 --- a/apps/backend/src/trpc/user.routes.ts +++ b/apps/backend/src/trpc/user.routes.ts @@ -99,6 +99,6 @@ export const userRoutes = { }), getMemories: protectedProcedure.query(async ({ ctx }) => { - return memoryQueries.getUserMemories(ctx.user.id); + return memoryQueries.getUserSavedMemories(ctx.user.id); }), }; diff --git a/apps/backend/src/types/memory.ts b/apps/backend/src/types/memory.ts index 84a9cc4a7..9a9d6d08f 100644 --- a/apps/backend/src/types/memory.ts +++ b/apps/backend/src/types/memory.ts @@ -4,11 +4,14 @@ import { z } from 'zod/v4'; import { DBMemory } from '../db/abstractSchema'; import { UIMessage } from './chat'; -/** Categories of memories that can be extracted from user messages. Ordered by priority. */ -export const MEMORY_CATEGORIES = ['global_rule', 'personal_fact'] as const; +/** Categories of memories. Ordered by priority for system prompt injection. */ +export const MEMORY_CATEGORIES = ['personal_rule', 'global_rule', 'personal_fact'] as const; export type MemoryCategory = (typeof MEMORY_CATEGORIES)[number]; +/** User-authored rules managed from settings (not extracted from conversations). */ +export const PERSONAL_RULE_CATEGORY = 'personal_rule' satisfies MemoryCategory; + export interface UserMemory { category: MemoryCategory; content: string; diff --git a/apps/frontend/src/components/settings-search-index.ts b/apps/frontend/src/components/settings-search-index.ts index a7fb820d1..79c89cb54 100644 --- a/apps/frontend/src/components/settings-search-index.ts +++ b/apps/frontend/src/components/settings-search-index.ts @@ -559,6 +559,15 @@ export const settingsSearchIndex: SettingsSearchEntry[] = [ cloudHidden: true, }, + // ── Rules (user-level) ─────────────────────────────────── + { + page: '/settings/rules', + pageLabel: 'Rules', + title: 'Rules', + description: 'Personal rules added to every system prompt and layered on top of global project rules.', + keywords: ['rules', 'instructions', 'preferences', 'system prompt', 'personal rules', 'guidelines'], + }, + // ── Memory (user-level) ────────────────────────────────── { page: '/settings/memory', diff --git a/apps/frontend/src/components/settings/rules.tsx b/apps/frontend/src/components/settings/rules.tsx new file mode 100644 index 000000000..002510719 --- /dev/null +++ b/apps/frontend/src/components/settings/rules.tsx @@ -0,0 +1,203 @@ +import { useState } from 'react'; +import { Pencil, Plus, Trash2 } from 'lucide-react'; +import type { UserRule } from '@/queries/use-rules'; +import { + AlertDialog, + AlertDialogAction, + AlertDialogCancel, + AlertDialogContent, + AlertDialogDescription, + AlertDialogFooter, + AlertDialogHeader, + AlertDialogTitle, +} from '@/components/ui/alert-dialog'; +import { Button } from '@/components/ui/button'; +import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog'; +import { Empty } from '@/components/ui/empty'; +import { ErrorMessage } from '@/components/ui/error-message'; +import { SettingsCard } from '@/components/ui/settings-card'; +import { Skeleton } from '@/components/ui/skeleton'; +import { Textarea } from '@/components/ui/textarea'; +import { useRuleMutations, useRulesQuery } from '@/queries/use-rules'; +import { cn } from '@/lib/utils'; + +export function SettingsRules() { + const { data: rules, isLoading } = useRulesQuery(); + const { createMutation, updateMutation, deleteMutation } = useRuleMutations(); + + const [newRule, setNewRule] = useState(''); + const [editRule, setEditRule] = useState(null); + const [editContent, setEditContent] = useState(''); + const [ruleToDelete, setRuleToDelete] = useState(null); + + const handleCreate = async () => { + const content = newRule.trim(); + if (!content) { + return; + } + await createMutation.mutateAsync({ content }); + setNewRule(''); + }; + + const handleSaveEdit = async () => { + if (!editRule) { + return; + } + await updateMutation.mutateAsync({ ruleId: editRule.id, content: editContent }); + setEditRule(null); + }; + + const handleConfirmDelete = () => { + if (!ruleToDelete) { + return; + } + deleteMutation.mutate({ ruleId: ruleToDelete.id }); + }; + + return ( + <> + +
+