From cd4d20ef1878b1995d1160308a04935a2ee504df Mon Sep 17 00:00:00 2001 From: Vikhyath Mondreti Date: Thu, 19 Jun 2025 14:54:33 -0700 Subject: [PATCH 1/2] fix decimal entry issues --- .../migrations/0044_uneven_killer_shrike.sql | 4 + .../sim/db/migrations/meta/0044_snapshot.json | 3738 +++++++++++++++++ apps/sim/db/migrations/meta/_journal.json | 9 +- apps/sim/db/migrations/relations.ts | 308 ++ apps/sim/db/migrations/schema.ts | 722 ++++ apps/sim/db/schema.ts | 6 +- apps/sim/lib/workflows/db-helpers.ts | 4 +- 7 files changed, 4785 insertions(+), 6 deletions(-) create mode 100644 apps/sim/db/migrations/0044_uneven_killer_shrike.sql create mode 100644 apps/sim/db/migrations/meta/0044_snapshot.json create mode 100644 apps/sim/db/migrations/relations.ts create mode 100644 apps/sim/db/migrations/schema.ts diff --git a/apps/sim/db/migrations/0044_uneven_killer_shrike.sql b/apps/sim/db/migrations/0044_uneven_killer_shrike.sql new file mode 100644 index 00000000000..b2ed1d26071 --- /dev/null +++ b/apps/sim/db/migrations/0044_uneven_killer_shrike.sql @@ -0,0 +1,4 @@ +ALTER TABLE "workflow_blocks" ALTER COLUMN "position_x" SET DATA TYPE numeric;--> statement-breakpoint +ALTER TABLE "workflow_blocks" ALTER COLUMN "position_y" SET DATA TYPE numeric;--> statement-breakpoint +ALTER TABLE "workflow_blocks" ALTER COLUMN "height" SET DATA TYPE numeric;--> statement-breakpoint +ALTER TABLE "workflow_blocks" ALTER COLUMN "height" SET DEFAULT '0'; diff --git a/apps/sim/db/migrations/meta/0044_snapshot.json b/apps/sim/db/migrations/meta/0044_snapshot.json new file mode 100644 index 00000000000..414d83ef78b --- /dev/null +++ b/apps/sim/db/migrations/meta/0044_snapshot.json @@ -0,0 +1,3738 @@ +{ + "id": "1759bea4-96f8-432b-9dc7-55e8dbf8c970", + "prevId": "05e26e13-3a24-4e29-b48b-e70b156e7434", + "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 + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "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.api_key": { + "name": "api_key", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "key": { + "name": "key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "last_used": { + "name": "last_used", + "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()" + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "api_key_user_id_user_id_fk": { + "name": "api_key_user_id_user_id_fk", + "tableFrom": "api_key", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "api_key_key_unique": { + "name": "api_key_key_unique", + "nullsNotDistinct": false, + "columns": [ + "key" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.chat": { + "name": "chat", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workflow_id": { + "name": "workflow_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "subdomain": { + "name": "subdomain", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "is_active": { + "name": "is_active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "customizations": { + "name": "customizations", + "type": "json", + "primaryKey": false, + "notNull": false, + "default": "'{}'" + }, + "auth_type": { + "name": "auth_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'public'" + }, + "password": { + "name": "password", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "allowed_emails": { + "name": "allowed_emails", + "type": "json", + "primaryKey": false, + "notNull": false, + "default": "'[]'" + }, + "output_configs": { + "name": "output_configs", + "type": "json", + "primaryKey": false, + "notNull": false, + "default": "'[]'" + }, + "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": { + "subdomain_idx": { + "name": "subdomain_idx", + "columns": [ + { + "expression": "subdomain", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "chat_workflow_id_workflow_id_fk": { + "name": "chat_workflow_id_workflow_id_fk", + "tableFrom": "chat", + "tableTo": "workflow", + "columnsFrom": [ + "workflow_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "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" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.custom_tools": { + "name": "custom_tools", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "schema": { + "name": "schema", + "type": "json", + "primaryKey": false, + "notNull": true + }, + "code": { + "name": "code", + "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": {}, + "foreignKeys": { + "custom_tools_user_id_user_id_fk": { + "name": "custom_tools_user_id_user_id_fk", + "tableFrom": "custom_tools", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.document": { + "name": "document", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "knowledge_base_id": { + "name": "knowledge_base_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "filename": { + "name": "filename", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "file_url": { + "name": "file_url", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "file_size": { + "name": "file_size", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "mime_type": { + "name": "mime_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "file_hash": { + "name": "file_hash", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "chunk_count": { + "name": "chunk_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "token_count": { + "name": "token_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "character_count": { + "name": "character_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "processing_status": { + "name": "processing_status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "processing_started_at": { + "name": "processing_started_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "processing_completed_at": { + "name": "processing_completed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "processing_error": { + "name": "processing_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "enabled": { + "name": "enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "uploaded_at": { + "name": "uploaded_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "doc_kb_id_idx": { + "name": "doc_kb_id_idx", + "columns": [ + { + "expression": "knowledge_base_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "doc_file_hash_idx": { + "name": "doc_file_hash_idx", + "columns": [ + { + "expression": "file_hash", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "doc_filename_idx": { + "name": "doc_filename_idx", + "columns": [ + { + "expression": "filename", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "doc_kb_uploaded_at_idx": { + "name": "doc_kb_uploaded_at_idx", + "columns": [ + { + "expression": "knowledge_base_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "uploaded_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "doc_processing_status_idx": { + "name": "doc_processing_status_idx", + "columns": [ + { + "expression": "knowledge_base_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "processing_status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "document_knowledge_base_id_knowledge_base_id_fk": { + "name": "document_knowledge_base_id_knowledge_base_id_fk", + "tableFrom": "document", + "tableTo": "knowledge_base", + "columnsFrom": [ + "knowledge_base_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.embedding": { + "name": "embedding", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "knowledge_base_id": { + "name": "knowledge_base_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "document_id": { + "name": "document_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "chunk_index": { + "name": "chunk_index", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "chunk_hash": { + "name": "chunk_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "content": { + "name": "content", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "content_length": { + "name": "content_length", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "token_count": { + "name": "token_count", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "embedding": { + "name": "embedding", + "type": "vector(1536)", + "primaryKey": false, + "notNull": false + }, + "embedding_model": { + "name": "embedding_model", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'text-embedding-3-small'" + }, + "start_offset": { + "name": "start_offset", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "end_offset": { + "name": "end_offset", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "overlap_tokens": { + "name": "overlap_tokens", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'" + }, + "search_rank": { + "name": "search_rank", + "type": "numeric", + "primaryKey": false, + "notNull": false, + "default": "'1.0'" + }, + "access_count": { + "name": "access_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "last_accessed_at": { + "name": "last_accessed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "quality_score": { + "name": "quality_score", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "enabled": { + "name": "enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "content_tsv": { + "name": "content_tsv", + "type": "tsvector", + "primaryKey": false, + "notNull": false, + "generated": { + "as": "to_tsvector('english', \"embedding\".\"content\")", + "type": "stored" + } + }, + "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": { + "emb_kb_id_idx": { + "name": "emb_kb_id_idx", + "columns": [ + { + "expression": "knowledge_base_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "emb_doc_id_idx": { + "name": "emb_doc_id_idx", + "columns": [ + { + "expression": "document_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "emb_doc_chunk_idx": { + "name": "emb_doc_chunk_idx", + "columns": [ + { + "expression": "document_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "chunk_index", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "emb_kb_model_idx": { + "name": "emb_kb_model_idx", + "columns": [ + { + "expression": "knowledge_base_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "embedding_model", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "emb_chunk_hash_idx": { + "name": "emb_chunk_hash_idx", + "columns": [ + { + "expression": "chunk_hash", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "emb_kb_access_idx": { + "name": "emb_kb_access_idx", + "columns": [ + { + "expression": "knowledge_base_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "last_accessed_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "emb_kb_rank_idx": { + "name": "emb_kb_rank_idx", + "columns": [ + { + "expression": "knowledge_base_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "search_rank", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "emb_kb_enabled_idx": { + "name": "emb_kb_enabled_idx", + "columns": [ + { + "expression": "knowledge_base_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "enabled", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "emb_doc_enabled_idx": { + "name": "emb_doc_enabled_idx", + "columns": [ + { + "expression": "document_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "enabled", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "embedding_vector_hnsw_idx": { + "name": "embedding_vector_hnsw_idx", + "columns": [ + { + "expression": "embedding", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "vector_cosine_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "hnsw", + "with": { + "m": 16, + "ef_construction": 64 + } + }, + "emb_metadata_gin_idx": { + "name": "emb_metadata_gin_idx", + "columns": [ + { + "expression": "metadata", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "gin", + "with": {} + }, + "emb_content_fts_idx": { + "name": "emb_content_fts_idx", + "columns": [ + { + "expression": "content_tsv", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "gin", + "with": {} + } + }, + "foreignKeys": { + "embedding_knowledge_base_id_knowledge_base_id_fk": { + "name": "embedding_knowledge_base_id_knowledge_base_id_fk", + "tableFrom": "embedding", + "tableTo": "knowledge_base", + "columnsFrom": [ + "knowledge_base_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "embedding_document_id_document_id_fk": { + "name": "embedding_document_id_document_id_fk", + "tableFrom": "embedding", + "tableTo": "document", + "columnsFrom": [ + "document_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "embedding_not_null_check": { + "name": "embedding_not_null_check", + "value": "\"embedding\" IS NOT NULL" + } + }, + "isRLSEnabled": false + }, + "public.environment": { + "name": "environment", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "variables": { + "name": "variables", + "type": "json", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "environment_user_id_user_id_fk": { + "name": "environment_user_id_user_id_fk", + "tableFrom": "environment", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "environment_user_id_unique": { + "name": "environment_user_id_unique", + "nullsNotDistinct": false, + "columns": [ + "user_id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.invitation": { + "name": "invitation", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "inviter_id": { + "name": "inviter_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "role": { + "name": "role", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "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()" + } + }, + "indexes": {}, + "foreignKeys": { + "invitation_inviter_id_user_id_fk": { + "name": "invitation_inviter_id_user_id_fk", + "tableFrom": "invitation", + "tableTo": "user", + "columnsFrom": [ + "inviter_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "invitation_organization_id_organization_id_fk": { + "name": "invitation_organization_id_organization_id_fk", + "tableFrom": "invitation", + "tableTo": "organization", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.knowledge_base": { + "name": "knowledge_base", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "token_count": { + "name": "token_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "embedding_model": { + "name": "embedding_model", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'text-embedding-3-small'" + }, + "embedding_dimension": { + "name": "embedding_dimension", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1536 + }, + "chunking_config": { + "name": "chunking_config", + "type": "json", + "primaryKey": false, + "notNull": true, + "default": "'{\"maxSize\": 1024, \"minSize\": 100, \"overlap\": 200}'" + }, + "deleted_at": { + "name": "deleted_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": { + "kb_user_id_idx": { + "name": "kb_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "kb_workspace_id_idx": { + "name": "kb_workspace_id_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "kb_user_workspace_idx": { + "name": "kb_user_workspace_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "kb_deleted_at_idx": { + "name": "kb_deleted_at_idx", + "columns": [ + { + "expression": "deleted_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "knowledge_base_user_id_user_id_fk": { + "name": "knowledge_base_user_id_user_id_fk", + "tableFrom": "knowledge_base", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "knowledge_base_workspace_id_workspace_id_fk": { + "name": "knowledge_base_workspace_id_workspace_id_fk", + "tableFrom": "knowledge_base", + "tableTo": "workspace", + "columnsFrom": [ + "workspace_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.marketplace": { + "name": "marketplace", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workflow_id": { + "name": "workflow_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "state": { + "name": "state", + "type": "json", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "author_id": { + "name": "author_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "author_name": { + "name": "author_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "views": { + "name": "views", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "category": { + "name": "category", + "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": { + "marketplace_workflow_id_workflow_id_fk": { + "name": "marketplace_workflow_id_workflow_id_fk", + "tableFrom": "marketplace", + "tableTo": "workflow", + "columnsFrom": [ + "workflow_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "marketplace_author_id_user_id_fk": { + "name": "marketplace_author_id_user_id_fk", + "tableFrom": "marketplace", + "tableTo": "user", + "columnsFrom": [ + "author_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.member": { + "name": "member", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "organization_id": { + "name": "organization_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": {}, + "foreignKeys": { + "member_user_id_user_id_fk": { + "name": "member_user_id_user_id_fk", + "tableFrom": "member", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "member_organization_id_organization_id_fk": { + "name": "member_organization_id_organization_id_fk", + "tableFrom": "member", + "tableTo": "organization", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.memory": { + "name": "memory", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workflow_id": { + "name": "workflow_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "key": { + "name": "key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "data": { + "name": "data", + "type": "json", + "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()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "memory_key_idx": { + "name": "memory_key_idx", + "columns": [ + { + "expression": "key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "memory_workflow_idx": { + "name": "memory_workflow_idx", + "columns": [ + { + "expression": "workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "memory_workflow_key_idx": { + "name": "memory_workflow_key_idx", + "columns": [ + { + "expression": "workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "memory_workflow_id_workflow_id_fk": { + "name": "memory_workflow_id_workflow_id_fk", + "tableFrom": "memory", + "tableTo": "workflow", + "columnsFrom": [ + "workflow_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "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 + }, + "logo": { + "name": "logo", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "metadata": { + "name": "metadata", + "type": "json", + "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": {}, + "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 + }, + "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 + }, + "active_organization_id": { + "name": "active_organization_id", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "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" + }, + "session_active_organization_id_organization_id_fk": { + "name": "session_active_organization_id_organization_id_fk", + "tableFrom": "session", + "tableTo": "organization", + "columnsFrom": [ + "active_organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "session_token_unique": { + "name": "session_token_unique", + "nullsNotDistinct": false, + "columns": [ + "token" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.settings": { + "name": "settings", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "theme": { + "name": "theme", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'system'" + }, + "debug_mode": { + "name": "debug_mode", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "auto_connect": { + "name": "auto_connect", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "auto_fill_env_vars": { + "name": "auto_fill_env_vars", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "telemetry_enabled": { + "name": "telemetry_enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "telemetry_notified_user": { + "name": "telemetry_notified_user", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "email_preferences": { + "name": "email_preferences", + "type": "json", + "primaryKey": false, + "notNull": true, + "default": "'{}'" + }, + "general": { + "name": "general", + "type": "json", + "primaryKey": false, + "notNull": true, + "default": "'{}'" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "settings_user_id_user_id_fk": { + "name": "settings_user_id_user_id_fk", + "tableFrom": "settings", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "settings_user_id_unique": { + "name": "settings_user_id_unique", + "nullsNotDistinct": false, + "columns": [ + "user_id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.subscription": { + "name": "subscription", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "plan": { + "name": "plan", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "reference_id": { + "name": "reference_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "stripe_customer_id": { + "name": "stripe_customer_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "stripe_subscription_id": { + "name": "stripe_subscription_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "period_start": { + "name": "period_start", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "period_end": { + "name": "period_end", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "cancel_at_period_end": { + "name": "cancel_at_period_end", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "seats": { + "name": "seats", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "trial_start": { + "name": "trial_start", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "trial_end": { + "name": "trial_end", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "metadata": { + "name": "metadata", + "type": "json", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "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 + }, + "image": { + "name": "image", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "stripe_customer_id": { + "name": "stripe_customer_id", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "user_email_unique": { + "name": "user_email_unique", + "nullsNotDistinct": false, + "columns": [ + "email" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.user_stats": { + "name": "user_stats", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "total_manual_executions": { + "name": "total_manual_executions", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "total_api_calls": { + "name": "total_api_calls", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "total_webhook_triggers": { + "name": "total_webhook_triggers", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "total_scheduled_executions": { + "name": "total_scheduled_executions", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "total_chat_executions": { + "name": "total_chat_executions", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "total_tokens_used": { + "name": "total_tokens_used", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "total_cost": { + "name": "total_cost", + "type": "numeric", + "primaryKey": false, + "notNull": true, + "default": "'0'" + }, + "last_active": { + "name": "last_active", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "user_stats_user_id_user_id_fk": { + "name": "user_stats_user_id_user_id_fk", + "tableFrom": "user_stats", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "user_stats_user_id_unique": { + "name": "user_stats_user_id_unique", + "nullsNotDistinct": false, + "columns": [ + "user_id" + ] + } + }, + "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": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.waitlist": { + "name": "waitlist", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "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": { + "waitlist_email_unique": { + "name": "waitlist_email_unique", + "nullsNotDistinct": false, + "columns": [ + "email" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.webhook": { + "name": "webhook", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workflow_id": { + "name": "workflow_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "path": { + "name": "path", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "provider_config": { + "name": "provider_config", + "type": "json", + "primaryKey": false, + "notNull": false + }, + "is_active": { + "name": "is_active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": 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": { + "path_idx": { + "name": "path_idx", + "columns": [ + { + "expression": "path", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "webhook_workflow_id_workflow_id_fk": { + "name": "webhook_workflow_id_workflow_id_fk", + "tableFrom": "webhook", + "tableTo": "workflow", + "columnsFrom": [ + "workflow_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.workflow": { + "name": "workflow", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "folder_id": { + "name": "folder_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "state": { + "name": "state", + "type": "json", + "primaryKey": false, + "notNull": true + }, + "color": { + "name": "color", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'#3972F6'" + }, + "last_synced": { + "name": "last_synced", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "is_deployed": { + "name": "is_deployed", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "deployed_state": { + "name": "deployed_state", + "type": "json", + "primaryKey": false, + "notNull": false + }, + "deployed_at": { + "name": "deployed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "collaborators": { + "name": "collaborators", + "type": "json", + "primaryKey": false, + "notNull": true, + "default": "'[]'" + }, + "run_count": { + "name": "run_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "last_run_at": { + "name": "last_run_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "variables": { + "name": "variables", + "type": "json", + "primaryKey": false, + "notNull": false, + "default": "'{}'" + }, + "is_published": { + "name": "is_published", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "marketplace_data": { + "name": "marketplace_data", + "type": "json", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "workflow_user_id_user_id_fk": { + "name": "workflow_user_id_user_id_fk", + "tableFrom": "workflow", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "workflow_workspace_id_workspace_id_fk": { + "name": "workflow_workspace_id_workspace_id_fk", + "tableFrom": "workflow", + "tableTo": "workspace", + "columnsFrom": [ + "workspace_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "workflow_folder_id_workflow_folder_id_fk": { + "name": "workflow_folder_id_workflow_folder_id_fk", + "tableFrom": "workflow", + "tableTo": "workflow_folder", + "columnsFrom": [ + "folder_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.workflow_blocks": { + "name": "workflow_blocks", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workflow_id": { + "name": "workflow_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "position_x": { + "name": "position_x", + "type": "numeric", + "primaryKey": false, + "notNull": true + }, + "position_y": { + "name": "position_y", + "type": "numeric", + "primaryKey": false, + "notNull": true + }, + "enabled": { + "name": "enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "horizontal_handles": { + "name": "horizontal_handles", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "is_wide": { + "name": "is_wide", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "height": { + "name": "height", + "type": "numeric", + "primaryKey": false, + "notNull": true, + "default": "'0'" + }, + "sub_blocks": { + "name": "sub_blocks", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'" + }, + "outputs": { + "name": "outputs", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'" + }, + "data": { + "name": "data", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'{}'" + }, + "parent_id": { + "name": "parent_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "extent": { + "name": "extent", + "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": { + "workflow_blocks_workflow_id_idx": { + "name": "workflow_blocks_workflow_id_idx", + "columns": [ + { + "expression": "workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_blocks_parent_id_idx": { + "name": "workflow_blocks_parent_id_idx", + "columns": [ + { + "expression": "parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_blocks_workflow_parent_idx": { + "name": "workflow_blocks_workflow_parent_idx", + "columns": [ + { + "expression": "workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_blocks_workflow_type_idx": { + "name": "workflow_blocks_workflow_type_idx", + "columns": [ + { + "expression": "workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "type", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "workflow_blocks_workflow_id_workflow_id_fk": { + "name": "workflow_blocks_workflow_id_workflow_id_fk", + "tableFrom": "workflow_blocks", + "tableTo": "workflow", + "columnsFrom": [ + "workflow_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.workflow_edges": { + "name": "workflow_edges", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workflow_id": { + "name": "workflow_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "source_block_id": { + "name": "source_block_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "target_block_id": { + "name": "target_block_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "source_handle": { + "name": "source_handle", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "target_handle": { + "name": "target_handle", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "workflow_edges_workflow_id_idx": { + "name": "workflow_edges_workflow_id_idx", + "columns": [ + { + "expression": "workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_edges_source_block_idx": { + "name": "workflow_edges_source_block_idx", + "columns": [ + { + "expression": "source_block_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_edges_target_block_idx": { + "name": "workflow_edges_target_block_idx", + "columns": [ + { + "expression": "target_block_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_edges_workflow_source_idx": { + "name": "workflow_edges_workflow_source_idx", + "columns": [ + { + "expression": "workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "source_block_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_edges_workflow_target_idx": { + "name": "workflow_edges_workflow_target_idx", + "columns": [ + { + "expression": "workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "target_block_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "workflow_edges_workflow_id_workflow_id_fk": { + "name": "workflow_edges_workflow_id_workflow_id_fk", + "tableFrom": "workflow_edges", + "tableTo": "workflow", + "columnsFrom": [ + "workflow_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "workflow_edges_source_block_id_workflow_blocks_id_fk": { + "name": "workflow_edges_source_block_id_workflow_blocks_id_fk", + "tableFrom": "workflow_edges", + "tableTo": "workflow_blocks", + "columnsFrom": [ + "source_block_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "workflow_edges_target_block_id_workflow_blocks_id_fk": { + "name": "workflow_edges_target_block_id_workflow_blocks_id_fk", + "tableFrom": "workflow_edges", + "tableTo": "workflow_blocks", + "columnsFrom": [ + "target_block_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.workflow_folder": { + "name": "workflow_folder", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "parent_id": { + "name": "parent_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "color": { + "name": "color", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'#6B7280'" + }, + "is_expanded": { + "name": "is_expanded", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "sort_order": { + "name": "sort_order", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "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": { + "workflow_folder_user_idx": { + "name": "workflow_folder_user_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_folder_workspace_parent_idx": { + "name": "workflow_folder_workspace_parent_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_folder_parent_sort_idx": { + "name": "workflow_folder_parent_sort_idx", + "columns": [ + { + "expression": "parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "sort_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "workflow_folder_user_id_user_id_fk": { + "name": "workflow_folder_user_id_user_id_fk", + "tableFrom": "workflow_folder", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "workflow_folder_workspace_id_workspace_id_fk": { + "name": "workflow_folder_workspace_id_workspace_id_fk", + "tableFrom": "workflow_folder", + "tableTo": "workspace", + "columnsFrom": [ + "workspace_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.workflow_logs": { + "name": "workflow_logs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workflow_id": { + "name": "workflow_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "execution_id": { + "name": "execution_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "level": { + "name": "level", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "message": { + "name": "message", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "duration": { + "name": "duration", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "trigger": { + "name": "trigger", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "metadata": { + "name": "metadata", + "type": "json", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "workflow_logs_workflow_id_workflow_id_fk": { + "name": "workflow_logs_workflow_id_workflow_id_fk", + "tableFrom": "workflow_logs", + "tableTo": "workflow", + "columnsFrom": [ + "workflow_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.workflow_schedule": { + "name": "workflow_schedule", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workflow_id": { + "name": "workflow_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "cron_expression": { + "name": "cron_expression", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "next_run_at": { + "name": "next_run_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "last_ran_at": { + "name": "last_ran_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "trigger_type": { + "name": "trigger_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "timezone": { + "name": "timezone", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'UTC'" + }, + "failed_count": { + "name": "failed_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'active'" + }, + "last_failed_at": { + "name": "last_failed_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": {}, + "foreignKeys": { + "workflow_schedule_workflow_id_workflow_id_fk": { + "name": "workflow_schedule_workflow_id_workflow_id_fk", + "tableFrom": "workflow_schedule", + "tableTo": "workflow", + "columnsFrom": [ + "workflow_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "workflow_schedule_workflow_id_unique": { + "name": "workflow_schedule_workflow_id_unique", + "nullsNotDistinct": false, + "columns": [ + "workflow_id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.workflow_subflows": { + "name": "workflow_subflows", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workflow_id": { + "name": "workflow_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "config": { + "name": "config", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'" + }, + "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": { + "workflow_subflows_workflow_id_idx": { + "name": "workflow_subflows_workflow_id_idx", + "columns": [ + { + "expression": "workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_subflows_workflow_type_idx": { + "name": "workflow_subflows_workflow_type_idx", + "columns": [ + { + "expression": "workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "type", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "workflow_subflows_workflow_id_workflow_id_fk": { + "name": "workflow_subflows_workflow_id_workflow_id_fk", + "tableFrom": "workflow_subflows", + "tableTo": "workflow", + "columnsFrom": [ + "workflow_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.workspace": { + "name": "workspace", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "owner_id": { + "name": "owner_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": {}, + "foreignKeys": { + "workspace_owner_id_user_id_fk": { + "name": "workspace_owner_id_user_id_fk", + "tableFrom": "workspace", + "tableTo": "user", + "columnsFrom": [ + "owner_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.workspace_invitation": { + "name": "workspace_invitation", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "inviter_id": { + "name": "inviter_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "role": { + "name": "role", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'member'" + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "token": { + "name": "token", + "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": {}, + "foreignKeys": { + "workspace_invitation_workspace_id_workspace_id_fk": { + "name": "workspace_invitation_workspace_id_workspace_id_fk", + "tableFrom": "workspace_invitation", + "tableTo": "workspace", + "columnsFrom": [ + "workspace_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "workspace_invitation_inviter_id_user_id_fk": { + "name": "workspace_invitation_inviter_id_user_id_fk", + "tableFrom": "workspace_invitation", + "tableTo": "user", + "columnsFrom": [ + "inviter_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "workspace_invitation_token_unique": { + "name": "workspace_invitation_token_unique", + "nullsNotDistinct": false, + "columns": [ + "token" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.workspace_member": { + "name": "workspace_member", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_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, + "default": "'member'" + }, + "joined_at": { + "name": "joined_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "user_workspace_idx": { + "name": "user_workspace_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "workspace_member_workspace_id_workspace_id_fk": { + "name": "workspace_member_workspace_id_workspace_id_fk", + "tableFrom": "workspace_member", + "tableTo": "workspace", + "columnsFrom": [ + "workspace_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "workspace_member_user_id_user_id_fk": { + "name": "workspace_member_user_id_user_id_fk", + "tableFrom": "workspace_member", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "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/sim/db/migrations/meta/_journal.json b/apps/sim/db/migrations/meta/_journal.json index 6bf0d597bd7..28478f84736 100644 --- a/apps/sim/db/migrations/meta/_journal.json +++ b/apps/sim/db/migrations/meta/_journal.json @@ -302,6 +302,13 @@ "when": 1750193663357, "tag": "0043_silent_the_anarchist", "breakpoints": true + }, + { + "idx": 44, + "version": "7", + "when": 1750369626350, + "tag": "0044_uneven_killer_shrike", + "breakpoints": true } ] -} +} \ No newline at end of file diff --git a/apps/sim/db/migrations/relations.ts b/apps/sim/db/migrations/relations.ts new file mode 100644 index 00000000000..6010b0806eb --- /dev/null +++ b/apps/sim/db/migrations/relations.ts @@ -0,0 +1,308 @@ +import { relations } from "drizzle-orm/relations"; +import { user, account, workflow, workflowBroadcastConnections, environment, webhook, workflowLogs, apiKey, marketplace, customTools, session, organization, invitation, member, chat, settings, workspace, workspaceMember, workspaceInvitation, userStats, workflowFolder, workflowSchedule, memory, knowledgeBase, document, embedding, workflowBlocks, workflowEdges, workflowSubflows } from "./schema"; + +export const accountRelations = relations(account, ({one}) => ({ + user: one(user, { + fields: [account.userId], + references: [user.id] + }), +})); + +export const userRelations = relations(user, ({many}) => ({ + accounts: many(account), + environments: many(environment), + apiKeys: many(apiKey), + marketplaces: many(marketplace), + customTools: many(customTools), + sessions: many(session), + invitations: many(invitation), + members: many(member), + chats: many(chat), + settings: many(settings), + workspaces: many(workspace), + workspaceMembers: many(workspaceMember), + workspaceInvitations: many(workspaceInvitation), + userStats: many(userStats), + workflows: many(workflow), + knowledgeBases: many(knowledgeBase), + workflowFolders: many(workflowFolder), +})); + +export const workflowBroadcastConnectionsRelations = relations(workflowBroadcastConnections, ({one}) => ({ + workflow: one(workflow, { + fields: [workflowBroadcastConnections.workflowId], + references: [workflow.id] + }), +})); + +export const workflowRelations = relations(workflow, ({one, many}) => ({ + workflowBroadcastConnections: many(workflowBroadcastConnections), + webhooks: many(webhook), + workflowLogs: many(workflowLogs), + marketplaces: many(marketplace), + chats: many(chat), + user: one(user, { + fields: [workflow.userId], + references: [user.id] + }), + workspace: one(workspace, { + fields: [workflow.workspaceId], + references: [workspace.id] + }), + workflowFolder: one(workflowFolder, { + fields: [workflow.folderId], + references: [workflowFolder.id] + }), + workflowSchedules: many(workflowSchedule), + memories: many(memory), + workflowBlocks: many(workflowBlocks), + workflowEdges: many(workflowEdges), + workflowSubflows: many(workflowSubflows), +})); + +export const environmentRelations = relations(environment, ({one}) => ({ + user: one(user, { + fields: [environment.userId], + references: [user.id] + }), +})); + +export const webhookRelations = relations(webhook, ({one}) => ({ + workflow: one(workflow, { + fields: [webhook.workflowId], + references: [workflow.id] + }), +})); + +export const workflowLogsRelations = relations(workflowLogs, ({one}) => ({ + workflow: one(workflow, { + fields: [workflowLogs.workflowId], + references: [workflow.id] + }), +})); + +export const apiKeyRelations = relations(apiKey, ({one}) => ({ + user: one(user, { + fields: [apiKey.userId], + references: [user.id] + }), +})); + +export const marketplaceRelations = relations(marketplace, ({one}) => ({ + workflow: one(workflow, { + fields: [marketplace.workflowId], + references: [workflow.id] + }), + user: one(user, { + fields: [marketplace.authorId], + references: [user.id] + }), +})); + +export const customToolsRelations = relations(customTools, ({one}) => ({ + user: one(user, { + fields: [customTools.userId], + references: [user.id] + }), +})); + +export const sessionRelations = relations(session, ({one}) => ({ + user: one(user, { + fields: [session.userId], + references: [user.id] + }), + organization: one(organization, { + fields: [session.activeOrganizationId], + references: [organization.id] + }), +})); + +export const organizationRelations = relations(organization, ({many}) => ({ + sessions: many(session), + invitations: many(invitation), + members: many(member), +})); + +export const invitationRelations = relations(invitation, ({one}) => ({ + user: one(user, { + fields: [invitation.inviterId], + references: [user.id] + }), + organization: one(organization, { + fields: [invitation.organizationId], + references: [organization.id] + }), +})); + +export const memberRelations = relations(member, ({one}) => ({ + user: one(user, { + fields: [member.userId], + references: [user.id] + }), + organization: one(organization, { + fields: [member.organizationId], + references: [organization.id] + }), +})); + +export const chatRelations = relations(chat, ({one}) => ({ + workflow: one(workflow, { + fields: [chat.workflowId], + references: [workflow.id] + }), + user: one(user, { + fields: [chat.userId], + references: [user.id] + }), +})); + +export const settingsRelations = relations(settings, ({one}) => ({ + user: one(user, { + fields: [settings.userId], + references: [user.id] + }), +})); + +export const workspaceRelations = relations(workspace, ({one, many}) => ({ + user: one(user, { + fields: [workspace.ownerId], + references: [user.id] + }), + workspaceMembers: many(workspaceMember), + workspaceInvitations: many(workspaceInvitation), + workflows: many(workflow), + knowledgeBases: many(knowledgeBase), + workflowFolders: many(workflowFolder), +})); + +export const workspaceMemberRelations = relations(workspaceMember, ({one}) => ({ + workspace: one(workspace, { + fields: [workspaceMember.workspaceId], + references: [workspace.id] + }), + user: one(user, { + fields: [workspaceMember.userId], + references: [user.id] + }), +})); + +export const workspaceInvitationRelations = relations(workspaceInvitation, ({one}) => ({ + workspace: one(workspace, { + fields: [workspaceInvitation.workspaceId], + references: [workspace.id] + }), + user: one(user, { + fields: [workspaceInvitation.inviterId], + references: [user.id] + }), +})); + +export const userStatsRelations = relations(userStats, ({one}) => ({ + user: one(user, { + fields: [userStats.userId], + references: [user.id] + }), +})); + +export const workflowFolderRelations = relations(workflowFolder, ({one, many}) => ({ + workflows: many(workflow), + user: one(user, { + fields: [workflowFolder.userId], + references: [user.id] + }), + workspace: one(workspace, { + fields: [workflowFolder.workspaceId], + references: [workspace.id] + }), +})); + +export const workflowScheduleRelations = relations(workflowSchedule, ({one}) => ({ + workflow: one(workflow, { + fields: [workflowSchedule.workflowId], + references: [workflow.id] + }), +})); + +export const memoryRelations = relations(memory, ({one}) => ({ + workflow: one(workflow, { + fields: [memory.workflowId], + references: [workflow.id] + }), +})); + +export const knowledgeBaseRelations = relations(knowledgeBase, ({one, many}) => ({ + user: one(user, { + fields: [knowledgeBase.userId], + references: [user.id] + }), + workspace: one(workspace, { + fields: [knowledgeBase.workspaceId], + references: [workspace.id] + }), + documents: many(document), + embeddings: many(embedding), +})); + +export const documentRelations = relations(document, ({one, many}) => ({ + knowledgeBase: one(knowledgeBase, { + fields: [document.knowledgeBaseId], + references: [knowledgeBase.id] + }), + embeddings: many(embedding), +})); + +export const embeddingRelations = relations(embedding, ({one}) => ({ + knowledgeBase: one(knowledgeBase, { + fields: [embedding.knowledgeBaseId], + references: [knowledgeBase.id] + }), + document: one(document, { + fields: [embedding.documentId], + references: [document.id] + }), +})); + +export const workflowBlocksRelations = relations(workflowBlocks, ({one, many}) => ({ + workflow: one(workflow, { + fields: [workflowBlocks.workflowId], + references: [workflow.id] + }), + workflowBlock: one(workflowBlocks, { + fields: [workflowBlocks.parentId], + references: [workflowBlocks.id], + relationName: "workflowBlocks_parentId_workflowBlocks_id" + }), + workflowBlocks: many(workflowBlocks, { + relationName: "workflowBlocks_parentId_workflowBlocks_id" + }), + workflowEdges_sourceBlockId: many(workflowEdges, { + relationName: "workflowEdges_sourceBlockId_workflowBlocks_id" + }), + workflowEdges_targetBlockId: many(workflowEdges, { + relationName: "workflowEdges_targetBlockId_workflowBlocks_id" + }), +})); + +export const workflowEdgesRelations = relations(workflowEdges, ({one}) => ({ + workflow: one(workflow, { + fields: [workflowEdges.workflowId], + references: [workflow.id] + }), + workflowBlock_sourceBlockId: one(workflowBlocks, { + fields: [workflowEdges.sourceBlockId], + references: [workflowBlocks.id], + relationName: "workflowEdges_sourceBlockId_workflowBlocks_id" + }), + workflowBlock_targetBlockId: one(workflowBlocks, { + fields: [workflowEdges.targetBlockId], + references: [workflowBlocks.id], + relationName: "workflowEdges_targetBlockId_workflowBlocks_id" + }), +})); + +export const workflowSubflowsRelations = relations(workflowSubflows, ({one}) => ({ + workflow: one(workflow, { + fields: [workflowSubflows.workflowId], + references: [workflow.id] + }), +})); \ No newline at end of file diff --git a/apps/sim/db/migrations/schema.ts b/apps/sim/db/migrations/schema.ts new file mode 100644 index 00000000000..378352aa9d7 --- /dev/null +++ b/apps/sim/db/migrations/schema.ts @@ -0,0 +1,722 @@ +import { pgTable, text, timestamp, foreignKey, unique, index, serial, json, uniqueIndex, boolean, integer, numeric, jsonb, check, vector } from "drizzle-orm/pg-core" +import { sql } from "drizzle-orm" + + + +export const verification = pgTable("verification", { + id: text().primaryKey().notNull(), + identifier: text().notNull(), + value: text().notNull(), + expiresAt: timestamp("expires_at", { mode: 'string' }).notNull(), + createdAt: timestamp("created_at", { mode: 'string' }), + updatedAt: timestamp("updated_at", { mode: 'string' }), +}); + +export const account = pgTable("account", { + id: text().primaryKey().notNull(), + accountId: text("account_id").notNull(), + providerId: text("provider_id").notNull(), + userId: text("user_id").notNull(), + accessToken: text("access_token"), + refreshToken: text("refresh_token"), + idToken: text("id_token"), + accessTokenExpiresAt: timestamp("access_token_expires_at", { mode: 'string' }), + refreshTokenExpiresAt: timestamp("refresh_token_expires_at", { mode: 'string' }), + scope: text(), + password: text(), + createdAt: timestamp("created_at", { mode: 'string' }).notNull(), + updatedAt: timestamp("updated_at", { mode: 'string' }).notNull(), +}, (table) => [ + foreignKey({ + columns: [table.userId], + foreignColumns: [user.id], + name: "account_user_id_user_id_fk" + }).onDelete("cascade"), +]); + +export const waitlist = pgTable("waitlist", { + id: text().primaryKey().notNull(), + email: text().notNull(), + status: text().default('pending').notNull(), + createdAt: timestamp("created_at", { mode: 'string' }).defaultNow().notNull(), + updatedAt: timestamp("updated_at", { mode: 'string' }).defaultNow().notNull(), +}, (table) => [ + unique("waitlist_email_unique").on(table.email), +]); + +export const workflowBroadcastConnections = pgTable("workflow_broadcast_connections", { + id: serial().primaryKey().notNull(), + userId: text("user_id").notNull(), + workflowId: text("workflow_id").notNull(), + connectionId: text("connection_id").notNull(), + createdAt: timestamp("created_at", { mode: 'string' }).defaultNow(), + lastSeen: timestamp("last_seen", { mode: 'string' }).defaultNow(), +}, (table) => [ + index("idx_workflow_broadcast_connections_user").using("btree", table.userId.asc().nullsLast().op("text_ops")), + index("idx_workflow_broadcast_connections_workflow").using("btree", table.workflowId.asc().nullsLast().op("text_ops")), + foreignKey({ + columns: [table.workflowId], + foreignColumns: [workflow.id], + name: "workflow_broadcast_connections_workflow_id_fkey" + }).onDelete("cascade"), + unique("workflow_broadcast_connections_connection_id_key").on(table.connectionId), +]); + +export const environment = pgTable("environment", { + id: text().primaryKey().notNull(), + userId: text("user_id").notNull(), + variables: json().notNull(), + updatedAt: timestamp("updated_at", { mode: 'string' }).defaultNow().notNull(), +}, (table) => [ + foreignKey({ + columns: [table.userId], + foreignColumns: [user.id], + name: "environment_user_id_user_id_fk" + }).onDelete("cascade"), + unique("environment_user_id_unique").on(table.userId), +]); + +export const webhook = pgTable("webhook", { + id: text().primaryKey().notNull(), + workflowId: text("workflow_id").notNull(), + path: text().notNull(), + provider: text(), + isActive: boolean("is_active").default(true).notNull(), + createdAt: timestamp("created_at", { mode: 'string' }).defaultNow().notNull(), + updatedAt: timestamp("updated_at", { mode: 'string' }).defaultNow().notNull(), + providerConfig: json("provider_config"), +}, (table) => [ + uniqueIndex("path_idx").using("btree", table.path.asc().nullsLast().op("text_ops")), + foreignKey({ + columns: [table.workflowId], + foreignColumns: [workflow.id], + name: "webhook_workflow_id_workflow_id_fk" + }).onDelete("cascade"), +]); + +export const workflowLogs = pgTable("workflow_logs", { + id: text().primaryKey().notNull(), + workflowId: text("workflow_id").notNull(), + executionId: text("execution_id"), + level: text().notNull(), + message: text().notNull(), + createdAt: timestamp("created_at", { mode: 'string' }).defaultNow().notNull(), + duration: text(), + trigger: text(), + metadata: json(), +}, (table) => [ + foreignKey({ + columns: [table.workflowId], + foreignColumns: [workflow.id], + name: "workflow_logs_workflow_id_workflow_id_fk" + }).onDelete("cascade"), +]); + +export const apiKey = pgTable("api_key", { + id: text().primaryKey().notNull(), + userId: text("user_id").notNull(), + name: text().notNull(), + key: text().notNull(), + lastUsed: timestamp("last_used", { mode: 'string' }), + createdAt: timestamp("created_at", { mode: 'string' }).defaultNow().notNull(), + updatedAt: timestamp("updated_at", { mode: 'string' }).defaultNow().notNull(), + expiresAt: timestamp("expires_at", { mode: 'string' }), +}, (table) => [ + foreignKey({ + columns: [table.userId], + foreignColumns: [user.id], + name: "api_key_user_id_user_id_fk" + }).onDelete("cascade"), + unique("api_key_key_unique").on(table.key), +]); + +export const marketplace = pgTable("marketplace", { + id: text().primaryKey().notNull(), + workflowId: text("workflow_id").notNull(), + state: json().notNull(), + name: text().notNull(), + description: text(), + authorId: text("author_id").notNull(), + authorName: text("author_name").notNull(), + views: integer().default(0).notNull(), + category: text(), + createdAt: timestamp("created_at", { mode: 'string' }).defaultNow().notNull(), + updatedAt: timestamp("updated_at", { mode: 'string' }).defaultNow().notNull(), +}, (table) => [ + foreignKey({ + columns: [table.workflowId], + foreignColumns: [workflow.id], + name: "marketplace_workflow_id_workflow_id_fk" + }).onDelete("cascade"), + foreignKey({ + columns: [table.authorId], + foreignColumns: [user.id], + name: "marketplace_author_id_user_id_fk" + }), +]); + +export const customTools = pgTable("custom_tools", { + id: text().primaryKey().notNull(), + userId: text("user_id").notNull(), + title: text().notNull(), + schema: json().notNull(), + code: text().notNull(), + createdAt: timestamp("created_at", { mode: 'string' }).defaultNow().notNull(), + updatedAt: timestamp("updated_at", { mode: 'string' }).defaultNow().notNull(), +}, (table) => [ + foreignKey({ + columns: [table.userId], + foreignColumns: [user.id], + name: "custom_tools_user_id_user_id_fk" + }).onDelete("cascade"), +]); + +export const user = pgTable("user", { + id: text().primaryKey().notNull(), + name: text().notNull(), + email: text().notNull(), + emailVerified: boolean("email_verified").notNull(), + image: text(), + createdAt: timestamp("created_at", { mode: 'string' }).notNull(), + updatedAt: timestamp("updated_at", { mode: 'string' }).notNull(), + stripeCustomerId: text("stripe_customer_id"), +}, (table) => [ + unique("user_email_unique").on(table.email), +]); + +export const session = pgTable("session", { + id: text().primaryKey().notNull(), + expiresAt: timestamp("expires_at", { mode: 'string' }).notNull(), + token: text().notNull(), + createdAt: timestamp("created_at", { mode: 'string' }).notNull(), + updatedAt: timestamp("updated_at", { mode: 'string' }).notNull(), + ipAddress: text("ip_address"), + userAgent: text("user_agent"), + userId: text("user_id").notNull(), + activeOrganizationId: text("active_organization_id"), +}, (table) => [ + foreignKey({ + columns: [table.userId], + foreignColumns: [user.id], + name: "session_user_id_user_id_fk" + }).onDelete("cascade"), + foreignKey({ + columns: [table.activeOrganizationId], + foreignColumns: [organization.id], + name: "session_active_organization_id_organization_id_fk" + }).onDelete("set null"), + unique("session_token_unique").on(table.token), +]); + +export const invitation = pgTable("invitation", { + id: text().primaryKey().notNull(), + email: text().notNull(), + inviterId: text("inviter_id").notNull(), + organizationId: text("organization_id").notNull(), + role: text().notNull(), + status: text().notNull(), + expiresAt: timestamp("expires_at", { mode: 'string' }).notNull(), + createdAt: timestamp("created_at", { mode: 'string' }).defaultNow().notNull(), +}, (table) => [ + foreignKey({ + columns: [table.inviterId], + foreignColumns: [user.id], + name: "invitation_inviter_id_user_id_fk" + }).onDelete("cascade"), + foreignKey({ + columns: [table.organizationId], + foreignColumns: [organization.id], + name: "invitation_organization_id_organization_id_fk" + }).onDelete("cascade"), +]); + +export const member = pgTable("member", { + id: text().primaryKey().notNull(), + userId: text("user_id").notNull(), + organizationId: text("organization_id").notNull(), + role: text().notNull(), + createdAt: timestamp("created_at", { mode: 'string' }).defaultNow().notNull(), +}, (table) => [ + foreignKey({ + columns: [table.userId], + foreignColumns: [user.id], + name: "member_user_id_user_id_fk" + }).onDelete("cascade"), + foreignKey({ + columns: [table.organizationId], + foreignColumns: [organization.id], + name: "member_organization_id_organization_id_fk" + }).onDelete("cascade"), +]); + +export const chat = pgTable("chat", { + id: text().primaryKey().notNull(), + workflowId: text("workflow_id").notNull(), + userId: text("user_id").notNull(), + subdomain: text().notNull(), + title: text().notNull(), + description: text(), + isActive: boolean("is_active").default(true).notNull(), + customizations: json().default({}), + authType: text("auth_type").default('public').notNull(), + password: text(), + allowedEmails: json("allowed_emails").default([]), + createdAt: timestamp("created_at", { mode: 'string' }).defaultNow().notNull(), + updatedAt: timestamp("updated_at", { mode: 'string' }).defaultNow().notNull(), + outputConfigs: json("output_configs").default([]), +}, (table) => [ + uniqueIndex("subdomain_idx").using("btree", table.subdomain.asc().nullsLast().op("text_ops")), + foreignKey({ + columns: [table.workflowId], + foreignColumns: [workflow.id], + name: "chat_workflow_id_workflow_id_fk" + }).onDelete("cascade"), + foreignKey({ + columns: [table.userId], + foreignColumns: [user.id], + name: "chat_user_id_user_id_fk" + }).onDelete("cascade"), +]); + +export const settings = pgTable("settings", { + id: text().primaryKey().notNull(), + userId: text("user_id").notNull(), + general: json().default({}).notNull(), + updatedAt: timestamp("updated_at", { mode: 'string' }).defaultNow().notNull(), + theme: text().default('system').notNull(), + debugMode: boolean("debug_mode").default(false).notNull(), + autoConnect: boolean("auto_connect").default(true).notNull(), + autoFillEnvVars: boolean("auto_fill_env_vars").default(true).notNull(), + telemetryEnabled: boolean("telemetry_enabled").default(true).notNull(), + telemetryNotifiedUser: boolean("telemetry_notified_user").default(false).notNull(), + emailPreferences: json("email_preferences").default({}).notNull(), +}, (table) => [ + foreignKey({ + columns: [table.userId], + foreignColumns: [user.id], + name: "settings_user_id_user_id_fk" + }).onDelete("cascade"), + unique("settings_user_id_unique").on(table.userId), +]); + +export const workspace = pgTable("workspace", { + id: text().primaryKey().notNull(), + name: text().notNull(), + ownerId: text("owner_id").notNull(), + createdAt: timestamp("created_at", { mode: 'string' }).defaultNow().notNull(), + updatedAt: timestamp("updated_at", { mode: 'string' }).defaultNow().notNull(), +}, (table) => [ + foreignKey({ + columns: [table.ownerId], + foreignColumns: [user.id], + name: "workspace_owner_id_user_id_fk" + }).onDelete("cascade"), +]); + +export const workspaceMember = pgTable("workspace_member", { + id: text().primaryKey().notNull(), + workspaceId: text("workspace_id").notNull(), + userId: text("user_id").notNull(), + role: text().default('member').notNull(), + joinedAt: timestamp("joined_at", { mode: 'string' }).defaultNow().notNull(), + updatedAt: timestamp("updated_at", { mode: 'string' }).defaultNow().notNull(), +}, (table) => [ + uniqueIndex("user_workspace_idx").using("btree", table.userId.asc().nullsLast().op("text_ops"), table.workspaceId.asc().nullsLast().op("text_ops")), + foreignKey({ + columns: [table.workspaceId], + foreignColumns: [workspace.id], + name: "workspace_member_workspace_id_workspace_id_fk" + }).onDelete("cascade"), + foreignKey({ + columns: [table.userId], + foreignColumns: [user.id], + name: "workspace_member_user_id_user_id_fk" + }).onDelete("cascade"), +]); + +export const workspaceInvitation = pgTable("workspace_invitation", { + id: text().primaryKey().notNull(), + workspaceId: text("workspace_id").notNull(), + email: text().notNull(), + inviterId: text("inviter_id").notNull(), + role: text().default('member').notNull(), + status: text().default('pending').notNull(), + token: text().notNull(), + expiresAt: timestamp("expires_at", { mode: 'string' }).notNull(), + createdAt: timestamp("created_at", { mode: 'string' }).defaultNow().notNull(), + updatedAt: timestamp("updated_at", { mode: 'string' }).defaultNow().notNull(), +}, (table) => [ + foreignKey({ + columns: [table.workspaceId], + foreignColumns: [workspace.id], + name: "workspace_invitation_workspace_id_workspace_id_fk" + }).onDelete("cascade"), + foreignKey({ + columns: [table.inviterId], + foreignColumns: [user.id], + name: "workspace_invitation_inviter_id_user_id_fk" + }).onDelete("cascade"), + unique("workspace_invitation_token_unique").on(table.token), +]); + +export const organization = pgTable("organization", { + id: text().primaryKey().notNull(), + name: text().notNull(), + slug: text().notNull(), + logo: text(), + metadata: json(), + createdAt: timestamp("created_at", { mode: 'string' }).defaultNow().notNull(), + updatedAt: timestamp("updated_at", { mode: 'string' }).defaultNow().notNull(), +}); + +export const subscription = pgTable("subscription", { + id: text().primaryKey().notNull(), + plan: text().notNull(), + referenceId: text("reference_id").notNull(), + stripeCustomerId: text("stripe_customer_id"), + stripeSubscriptionId: text("stripe_subscription_id"), + status: text(), + periodStart: timestamp("period_start", { mode: 'string' }), + periodEnd: timestamp("period_end", { mode: 'string' }), + cancelAtPeriodEnd: boolean("cancel_at_period_end"), + seats: integer(), + trialStart: timestamp("trial_start", { mode: 'string' }), + trialEnd: timestamp("trial_end", { mode: 'string' }), + metadata: json(), +}); + +export const userStats = pgTable("user_stats", { + id: text().primaryKey().notNull(), + userId: text("user_id").notNull(), + totalManualExecutions: integer("total_manual_executions").default(0).notNull(), + totalApiCalls: integer("total_api_calls").default(0).notNull(), + totalWebhookTriggers: integer("total_webhook_triggers").default(0).notNull(), + totalScheduledExecutions: integer("total_scheduled_executions").default(0).notNull(), + totalTokensUsed: integer("total_tokens_used").default(0).notNull(), + totalCost: numeric("total_cost").default('0').notNull(), + lastActive: timestamp("last_active", { mode: 'string' }).defaultNow().notNull(), + totalChatExecutions: integer("total_chat_executions").default(0).notNull(), +}, (table) => [ + foreignKey({ + columns: [table.userId], + foreignColumns: [user.id], + name: "user_stats_user_id_user_id_fk" + }).onDelete("cascade"), + unique("user_stats_user_id_unique").on(table.userId), +]); + +export const workflow = pgTable("workflow", { + id: text().primaryKey().notNull(), + userId: text("user_id").notNull(), + name: text().notNull(), + description: text(), + state: json().notNull(), + lastSynced: timestamp("last_synced", { mode: 'string' }).notNull(), + createdAt: timestamp("created_at", { mode: 'string' }).notNull(), + updatedAt: timestamp("updated_at", { mode: 'string' }).notNull(), + isDeployed: boolean("is_deployed").default(false).notNull(), + deployedAt: timestamp("deployed_at", { mode: 'string' }), + color: text().default('#3972F6').notNull(), + collaborators: json().default([]).notNull(), + isPublished: boolean("is_published").default(false).notNull(), + runCount: integer("run_count").default(0).notNull(), + lastRunAt: timestamp("last_run_at", { mode: 'string' }), + variables: json().default({}), + marketplaceData: json("marketplace_data"), + deployedHash: text("deployed_hash"), + workspaceId: text("workspace_id"), + folderId: text("folder_id"), + deployedState: json("deployed_state"), + lastSaved: timestamp("last_saved", { mode: 'string' }), + deploymentStatuses: jsonb("deployment_statuses").default({}), + hasActiveSchedule: boolean("has_active_schedule").default(false), + hasActiveWebhook: boolean("has_active_webhook").default(false), +}, (table) => [ + foreignKey({ + columns: [table.userId], + foreignColumns: [user.id], + name: "workflow_user_id_user_id_fk" + }).onDelete("cascade"), + foreignKey({ + columns: [table.workspaceId], + foreignColumns: [workspace.id], + name: "workflow_workspace_id_workspace_id_fk" + }).onDelete("cascade"), + foreignKey({ + columns: [table.folderId], + foreignColumns: [workflowFolder.id], + name: "workflow_folder_id_workflow_folder_id_fk" + }).onDelete("set null"), +]); + +export const workflowSchedule = pgTable("workflow_schedule", { + id: text().primaryKey().notNull(), + workflowId: text("workflow_id").notNull(), + cronExpression: text("cron_expression"), + nextRunAt: timestamp("next_run_at", { mode: 'string' }), + lastRanAt: timestamp("last_ran_at", { mode: 'string' }), + triggerType: text("trigger_type").notNull(), + timezone: text().default('UTC').notNull(), + createdAt: timestamp("created_at", { mode: 'string' }).defaultNow().notNull(), + updatedAt: timestamp("updated_at", { mode: 'string' }).defaultNow().notNull(), + failedCount: integer("failed_count").default(0).notNull(), + status: text().default('active').notNull(), + lastFailedAt: timestamp("last_failed_at", { mode: 'string' }), +}, (table) => [ + foreignKey({ + columns: [table.workflowId], + foreignColumns: [workflow.id], + name: "workflow_schedule_workflow_id_workflow_id_fk" + }).onDelete("cascade"), + unique("workflow_schedule_workflow_id_unique").on(table.workflowId), +]); + +export const memory = pgTable("memory", { + id: text().primaryKey().notNull(), + workflowId: text("workflow_id"), + key: text().notNull(), + type: text().notNull(), + data: json().notNull(), + createdAt: timestamp("created_at", { mode: 'string' }).defaultNow().notNull(), + updatedAt: timestamp("updated_at", { mode: 'string' }).defaultNow().notNull(), + deletedAt: timestamp("deleted_at", { mode: 'string' }), +}, (table) => [ + index("memory_key_idx").using("btree", table.key.asc().nullsLast().op("text_ops")), + index("memory_workflow_idx").using("btree", table.workflowId.asc().nullsLast().op("text_ops")), + uniqueIndex("memory_workflow_key_idx").using("btree", table.workflowId.asc().nullsLast().op("text_ops"), table.key.asc().nullsLast().op("text_ops")), + foreignKey({ + columns: [table.workflowId], + foreignColumns: [workflow.id], + name: "memory_workflow_id_workflow_id_fk" + }).onDelete("cascade"), +]); + +export const knowledgeBase = pgTable("knowledge_base", { + id: text().primaryKey().notNull(), + userId: text("user_id").notNull(), + workspaceId: text("workspace_id"), + name: text().notNull(), + description: text(), + tokenCount: integer("token_count").default(0).notNull(), + embeddingModel: text("embedding_model").default('text-embedding-3-small').notNull(), + embeddingDimension: integer("embedding_dimension").default(1536).notNull(), + chunkingConfig: json("chunking_config").default({"maxSize":1024,"minSize":100,"overlap":200}).notNull(), + deletedAt: timestamp("deleted_at", { mode: 'string' }), + createdAt: timestamp("created_at", { mode: 'string' }).defaultNow().notNull(), + updatedAt: timestamp("updated_at", { mode: 'string' }).defaultNow().notNull(), +}, (table) => [ + index("kb_deleted_at_idx").using("btree", table.deletedAt.asc().nullsLast().op("timestamp_ops")), + index("kb_user_id_idx").using("btree", table.userId.asc().nullsLast().op("text_ops")), + index("kb_user_workspace_idx").using("btree", table.userId.asc().nullsLast().op("text_ops"), table.workspaceId.asc().nullsLast().op("text_ops")), + index("kb_workspace_id_idx").using("btree", table.workspaceId.asc().nullsLast().op("text_ops")), + foreignKey({ + columns: [table.userId], + foreignColumns: [user.id], + name: "knowledge_base_user_id_user_id_fk" + }).onDelete("cascade"), + foreignKey({ + columns: [table.workspaceId], + foreignColumns: [workspace.id], + name: "knowledge_base_workspace_id_workspace_id_fk" + }).onDelete("cascade"), +]); + +export const document = pgTable("document", { + id: text().primaryKey().notNull(), + knowledgeBaseId: text("knowledge_base_id").notNull(), + filename: text().notNull(), + fileUrl: text("file_url").notNull(), + fileSize: integer("file_size").notNull(), + mimeType: text("mime_type").notNull(), + fileHash: text("file_hash"), + chunkCount: integer("chunk_count").default(0).notNull(), + tokenCount: integer("token_count").default(0).notNull(), + characterCount: integer("character_count").default(0).notNull(), + enabled: boolean().default(true).notNull(), + deletedAt: timestamp("deleted_at", { mode: 'string' }), + uploadedAt: timestamp("uploaded_at", { mode: 'string' }).defaultNow().notNull(), + processingStatus: text("processing_status").default('pending').notNull(), + processingStartedAt: timestamp("processing_started_at", { mode: 'string' }), + processingCompletedAt: timestamp("processing_completed_at", { mode: 'string' }), + processingError: text("processing_error"), +}, (table) => [ + index("doc_file_hash_idx").using("btree", table.fileHash.asc().nullsLast().op("text_ops")), + index("doc_filename_idx").using("btree", table.filename.asc().nullsLast().op("text_ops")), + index("doc_kb_id_idx").using("btree", table.knowledgeBaseId.asc().nullsLast().op("text_ops")), + index("doc_kb_uploaded_at_idx").using("btree", table.knowledgeBaseId.asc().nullsLast().op("timestamp_ops"), table.uploadedAt.asc().nullsLast().op("timestamp_ops")), + index("doc_processing_status_idx").using("btree", table.knowledgeBaseId.asc().nullsLast().op("text_ops"), table.processingStatus.asc().nullsLast().op("text_ops")), + foreignKey({ + columns: [table.knowledgeBaseId], + foreignColumns: [knowledgeBase.id], + name: "document_knowledge_base_id_knowledge_base_id_fk" + }).onDelete("cascade"), +]); + +export const workflowFolder = pgTable("workflow_folder", { + id: text().primaryKey().notNull(), + name: text().notNull(), + userId: text("user_id").notNull(), + workspaceId: text("workspace_id").notNull(), + parentId: text("parent_id"), + color: text().default('#6B7280'), + isExpanded: boolean("is_expanded").default(true).notNull(), + sortOrder: integer("sort_order").default(0).notNull(), + createdAt: timestamp("created_at", { mode: 'string' }).defaultNow().notNull(), + updatedAt: timestamp("updated_at", { mode: 'string' }).defaultNow().notNull(), +}, (table) => [ + index("workflow_folder_parent_sort_idx").using("btree", table.parentId.asc().nullsLast().op("int4_ops"), table.sortOrder.asc().nullsLast().op("text_ops")), + index("workflow_folder_user_idx").using("btree", table.userId.asc().nullsLast().op("text_ops")), + index("workflow_folder_workspace_parent_idx").using("btree", table.workspaceId.asc().nullsLast().op("text_ops"), table.parentId.asc().nullsLast().op("text_ops")), + foreignKey({ + columns: [table.userId], + foreignColumns: [user.id], + name: "workflow_folder_user_id_user_id_fk" + }).onDelete("cascade"), + foreignKey({ + columns: [table.workspaceId], + foreignColumns: [workspace.id], + name: "workflow_folder_workspace_id_workspace_id_fk" + }).onDelete("cascade"), +]); + +export const embedding = pgTable("embedding", { + id: text().primaryKey().notNull(), + knowledgeBaseId: text("knowledge_base_id").notNull(), + documentId: text("document_id").notNull(), + chunkIndex: integer("chunk_index").notNull(), + chunkHash: text("chunk_hash").notNull(), + content: text().notNull(), + contentLength: integer("content_length").notNull(), + tokenCount: integer("token_count").notNull(), + embedding: vector({ dimensions: 1536 }), + embeddingModel: text("embedding_model").default('text-embedding-3-small').notNull(), + startOffset: integer("start_offset").notNull(), + endOffset: integer("end_offset").notNull(), + overlapTokens: integer("overlap_tokens").default(0).notNull(), + metadata: jsonb().default({}).notNull(), + searchRank: numeric("search_rank").default('1.0'), + accessCount: integer("access_count").default(0).notNull(), + lastAccessedAt: timestamp("last_accessed_at", { mode: 'string' }), + qualityScore: numeric("quality_score"), + createdAt: timestamp("created_at", { mode: 'string' }).defaultNow().notNull(), + updatedAt: timestamp("updated_at", { mode: 'string' }).defaultNow().notNull(), + // TODO: failed to parse database type 'tsvector' + contentTsv: unknown("content_tsv").generatedAlwaysAs(sql`to_tsvector('english'::regconfig, content)`), + enabled: boolean().default(true).notNull(), +}, (table) => [ + index("emb_chunk_hash_idx").using("btree", table.chunkHash.asc().nullsLast().op("text_ops")), + index("emb_content_fts_idx").using("gin", table.contentTsv.asc().nullsLast().op("tsvector_ops")), + uniqueIndex("emb_doc_chunk_idx").using("btree", table.documentId.asc().nullsLast().op("int4_ops"), table.chunkIndex.asc().nullsLast().op("int4_ops")), + index("emb_doc_enabled_idx").using("btree", table.documentId.asc().nullsLast().op("text_ops"), table.enabled.asc().nullsLast().op("bool_ops")), + index("emb_doc_id_idx").using("btree", table.documentId.asc().nullsLast().op("text_ops")), + index("emb_kb_access_idx").using("btree", table.knowledgeBaseId.asc().nullsLast().op("timestamp_ops"), table.lastAccessedAt.asc().nullsLast().op("text_ops")), + index("emb_kb_enabled_idx").using("btree", table.knowledgeBaseId.asc().nullsLast().op("bool_ops"), table.enabled.asc().nullsLast().op("bool_ops")), + index("emb_kb_id_idx").using("btree", table.knowledgeBaseId.asc().nullsLast().op("text_ops")), + index("emb_kb_model_idx").using("btree", table.knowledgeBaseId.asc().nullsLast().op("text_ops"), table.embeddingModel.asc().nullsLast().op("text_ops")), + index("emb_kb_rank_idx").using("btree", table.knowledgeBaseId.asc().nullsLast().op("text_ops"), table.searchRank.asc().nullsLast().op("text_ops")), + index("emb_metadata_gin_idx").using("gin", table.metadata.asc().nullsLast().op("jsonb_ops")), + index("embedding_vector_hnsw_idx").using("hnsw", table.embedding.asc().nullsLast().op("vector_cosine_ops")).with({m: "16",ef_construction: "64"}), + foreignKey({ + columns: [table.knowledgeBaseId], + foreignColumns: [knowledgeBase.id], + name: "embedding_knowledge_base_id_knowledge_base_id_fk" + }).onDelete("cascade"), + foreignKey({ + columns: [table.documentId], + foreignColumns: [document.id], + name: "embedding_document_id_document_id_fk" + }).onDelete("cascade"), + check("embedding_not_null_check", sql`embedding IS NOT NULL`), +]); + +export const workflowBlocks = pgTable("workflow_blocks", { + id: text().primaryKey().notNull(), + workflowId: text("workflow_id").notNull(), + type: text().notNull(), + name: text().notNull(), + positionX: integer("position_x").notNull(), + positionY: integer("position_y").notNull(), + enabled: boolean().default(true).notNull(), + horizontalHandles: boolean("horizontal_handles").default(true).notNull(), + isWide: boolean("is_wide").default(false).notNull(), + height: integer().default(0).notNull(), + subBlocks: jsonb("sub_blocks").default({}).notNull(), + outputs: jsonb().default({}).notNull(), + data: jsonb().default({}), + parentId: text("parent_id"), + extent: text(), + createdAt: timestamp("created_at", { mode: 'string' }).defaultNow().notNull(), + updatedAt: timestamp("updated_at", { mode: 'string' }).defaultNow().notNull(), + deployHash: text("deploy_hash"), +}, (table) => [ + index("workflow_blocks_deploy_hash_idx").using("btree", table.deployHash.asc().nullsLast().op("text_ops")), + index("workflow_blocks_parent_id_idx").using("btree", table.parentId.asc().nullsLast().op("text_ops")), + index("workflow_blocks_workflow_deploy_idx").using("btree", table.workflowId.asc().nullsLast().op("text_ops"), table.deployHash.asc().nullsLast().op("text_ops")), + index("workflow_blocks_workflow_id_idx").using("btree", table.workflowId.asc().nullsLast().op("text_ops")), + index("workflow_blocks_workflow_parent_idx").using("btree", table.workflowId.asc().nullsLast().op("text_ops"), table.parentId.asc().nullsLast().op("text_ops")), + index("workflow_blocks_workflow_type_idx").using("btree", table.workflowId.asc().nullsLast().op("text_ops"), table.type.asc().nullsLast().op("text_ops")), + foreignKey({ + columns: [table.workflowId], + foreignColumns: [workflow.id], + name: "workflow_blocks_workflow_id_workflow_id_fk" + }).onDelete("cascade"), + foreignKey({ + columns: [table.parentId], + foreignColumns: [table.id], + name: "workflow_blocks_parent_id_workflow_blocks_id_fk" + }).onDelete("cascade"), +]); + +export const workflowEdges = pgTable("workflow_edges", { + id: text().primaryKey().notNull(), + workflowId: text("workflow_id").notNull(), + sourceBlockId: text("source_block_id").notNull(), + targetBlockId: text("target_block_id").notNull(), + sourceHandle: text("source_handle"), + targetHandle: text("target_handle"), + createdAt: timestamp("created_at", { mode: 'string' }).defaultNow().notNull(), + deployHash: text("deploy_hash"), +}, (table) => [ + index("workflow_edges_deploy_hash_idx").using("btree", table.deployHash.asc().nullsLast().op("text_ops")), + index("workflow_edges_source_block_idx").using("btree", table.sourceBlockId.asc().nullsLast().op("text_ops")), + index("workflow_edges_target_block_idx").using("btree", table.targetBlockId.asc().nullsLast().op("text_ops")), + index("workflow_edges_workflow_deploy_idx").using("btree", table.workflowId.asc().nullsLast().op("text_ops"), table.deployHash.asc().nullsLast().op("text_ops")), + index("workflow_edges_workflow_id_idx").using("btree", table.workflowId.asc().nullsLast().op("text_ops")), + index("workflow_edges_workflow_source_idx").using("btree", table.workflowId.asc().nullsLast().op("text_ops"), table.sourceBlockId.asc().nullsLast().op("text_ops")), + index("workflow_edges_workflow_target_idx").using("btree", table.workflowId.asc().nullsLast().op("text_ops"), table.targetBlockId.asc().nullsLast().op("text_ops")), + foreignKey({ + columns: [table.workflowId], + foreignColumns: [workflow.id], + name: "workflow_edges_workflow_id_workflow_id_fk" + }).onDelete("cascade"), + foreignKey({ + columns: [table.sourceBlockId], + foreignColumns: [workflowBlocks.id], + name: "workflow_edges_source_block_id_workflow_blocks_id_fk" + }).onDelete("cascade"), + foreignKey({ + columns: [table.targetBlockId], + foreignColumns: [workflowBlocks.id], + name: "workflow_edges_target_block_id_workflow_blocks_id_fk" + }).onDelete("cascade"), +]); + +export const workflowSubflows = pgTable("workflow_subflows", { + id: text().primaryKey().notNull(), + workflowId: text("workflow_id").notNull(), + type: text().notNull(), + config: jsonb().default({}).notNull(), + createdAt: timestamp("created_at", { mode: 'string' }).defaultNow().notNull(), + updatedAt: timestamp("updated_at", { mode: 'string' }).defaultNow().notNull(), + deployHash: text("deploy_hash"), +}, (table) => [ + index("workflow_subflows_deploy_hash_idx").using("btree", table.deployHash.asc().nullsLast().op("text_ops")), + index("workflow_subflows_workflow_deploy_idx").using("btree", table.workflowId.asc().nullsLast().op("text_ops"), table.deployHash.asc().nullsLast().op("text_ops")), + index("workflow_subflows_workflow_id_idx").using("btree", table.workflowId.asc().nullsLast().op("text_ops")), + index("workflow_subflows_workflow_type_idx").using("btree", table.workflowId.asc().nullsLast().op("text_ops"), table.type.asc().nullsLast().op("text_ops")), + foreignKey({ + columns: [table.workflowId], + foreignColumns: [workflow.id], + name: "workflow_subflows_workflow_id_workflow_id_fk" + }).onDelete("cascade"), +]); diff --git a/apps/sim/db/schema.ts b/apps/sim/db/schema.ts index 030de3cc93f..e76c9054a2c 100644 --- a/apps/sim/db/schema.ts +++ b/apps/sim/db/schema.ts @@ -146,14 +146,14 @@ export const workflowBlocks = pgTable( name: text('name').notNull(), // Display name of the block // Position coordinates (from position.x, position.y) - positionX: integer('position_x').notNull(), // X coordinate on canvas - positionY: integer('position_y').notNull(), // Y coordinate on canvas + positionX: decimal('position_x').notNull(), // X coordinate on canvas + positionY: decimal('position_y').notNull(), // Y coordinate on canvas // Block behavior flags (from current BlockState) enabled: boolean('enabled').notNull().default(true), // Whether block is active horizontalHandles: boolean('horizontal_handles').notNull().default(true), // UI layout preference isWide: boolean('is_wide').notNull().default(false), // Whether block uses wide layout - height: integer('height').notNull().default(0), // Custom height override + height: decimal('height').notNull().default('0'), // Custom height override // Block data (keeping JSON for flexibility as current system does) subBlocks: jsonb('sub_blocks').notNull().default('{}'), // All subblock configurations diff --git a/apps/sim/lib/workflows/db-helpers.ts b/apps/sim/lib/workflows/db-helpers.ts index fb4d7a59044..03f98bbc44e 100644 --- a/apps/sim/lib/workflows/db-helpers.ts +++ b/apps/sim/lib/workflows/db-helpers.ts @@ -131,8 +131,8 @@ export async function saveWorkflowToNormalizedTables( workflowId: workflowId, type: block.type, name: block.name || '', - positionX: Math.round(block.position?.x || 0), - positionY: Math.round(block.position?.y || 0), + positionX: block.position?.x || 0, + positionY: block.position?.y || 0, enabled: block.enabled ?? true, horizontalHandles: block.horizontalHandles ?? true, isWide: block.isWide ?? false, From 5009217f54426603d8a9bc23e6741ad5b2475b9b Mon Sep 17 00:00:00 2001 From: Vikhyath Mondreti Date: Thu, 19 Jun 2025 15:01:56 -0700 Subject: [PATCH 2/2] remove unused files --- .../sim/db/migrations/meta/0044_snapshot.json | 358 +++------ apps/sim/db/migrations/meta/_journal.json | 2 +- apps/sim/db/migrations/relations.ts | 308 -------- apps/sim/db/migrations/schema.ts | 722 ------------------ 4 files changed, 91 insertions(+), 1299 deletions(-) delete mode 100644 apps/sim/db/migrations/relations.ts delete mode 100644 apps/sim/db/migrations/schema.ts diff --git a/apps/sim/db/migrations/meta/0044_snapshot.json b/apps/sim/db/migrations/meta/0044_snapshot.json index 414d83ef78b..b61554aa4de 100644 --- a/apps/sim/db/migrations/meta/0044_snapshot.json +++ b/apps/sim/db/migrations/meta/0044_snapshot.json @@ -93,12 +93,8 @@ "name": "account_user_id_user_id_fk", "tableFrom": "account", "tableTo": "user", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], + "columnsFrom": ["user_id"], + "columnsTo": ["id"], "onDelete": "cascade", "onUpdate": "no action" } @@ -170,12 +166,8 @@ "name": "api_key_user_id_user_id_fk", "tableFrom": "api_key", "tableTo": "user", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], + "columnsFrom": ["user_id"], + "columnsTo": ["id"], "onDelete": "cascade", "onUpdate": "no action" } @@ -185,9 +177,7 @@ "api_key_key_unique": { "name": "api_key_key_unique", "nullsNotDistinct": false, - "columns": [ - "key" - ] + "columns": ["key"] } }, "policies": {}, @@ -312,12 +302,8 @@ "name": "chat_workflow_id_workflow_id_fk", "tableFrom": "chat", "tableTo": "workflow", - "columnsFrom": [ - "workflow_id" - ], - "columnsTo": [ - "id" - ], + "columnsFrom": ["workflow_id"], + "columnsTo": ["id"], "onDelete": "cascade", "onUpdate": "no action" }, @@ -325,12 +311,8 @@ "name": "chat_user_id_user_id_fk", "tableFrom": "chat", "tableTo": "user", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], + "columnsFrom": ["user_id"], + "columnsTo": ["id"], "onDelete": "cascade", "onUpdate": "no action" } @@ -396,12 +378,8 @@ "name": "custom_tools_user_id_user_id_fk", "tableFrom": "custom_tools", "tableTo": "user", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], + "columnsFrom": ["user_id"], + "columnsTo": ["id"], "onDelete": "cascade", "onUpdate": "no action" } @@ -619,12 +597,8 @@ "name": "document_knowledge_base_id_knowledge_base_id_fk", "tableFrom": "document", "tableTo": "knowledge_base", - "columnsFrom": [ - "knowledge_base_id" - ], - "columnsTo": [ - "id" - ], + "columnsFrom": ["knowledge_base_id"], + "columnsTo": ["id"], "onDelete": "cascade", "onUpdate": "no action" } @@ -1011,12 +985,8 @@ "name": "embedding_knowledge_base_id_knowledge_base_id_fk", "tableFrom": "embedding", "tableTo": "knowledge_base", - "columnsFrom": [ - "knowledge_base_id" - ], - "columnsTo": [ - "id" - ], + "columnsFrom": ["knowledge_base_id"], + "columnsTo": ["id"], "onDelete": "cascade", "onUpdate": "no action" }, @@ -1024,12 +994,8 @@ "name": "embedding_document_id_document_id_fk", "tableFrom": "embedding", "tableTo": "document", - "columnsFrom": [ - "document_id" - ], - "columnsTo": [ - "id" - ], + "columnsFrom": ["document_id"], + "columnsTo": ["id"], "onDelete": "cascade", "onUpdate": "no action" } @@ -1081,12 +1047,8 @@ "name": "environment_user_id_user_id_fk", "tableFrom": "environment", "tableTo": "user", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], + "columnsFrom": ["user_id"], + "columnsTo": ["id"], "onDelete": "cascade", "onUpdate": "no action" } @@ -1096,9 +1058,7 @@ "environment_user_id_unique": { "name": "environment_user_id_unique", "nullsNotDistinct": false, - "columns": [ - "user_id" - ] + "columns": ["user_id"] } }, "policies": {}, @@ -1165,12 +1125,8 @@ "name": "invitation_inviter_id_user_id_fk", "tableFrom": "invitation", "tableTo": "user", - "columnsFrom": [ - "inviter_id" - ], - "columnsTo": [ - "id" - ], + "columnsFrom": ["inviter_id"], + "columnsTo": ["id"], "onDelete": "cascade", "onUpdate": "no action" }, @@ -1178,12 +1134,8 @@ "name": "invitation_organization_id_organization_id_fk", "tableFrom": "invitation", "tableTo": "organization", - "columnsFrom": [ - "organization_id" - ], - "columnsTo": [ - "id" - ], + "columnsFrom": ["organization_id"], + "columnsTo": ["id"], "onDelete": "cascade", "onUpdate": "no action" } @@ -1350,12 +1302,8 @@ "name": "knowledge_base_user_id_user_id_fk", "tableFrom": "knowledge_base", "tableTo": "user", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], + "columnsFrom": ["user_id"], + "columnsTo": ["id"], "onDelete": "cascade", "onUpdate": "no action" }, @@ -1363,12 +1311,8 @@ "name": "knowledge_base_workspace_id_workspace_id_fk", "tableFrom": "knowledge_base", "tableTo": "workspace", - "columnsFrom": [ - "workspace_id" - ], - "columnsTo": [ - "id" - ], + "columnsFrom": ["workspace_id"], + "columnsTo": ["id"], "onDelete": "cascade", "onUpdate": "no action" } @@ -1459,12 +1403,8 @@ "name": "marketplace_workflow_id_workflow_id_fk", "tableFrom": "marketplace", "tableTo": "workflow", - "columnsFrom": [ - "workflow_id" - ], - "columnsTo": [ - "id" - ], + "columnsFrom": ["workflow_id"], + "columnsTo": ["id"], "onDelete": "cascade", "onUpdate": "no action" }, @@ -1472,12 +1412,8 @@ "name": "marketplace_author_id_user_id_fk", "tableFrom": "marketplace", "tableTo": "user", - "columnsFrom": [ - "author_id" - ], - "columnsTo": [ - "id" - ], + "columnsFrom": ["author_id"], + "columnsTo": ["id"], "onDelete": "no action", "onUpdate": "no action" } @@ -1530,12 +1466,8 @@ "name": "member_user_id_user_id_fk", "tableFrom": "member", "tableTo": "user", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], + "columnsFrom": ["user_id"], + "columnsTo": ["id"], "onDelete": "cascade", "onUpdate": "no action" }, @@ -1543,12 +1475,8 @@ "name": "member_organization_id_organization_id_fk", "tableFrom": "member", "tableTo": "organization", - "columnsFrom": [ - "organization_id" - ], - "columnsTo": [ - "id" - ], + "columnsFrom": ["organization_id"], + "columnsTo": ["id"], "onDelete": "cascade", "onUpdate": "no action" } @@ -1672,12 +1600,8 @@ "name": "memory_workflow_id_workflow_id_fk", "tableFrom": "memory", "tableTo": "workflow", - "columnsFrom": [ - "workflow_id" - ], - "columnsTo": [ - "id" - ], + "columnsFrom": ["workflow_id"], + "columnsTo": ["id"], "onDelete": "cascade", "onUpdate": "no action" } @@ -1810,12 +1734,8 @@ "name": "session_user_id_user_id_fk", "tableFrom": "session", "tableTo": "user", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], + "columnsFrom": ["user_id"], + "columnsTo": ["id"], "onDelete": "cascade", "onUpdate": "no action" }, @@ -1823,12 +1743,8 @@ "name": "session_active_organization_id_organization_id_fk", "tableFrom": "session", "tableTo": "organization", - "columnsFrom": [ - "active_organization_id" - ], - "columnsTo": [ - "id" - ], + "columnsFrom": ["active_organization_id"], + "columnsTo": ["id"], "onDelete": "set null", "onUpdate": "no action" } @@ -1838,9 +1754,7 @@ "session_token_unique": { "name": "session_token_unique", "nullsNotDistinct": false, - "columns": [ - "token" - ] + "columns": ["token"] } }, "policies": {}, @@ -1933,12 +1847,8 @@ "name": "settings_user_id_user_id_fk", "tableFrom": "settings", "tableTo": "user", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], + "columnsFrom": ["user_id"], + "columnsTo": ["id"], "onDelete": "cascade", "onUpdate": "no action" } @@ -1948,9 +1858,7 @@ "settings_user_id_unique": { "name": "settings_user_id_unique", "nullsNotDistinct": false, - "columns": [ - "user_id" - ] + "columns": ["user_id"] } }, "policies": {}, @@ -2108,9 +2016,7 @@ "user_email_unique": { "name": "user_email_unique", "nullsNotDistinct": false, - "columns": [ - "email" - ] + "columns": ["email"] } }, "policies": {}, @@ -2196,12 +2102,8 @@ "name": "user_stats_user_id_user_id_fk", "tableFrom": "user_stats", "tableTo": "user", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], + "columnsFrom": ["user_id"], + "columnsTo": ["id"], "onDelete": "cascade", "onUpdate": "no action" } @@ -2211,9 +2113,7 @@ "user_stats_user_id_unique": { "name": "user_stats_user_id_unique", "nullsNotDistinct": false, - "columns": [ - "user_id" - ] + "columns": ["user_id"] } }, "policies": {}, @@ -2314,9 +2214,7 @@ "waitlist_email_unique": { "name": "waitlist_email_unique", "nullsNotDistinct": false, - "columns": [ - "email" - ] + "columns": ["email"] } }, "policies": {}, @@ -2401,12 +2299,8 @@ "name": "webhook_workflow_id_workflow_id_fk", "tableFrom": "webhook", "tableTo": "workflow", - "columnsFrom": [ - "workflow_id" - ], - "columnsTo": [ - "id" - ], + "columnsFrom": ["workflow_id"], + "columnsTo": ["id"], "onDelete": "cascade", "onUpdate": "no action" } @@ -2554,12 +2448,8 @@ "name": "workflow_user_id_user_id_fk", "tableFrom": "workflow", "tableTo": "user", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], + "columnsFrom": ["user_id"], + "columnsTo": ["id"], "onDelete": "cascade", "onUpdate": "no action" }, @@ -2567,12 +2457,8 @@ "name": "workflow_workspace_id_workspace_id_fk", "tableFrom": "workflow", "tableTo": "workspace", - "columnsFrom": [ - "workspace_id" - ], - "columnsTo": [ - "id" - ], + "columnsFrom": ["workspace_id"], + "columnsTo": ["id"], "onDelete": "cascade", "onUpdate": "no action" }, @@ -2580,12 +2466,8 @@ "name": "workflow_folder_id_workflow_folder_id_fk", "tableFrom": "workflow", "tableTo": "workflow_folder", - "columnsFrom": [ - "folder_id" - ], - "columnsTo": [ - "id" - ], + "columnsFrom": ["folder_id"], + "columnsTo": ["id"], "onDelete": "set null", "onUpdate": "no action" } @@ -2791,12 +2673,8 @@ "name": "workflow_blocks_workflow_id_workflow_id_fk", "tableFrom": "workflow_blocks", "tableTo": "workflow", - "columnsFrom": [ - "workflow_id" - ], - "columnsTo": [ - "id" - ], + "columnsFrom": ["workflow_id"], + "columnsTo": ["id"], "onDelete": "cascade", "onUpdate": "no action" } @@ -2949,12 +2827,8 @@ "name": "workflow_edges_workflow_id_workflow_id_fk", "tableFrom": "workflow_edges", "tableTo": "workflow", - "columnsFrom": [ - "workflow_id" - ], - "columnsTo": [ - "id" - ], + "columnsFrom": ["workflow_id"], + "columnsTo": ["id"], "onDelete": "cascade", "onUpdate": "no action" }, @@ -2962,12 +2836,8 @@ "name": "workflow_edges_source_block_id_workflow_blocks_id_fk", "tableFrom": "workflow_edges", "tableTo": "workflow_blocks", - "columnsFrom": [ - "source_block_id" - ], - "columnsTo": [ - "id" - ], + "columnsFrom": ["source_block_id"], + "columnsTo": ["id"], "onDelete": "cascade", "onUpdate": "no action" }, @@ -2975,12 +2845,8 @@ "name": "workflow_edges_target_block_id_workflow_blocks_id_fk", "tableFrom": "workflow_edges", "tableTo": "workflow_blocks", - "columnsFrom": [ - "target_block_id" - ], - "columnsTo": [ - "id" - ], + "columnsFrom": ["target_block_id"], + "columnsTo": ["id"], "onDelete": "cascade", "onUpdate": "no action" } @@ -3125,12 +2991,8 @@ "name": "workflow_folder_user_id_user_id_fk", "tableFrom": "workflow_folder", "tableTo": "user", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], + "columnsFrom": ["user_id"], + "columnsTo": ["id"], "onDelete": "cascade", "onUpdate": "no action" }, @@ -3138,12 +3000,8 @@ "name": "workflow_folder_workspace_id_workspace_id_fk", "tableFrom": "workflow_folder", "tableTo": "workspace", - "columnsFrom": [ - "workspace_id" - ], - "columnsTo": [ - "id" - ], + "columnsFrom": ["workspace_id"], + "columnsTo": ["id"], "onDelete": "cascade", "onUpdate": "no action" } @@ -3220,12 +3078,8 @@ "name": "workflow_logs_workflow_id_workflow_id_fk", "tableFrom": "workflow_logs", "tableTo": "workflow", - "columnsFrom": [ - "workflow_id" - ], - "columnsTo": [ - "id" - ], + "columnsFrom": ["workflow_id"], + "columnsTo": ["id"], "onDelete": "cascade", "onUpdate": "no action" } @@ -3324,12 +3178,8 @@ "name": "workflow_schedule_workflow_id_workflow_id_fk", "tableFrom": "workflow_schedule", "tableTo": "workflow", - "columnsFrom": [ - "workflow_id" - ], - "columnsTo": [ - "id" - ], + "columnsFrom": ["workflow_id"], + "columnsTo": ["id"], "onDelete": "cascade", "onUpdate": "no action" } @@ -3339,9 +3189,7 @@ "workflow_schedule_workflow_id_unique": { "name": "workflow_schedule_workflow_id_unique", "nullsNotDistinct": false, - "columns": [ - "workflow_id" - ] + "columns": ["workflow_id"] } }, "policies": {}, @@ -3435,12 +3283,8 @@ "name": "workflow_subflows_workflow_id_workflow_id_fk", "tableFrom": "workflow_subflows", "tableTo": "workflow", - "columnsFrom": [ - "workflow_id" - ], - "columnsTo": [ - "id" - ], + "columnsFrom": ["workflow_id"], + "columnsTo": ["id"], "onDelete": "cascade", "onUpdate": "no action" } @@ -3494,12 +3338,8 @@ "name": "workspace_owner_id_user_id_fk", "tableFrom": "workspace", "tableTo": "user", - "columnsFrom": [ - "owner_id" - ], - "columnsTo": [ - "id" - ], + "columnsFrom": ["owner_id"], + "columnsTo": ["id"], "onDelete": "cascade", "onUpdate": "no action" } @@ -3585,12 +3425,8 @@ "name": "workspace_invitation_workspace_id_workspace_id_fk", "tableFrom": "workspace_invitation", "tableTo": "workspace", - "columnsFrom": [ - "workspace_id" - ], - "columnsTo": [ - "id" - ], + "columnsFrom": ["workspace_id"], + "columnsTo": ["id"], "onDelete": "cascade", "onUpdate": "no action" }, @@ -3598,12 +3434,8 @@ "name": "workspace_invitation_inviter_id_user_id_fk", "tableFrom": "workspace_invitation", "tableTo": "user", - "columnsFrom": [ - "inviter_id" - ], - "columnsTo": [ - "id" - ], + "columnsFrom": ["inviter_id"], + "columnsTo": ["id"], "onDelete": "cascade", "onUpdate": "no action" } @@ -3613,9 +3445,7 @@ "workspace_invitation_token_unique": { "name": "workspace_invitation_token_unique", "nullsNotDistinct": false, - "columns": [ - "token" - ] + "columns": ["token"] } }, "policies": {}, @@ -3694,12 +3524,8 @@ "name": "workspace_member_workspace_id_workspace_id_fk", "tableFrom": "workspace_member", "tableTo": "workspace", - "columnsFrom": [ - "workspace_id" - ], - "columnsTo": [ - "id" - ], + "columnsFrom": ["workspace_id"], + "columnsTo": ["id"], "onDelete": "cascade", "onUpdate": "no action" }, @@ -3707,12 +3533,8 @@ "name": "workspace_member_user_id_user_id_fk", "tableFrom": "workspace_member", "tableTo": "user", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], + "columnsFrom": ["user_id"], + "columnsTo": ["id"], "onDelete": "cascade", "onUpdate": "no action" } @@ -3735,4 +3557,4 @@ "schemas": {}, "tables": {} } -} \ No newline at end of file +} diff --git a/apps/sim/db/migrations/meta/_journal.json b/apps/sim/db/migrations/meta/_journal.json index 28478f84736..cc777d84025 100644 --- a/apps/sim/db/migrations/meta/_journal.json +++ b/apps/sim/db/migrations/meta/_journal.json @@ -311,4 +311,4 @@ "breakpoints": true } ] -} \ No newline at end of file +} diff --git a/apps/sim/db/migrations/relations.ts b/apps/sim/db/migrations/relations.ts deleted file mode 100644 index 6010b0806eb..00000000000 --- a/apps/sim/db/migrations/relations.ts +++ /dev/null @@ -1,308 +0,0 @@ -import { relations } from "drizzle-orm/relations"; -import { user, account, workflow, workflowBroadcastConnections, environment, webhook, workflowLogs, apiKey, marketplace, customTools, session, organization, invitation, member, chat, settings, workspace, workspaceMember, workspaceInvitation, userStats, workflowFolder, workflowSchedule, memory, knowledgeBase, document, embedding, workflowBlocks, workflowEdges, workflowSubflows } from "./schema"; - -export const accountRelations = relations(account, ({one}) => ({ - user: one(user, { - fields: [account.userId], - references: [user.id] - }), -})); - -export const userRelations = relations(user, ({many}) => ({ - accounts: many(account), - environments: many(environment), - apiKeys: many(apiKey), - marketplaces: many(marketplace), - customTools: many(customTools), - sessions: many(session), - invitations: many(invitation), - members: many(member), - chats: many(chat), - settings: many(settings), - workspaces: many(workspace), - workspaceMembers: many(workspaceMember), - workspaceInvitations: many(workspaceInvitation), - userStats: many(userStats), - workflows: many(workflow), - knowledgeBases: many(knowledgeBase), - workflowFolders: many(workflowFolder), -})); - -export const workflowBroadcastConnectionsRelations = relations(workflowBroadcastConnections, ({one}) => ({ - workflow: one(workflow, { - fields: [workflowBroadcastConnections.workflowId], - references: [workflow.id] - }), -})); - -export const workflowRelations = relations(workflow, ({one, many}) => ({ - workflowBroadcastConnections: many(workflowBroadcastConnections), - webhooks: many(webhook), - workflowLogs: many(workflowLogs), - marketplaces: many(marketplace), - chats: many(chat), - user: one(user, { - fields: [workflow.userId], - references: [user.id] - }), - workspace: one(workspace, { - fields: [workflow.workspaceId], - references: [workspace.id] - }), - workflowFolder: one(workflowFolder, { - fields: [workflow.folderId], - references: [workflowFolder.id] - }), - workflowSchedules: many(workflowSchedule), - memories: many(memory), - workflowBlocks: many(workflowBlocks), - workflowEdges: many(workflowEdges), - workflowSubflows: many(workflowSubflows), -})); - -export const environmentRelations = relations(environment, ({one}) => ({ - user: one(user, { - fields: [environment.userId], - references: [user.id] - }), -})); - -export const webhookRelations = relations(webhook, ({one}) => ({ - workflow: one(workflow, { - fields: [webhook.workflowId], - references: [workflow.id] - }), -})); - -export const workflowLogsRelations = relations(workflowLogs, ({one}) => ({ - workflow: one(workflow, { - fields: [workflowLogs.workflowId], - references: [workflow.id] - }), -})); - -export const apiKeyRelations = relations(apiKey, ({one}) => ({ - user: one(user, { - fields: [apiKey.userId], - references: [user.id] - }), -})); - -export const marketplaceRelations = relations(marketplace, ({one}) => ({ - workflow: one(workflow, { - fields: [marketplace.workflowId], - references: [workflow.id] - }), - user: one(user, { - fields: [marketplace.authorId], - references: [user.id] - }), -})); - -export const customToolsRelations = relations(customTools, ({one}) => ({ - user: one(user, { - fields: [customTools.userId], - references: [user.id] - }), -})); - -export const sessionRelations = relations(session, ({one}) => ({ - user: one(user, { - fields: [session.userId], - references: [user.id] - }), - organization: one(organization, { - fields: [session.activeOrganizationId], - references: [organization.id] - }), -})); - -export const organizationRelations = relations(organization, ({many}) => ({ - sessions: many(session), - invitations: many(invitation), - members: many(member), -})); - -export const invitationRelations = relations(invitation, ({one}) => ({ - user: one(user, { - fields: [invitation.inviterId], - references: [user.id] - }), - organization: one(organization, { - fields: [invitation.organizationId], - references: [organization.id] - }), -})); - -export const memberRelations = relations(member, ({one}) => ({ - user: one(user, { - fields: [member.userId], - references: [user.id] - }), - organization: one(organization, { - fields: [member.organizationId], - references: [organization.id] - }), -})); - -export const chatRelations = relations(chat, ({one}) => ({ - workflow: one(workflow, { - fields: [chat.workflowId], - references: [workflow.id] - }), - user: one(user, { - fields: [chat.userId], - references: [user.id] - }), -})); - -export const settingsRelations = relations(settings, ({one}) => ({ - user: one(user, { - fields: [settings.userId], - references: [user.id] - }), -})); - -export const workspaceRelations = relations(workspace, ({one, many}) => ({ - user: one(user, { - fields: [workspace.ownerId], - references: [user.id] - }), - workspaceMembers: many(workspaceMember), - workspaceInvitations: many(workspaceInvitation), - workflows: many(workflow), - knowledgeBases: many(knowledgeBase), - workflowFolders: many(workflowFolder), -})); - -export const workspaceMemberRelations = relations(workspaceMember, ({one}) => ({ - workspace: one(workspace, { - fields: [workspaceMember.workspaceId], - references: [workspace.id] - }), - user: one(user, { - fields: [workspaceMember.userId], - references: [user.id] - }), -})); - -export const workspaceInvitationRelations = relations(workspaceInvitation, ({one}) => ({ - workspace: one(workspace, { - fields: [workspaceInvitation.workspaceId], - references: [workspace.id] - }), - user: one(user, { - fields: [workspaceInvitation.inviterId], - references: [user.id] - }), -})); - -export const userStatsRelations = relations(userStats, ({one}) => ({ - user: one(user, { - fields: [userStats.userId], - references: [user.id] - }), -})); - -export const workflowFolderRelations = relations(workflowFolder, ({one, many}) => ({ - workflows: many(workflow), - user: one(user, { - fields: [workflowFolder.userId], - references: [user.id] - }), - workspace: one(workspace, { - fields: [workflowFolder.workspaceId], - references: [workspace.id] - }), -})); - -export const workflowScheduleRelations = relations(workflowSchedule, ({one}) => ({ - workflow: one(workflow, { - fields: [workflowSchedule.workflowId], - references: [workflow.id] - }), -})); - -export const memoryRelations = relations(memory, ({one}) => ({ - workflow: one(workflow, { - fields: [memory.workflowId], - references: [workflow.id] - }), -})); - -export const knowledgeBaseRelations = relations(knowledgeBase, ({one, many}) => ({ - user: one(user, { - fields: [knowledgeBase.userId], - references: [user.id] - }), - workspace: one(workspace, { - fields: [knowledgeBase.workspaceId], - references: [workspace.id] - }), - documents: many(document), - embeddings: many(embedding), -})); - -export const documentRelations = relations(document, ({one, many}) => ({ - knowledgeBase: one(knowledgeBase, { - fields: [document.knowledgeBaseId], - references: [knowledgeBase.id] - }), - embeddings: many(embedding), -})); - -export const embeddingRelations = relations(embedding, ({one}) => ({ - knowledgeBase: one(knowledgeBase, { - fields: [embedding.knowledgeBaseId], - references: [knowledgeBase.id] - }), - document: one(document, { - fields: [embedding.documentId], - references: [document.id] - }), -})); - -export const workflowBlocksRelations = relations(workflowBlocks, ({one, many}) => ({ - workflow: one(workflow, { - fields: [workflowBlocks.workflowId], - references: [workflow.id] - }), - workflowBlock: one(workflowBlocks, { - fields: [workflowBlocks.parentId], - references: [workflowBlocks.id], - relationName: "workflowBlocks_parentId_workflowBlocks_id" - }), - workflowBlocks: many(workflowBlocks, { - relationName: "workflowBlocks_parentId_workflowBlocks_id" - }), - workflowEdges_sourceBlockId: many(workflowEdges, { - relationName: "workflowEdges_sourceBlockId_workflowBlocks_id" - }), - workflowEdges_targetBlockId: many(workflowEdges, { - relationName: "workflowEdges_targetBlockId_workflowBlocks_id" - }), -})); - -export const workflowEdgesRelations = relations(workflowEdges, ({one}) => ({ - workflow: one(workflow, { - fields: [workflowEdges.workflowId], - references: [workflow.id] - }), - workflowBlock_sourceBlockId: one(workflowBlocks, { - fields: [workflowEdges.sourceBlockId], - references: [workflowBlocks.id], - relationName: "workflowEdges_sourceBlockId_workflowBlocks_id" - }), - workflowBlock_targetBlockId: one(workflowBlocks, { - fields: [workflowEdges.targetBlockId], - references: [workflowBlocks.id], - relationName: "workflowEdges_targetBlockId_workflowBlocks_id" - }), -})); - -export const workflowSubflowsRelations = relations(workflowSubflows, ({one}) => ({ - workflow: one(workflow, { - fields: [workflowSubflows.workflowId], - references: [workflow.id] - }), -})); \ No newline at end of file diff --git a/apps/sim/db/migrations/schema.ts b/apps/sim/db/migrations/schema.ts deleted file mode 100644 index 378352aa9d7..00000000000 --- a/apps/sim/db/migrations/schema.ts +++ /dev/null @@ -1,722 +0,0 @@ -import { pgTable, text, timestamp, foreignKey, unique, index, serial, json, uniqueIndex, boolean, integer, numeric, jsonb, check, vector } from "drizzle-orm/pg-core" -import { sql } from "drizzle-orm" - - - -export const verification = pgTable("verification", { - id: text().primaryKey().notNull(), - identifier: text().notNull(), - value: text().notNull(), - expiresAt: timestamp("expires_at", { mode: 'string' }).notNull(), - createdAt: timestamp("created_at", { mode: 'string' }), - updatedAt: timestamp("updated_at", { mode: 'string' }), -}); - -export const account = pgTable("account", { - id: text().primaryKey().notNull(), - accountId: text("account_id").notNull(), - providerId: text("provider_id").notNull(), - userId: text("user_id").notNull(), - accessToken: text("access_token"), - refreshToken: text("refresh_token"), - idToken: text("id_token"), - accessTokenExpiresAt: timestamp("access_token_expires_at", { mode: 'string' }), - refreshTokenExpiresAt: timestamp("refresh_token_expires_at", { mode: 'string' }), - scope: text(), - password: text(), - createdAt: timestamp("created_at", { mode: 'string' }).notNull(), - updatedAt: timestamp("updated_at", { mode: 'string' }).notNull(), -}, (table) => [ - foreignKey({ - columns: [table.userId], - foreignColumns: [user.id], - name: "account_user_id_user_id_fk" - }).onDelete("cascade"), -]); - -export const waitlist = pgTable("waitlist", { - id: text().primaryKey().notNull(), - email: text().notNull(), - status: text().default('pending').notNull(), - createdAt: timestamp("created_at", { mode: 'string' }).defaultNow().notNull(), - updatedAt: timestamp("updated_at", { mode: 'string' }).defaultNow().notNull(), -}, (table) => [ - unique("waitlist_email_unique").on(table.email), -]); - -export const workflowBroadcastConnections = pgTable("workflow_broadcast_connections", { - id: serial().primaryKey().notNull(), - userId: text("user_id").notNull(), - workflowId: text("workflow_id").notNull(), - connectionId: text("connection_id").notNull(), - createdAt: timestamp("created_at", { mode: 'string' }).defaultNow(), - lastSeen: timestamp("last_seen", { mode: 'string' }).defaultNow(), -}, (table) => [ - index("idx_workflow_broadcast_connections_user").using("btree", table.userId.asc().nullsLast().op("text_ops")), - index("idx_workflow_broadcast_connections_workflow").using("btree", table.workflowId.asc().nullsLast().op("text_ops")), - foreignKey({ - columns: [table.workflowId], - foreignColumns: [workflow.id], - name: "workflow_broadcast_connections_workflow_id_fkey" - }).onDelete("cascade"), - unique("workflow_broadcast_connections_connection_id_key").on(table.connectionId), -]); - -export const environment = pgTable("environment", { - id: text().primaryKey().notNull(), - userId: text("user_id").notNull(), - variables: json().notNull(), - updatedAt: timestamp("updated_at", { mode: 'string' }).defaultNow().notNull(), -}, (table) => [ - foreignKey({ - columns: [table.userId], - foreignColumns: [user.id], - name: "environment_user_id_user_id_fk" - }).onDelete("cascade"), - unique("environment_user_id_unique").on(table.userId), -]); - -export const webhook = pgTable("webhook", { - id: text().primaryKey().notNull(), - workflowId: text("workflow_id").notNull(), - path: text().notNull(), - provider: text(), - isActive: boolean("is_active").default(true).notNull(), - createdAt: timestamp("created_at", { mode: 'string' }).defaultNow().notNull(), - updatedAt: timestamp("updated_at", { mode: 'string' }).defaultNow().notNull(), - providerConfig: json("provider_config"), -}, (table) => [ - uniqueIndex("path_idx").using("btree", table.path.asc().nullsLast().op("text_ops")), - foreignKey({ - columns: [table.workflowId], - foreignColumns: [workflow.id], - name: "webhook_workflow_id_workflow_id_fk" - }).onDelete("cascade"), -]); - -export const workflowLogs = pgTable("workflow_logs", { - id: text().primaryKey().notNull(), - workflowId: text("workflow_id").notNull(), - executionId: text("execution_id"), - level: text().notNull(), - message: text().notNull(), - createdAt: timestamp("created_at", { mode: 'string' }).defaultNow().notNull(), - duration: text(), - trigger: text(), - metadata: json(), -}, (table) => [ - foreignKey({ - columns: [table.workflowId], - foreignColumns: [workflow.id], - name: "workflow_logs_workflow_id_workflow_id_fk" - }).onDelete("cascade"), -]); - -export const apiKey = pgTable("api_key", { - id: text().primaryKey().notNull(), - userId: text("user_id").notNull(), - name: text().notNull(), - key: text().notNull(), - lastUsed: timestamp("last_used", { mode: 'string' }), - createdAt: timestamp("created_at", { mode: 'string' }).defaultNow().notNull(), - updatedAt: timestamp("updated_at", { mode: 'string' }).defaultNow().notNull(), - expiresAt: timestamp("expires_at", { mode: 'string' }), -}, (table) => [ - foreignKey({ - columns: [table.userId], - foreignColumns: [user.id], - name: "api_key_user_id_user_id_fk" - }).onDelete("cascade"), - unique("api_key_key_unique").on(table.key), -]); - -export const marketplace = pgTable("marketplace", { - id: text().primaryKey().notNull(), - workflowId: text("workflow_id").notNull(), - state: json().notNull(), - name: text().notNull(), - description: text(), - authorId: text("author_id").notNull(), - authorName: text("author_name").notNull(), - views: integer().default(0).notNull(), - category: text(), - createdAt: timestamp("created_at", { mode: 'string' }).defaultNow().notNull(), - updatedAt: timestamp("updated_at", { mode: 'string' }).defaultNow().notNull(), -}, (table) => [ - foreignKey({ - columns: [table.workflowId], - foreignColumns: [workflow.id], - name: "marketplace_workflow_id_workflow_id_fk" - }).onDelete("cascade"), - foreignKey({ - columns: [table.authorId], - foreignColumns: [user.id], - name: "marketplace_author_id_user_id_fk" - }), -]); - -export const customTools = pgTable("custom_tools", { - id: text().primaryKey().notNull(), - userId: text("user_id").notNull(), - title: text().notNull(), - schema: json().notNull(), - code: text().notNull(), - createdAt: timestamp("created_at", { mode: 'string' }).defaultNow().notNull(), - updatedAt: timestamp("updated_at", { mode: 'string' }).defaultNow().notNull(), -}, (table) => [ - foreignKey({ - columns: [table.userId], - foreignColumns: [user.id], - name: "custom_tools_user_id_user_id_fk" - }).onDelete("cascade"), -]); - -export const user = pgTable("user", { - id: text().primaryKey().notNull(), - name: text().notNull(), - email: text().notNull(), - emailVerified: boolean("email_verified").notNull(), - image: text(), - createdAt: timestamp("created_at", { mode: 'string' }).notNull(), - updatedAt: timestamp("updated_at", { mode: 'string' }).notNull(), - stripeCustomerId: text("stripe_customer_id"), -}, (table) => [ - unique("user_email_unique").on(table.email), -]); - -export const session = pgTable("session", { - id: text().primaryKey().notNull(), - expiresAt: timestamp("expires_at", { mode: 'string' }).notNull(), - token: text().notNull(), - createdAt: timestamp("created_at", { mode: 'string' }).notNull(), - updatedAt: timestamp("updated_at", { mode: 'string' }).notNull(), - ipAddress: text("ip_address"), - userAgent: text("user_agent"), - userId: text("user_id").notNull(), - activeOrganizationId: text("active_organization_id"), -}, (table) => [ - foreignKey({ - columns: [table.userId], - foreignColumns: [user.id], - name: "session_user_id_user_id_fk" - }).onDelete("cascade"), - foreignKey({ - columns: [table.activeOrganizationId], - foreignColumns: [organization.id], - name: "session_active_organization_id_organization_id_fk" - }).onDelete("set null"), - unique("session_token_unique").on(table.token), -]); - -export const invitation = pgTable("invitation", { - id: text().primaryKey().notNull(), - email: text().notNull(), - inviterId: text("inviter_id").notNull(), - organizationId: text("organization_id").notNull(), - role: text().notNull(), - status: text().notNull(), - expiresAt: timestamp("expires_at", { mode: 'string' }).notNull(), - createdAt: timestamp("created_at", { mode: 'string' }).defaultNow().notNull(), -}, (table) => [ - foreignKey({ - columns: [table.inviterId], - foreignColumns: [user.id], - name: "invitation_inviter_id_user_id_fk" - }).onDelete("cascade"), - foreignKey({ - columns: [table.organizationId], - foreignColumns: [organization.id], - name: "invitation_organization_id_organization_id_fk" - }).onDelete("cascade"), -]); - -export const member = pgTable("member", { - id: text().primaryKey().notNull(), - userId: text("user_id").notNull(), - organizationId: text("organization_id").notNull(), - role: text().notNull(), - createdAt: timestamp("created_at", { mode: 'string' }).defaultNow().notNull(), -}, (table) => [ - foreignKey({ - columns: [table.userId], - foreignColumns: [user.id], - name: "member_user_id_user_id_fk" - }).onDelete("cascade"), - foreignKey({ - columns: [table.organizationId], - foreignColumns: [organization.id], - name: "member_organization_id_organization_id_fk" - }).onDelete("cascade"), -]); - -export const chat = pgTable("chat", { - id: text().primaryKey().notNull(), - workflowId: text("workflow_id").notNull(), - userId: text("user_id").notNull(), - subdomain: text().notNull(), - title: text().notNull(), - description: text(), - isActive: boolean("is_active").default(true).notNull(), - customizations: json().default({}), - authType: text("auth_type").default('public').notNull(), - password: text(), - allowedEmails: json("allowed_emails").default([]), - createdAt: timestamp("created_at", { mode: 'string' }).defaultNow().notNull(), - updatedAt: timestamp("updated_at", { mode: 'string' }).defaultNow().notNull(), - outputConfigs: json("output_configs").default([]), -}, (table) => [ - uniqueIndex("subdomain_idx").using("btree", table.subdomain.asc().nullsLast().op("text_ops")), - foreignKey({ - columns: [table.workflowId], - foreignColumns: [workflow.id], - name: "chat_workflow_id_workflow_id_fk" - }).onDelete("cascade"), - foreignKey({ - columns: [table.userId], - foreignColumns: [user.id], - name: "chat_user_id_user_id_fk" - }).onDelete("cascade"), -]); - -export const settings = pgTable("settings", { - id: text().primaryKey().notNull(), - userId: text("user_id").notNull(), - general: json().default({}).notNull(), - updatedAt: timestamp("updated_at", { mode: 'string' }).defaultNow().notNull(), - theme: text().default('system').notNull(), - debugMode: boolean("debug_mode").default(false).notNull(), - autoConnect: boolean("auto_connect").default(true).notNull(), - autoFillEnvVars: boolean("auto_fill_env_vars").default(true).notNull(), - telemetryEnabled: boolean("telemetry_enabled").default(true).notNull(), - telemetryNotifiedUser: boolean("telemetry_notified_user").default(false).notNull(), - emailPreferences: json("email_preferences").default({}).notNull(), -}, (table) => [ - foreignKey({ - columns: [table.userId], - foreignColumns: [user.id], - name: "settings_user_id_user_id_fk" - }).onDelete("cascade"), - unique("settings_user_id_unique").on(table.userId), -]); - -export const workspace = pgTable("workspace", { - id: text().primaryKey().notNull(), - name: text().notNull(), - ownerId: text("owner_id").notNull(), - createdAt: timestamp("created_at", { mode: 'string' }).defaultNow().notNull(), - updatedAt: timestamp("updated_at", { mode: 'string' }).defaultNow().notNull(), -}, (table) => [ - foreignKey({ - columns: [table.ownerId], - foreignColumns: [user.id], - name: "workspace_owner_id_user_id_fk" - }).onDelete("cascade"), -]); - -export const workspaceMember = pgTable("workspace_member", { - id: text().primaryKey().notNull(), - workspaceId: text("workspace_id").notNull(), - userId: text("user_id").notNull(), - role: text().default('member').notNull(), - joinedAt: timestamp("joined_at", { mode: 'string' }).defaultNow().notNull(), - updatedAt: timestamp("updated_at", { mode: 'string' }).defaultNow().notNull(), -}, (table) => [ - uniqueIndex("user_workspace_idx").using("btree", table.userId.asc().nullsLast().op("text_ops"), table.workspaceId.asc().nullsLast().op("text_ops")), - foreignKey({ - columns: [table.workspaceId], - foreignColumns: [workspace.id], - name: "workspace_member_workspace_id_workspace_id_fk" - }).onDelete("cascade"), - foreignKey({ - columns: [table.userId], - foreignColumns: [user.id], - name: "workspace_member_user_id_user_id_fk" - }).onDelete("cascade"), -]); - -export const workspaceInvitation = pgTable("workspace_invitation", { - id: text().primaryKey().notNull(), - workspaceId: text("workspace_id").notNull(), - email: text().notNull(), - inviterId: text("inviter_id").notNull(), - role: text().default('member').notNull(), - status: text().default('pending').notNull(), - token: text().notNull(), - expiresAt: timestamp("expires_at", { mode: 'string' }).notNull(), - createdAt: timestamp("created_at", { mode: 'string' }).defaultNow().notNull(), - updatedAt: timestamp("updated_at", { mode: 'string' }).defaultNow().notNull(), -}, (table) => [ - foreignKey({ - columns: [table.workspaceId], - foreignColumns: [workspace.id], - name: "workspace_invitation_workspace_id_workspace_id_fk" - }).onDelete("cascade"), - foreignKey({ - columns: [table.inviterId], - foreignColumns: [user.id], - name: "workspace_invitation_inviter_id_user_id_fk" - }).onDelete("cascade"), - unique("workspace_invitation_token_unique").on(table.token), -]); - -export const organization = pgTable("organization", { - id: text().primaryKey().notNull(), - name: text().notNull(), - slug: text().notNull(), - logo: text(), - metadata: json(), - createdAt: timestamp("created_at", { mode: 'string' }).defaultNow().notNull(), - updatedAt: timestamp("updated_at", { mode: 'string' }).defaultNow().notNull(), -}); - -export const subscription = pgTable("subscription", { - id: text().primaryKey().notNull(), - plan: text().notNull(), - referenceId: text("reference_id").notNull(), - stripeCustomerId: text("stripe_customer_id"), - stripeSubscriptionId: text("stripe_subscription_id"), - status: text(), - periodStart: timestamp("period_start", { mode: 'string' }), - periodEnd: timestamp("period_end", { mode: 'string' }), - cancelAtPeriodEnd: boolean("cancel_at_period_end"), - seats: integer(), - trialStart: timestamp("trial_start", { mode: 'string' }), - trialEnd: timestamp("trial_end", { mode: 'string' }), - metadata: json(), -}); - -export const userStats = pgTable("user_stats", { - id: text().primaryKey().notNull(), - userId: text("user_id").notNull(), - totalManualExecutions: integer("total_manual_executions").default(0).notNull(), - totalApiCalls: integer("total_api_calls").default(0).notNull(), - totalWebhookTriggers: integer("total_webhook_triggers").default(0).notNull(), - totalScheduledExecutions: integer("total_scheduled_executions").default(0).notNull(), - totalTokensUsed: integer("total_tokens_used").default(0).notNull(), - totalCost: numeric("total_cost").default('0').notNull(), - lastActive: timestamp("last_active", { mode: 'string' }).defaultNow().notNull(), - totalChatExecutions: integer("total_chat_executions").default(0).notNull(), -}, (table) => [ - foreignKey({ - columns: [table.userId], - foreignColumns: [user.id], - name: "user_stats_user_id_user_id_fk" - }).onDelete("cascade"), - unique("user_stats_user_id_unique").on(table.userId), -]); - -export const workflow = pgTable("workflow", { - id: text().primaryKey().notNull(), - userId: text("user_id").notNull(), - name: text().notNull(), - description: text(), - state: json().notNull(), - lastSynced: timestamp("last_synced", { mode: 'string' }).notNull(), - createdAt: timestamp("created_at", { mode: 'string' }).notNull(), - updatedAt: timestamp("updated_at", { mode: 'string' }).notNull(), - isDeployed: boolean("is_deployed").default(false).notNull(), - deployedAt: timestamp("deployed_at", { mode: 'string' }), - color: text().default('#3972F6').notNull(), - collaborators: json().default([]).notNull(), - isPublished: boolean("is_published").default(false).notNull(), - runCount: integer("run_count").default(0).notNull(), - lastRunAt: timestamp("last_run_at", { mode: 'string' }), - variables: json().default({}), - marketplaceData: json("marketplace_data"), - deployedHash: text("deployed_hash"), - workspaceId: text("workspace_id"), - folderId: text("folder_id"), - deployedState: json("deployed_state"), - lastSaved: timestamp("last_saved", { mode: 'string' }), - deploymentStatuses: jsonb("deployment_statuses").default({}), - hasActiveSchedule: boolean("has_active_schedule").default(false), - hasActiveWebhook: boolean("has_active_webhook").default(false), -}, (table) => [ - foreignKey({ - columns: [table.userId], - foreignColumns: [user.id], - name: "workflow_user_id_user_id_fk" - }).onDelete("cascade"), - foreignKey({ - columns: [table.workspaceId], - foreignColumns: [workspace.id], - name: "workflow_workspace_id_workspace_id_fk" - }).onDelete("cascade"), - foreignKey({ - columns: [table.folderId], - foreignColumns: [workflowFolder.id], - name: "workflow_folder_id_workflow_folder_id_fk" - }).onDelete("set null"), -]); - -export const workflowSchedule = pgTable("workflow_schedule", { - id: text().primaryKey().notNull(), - workflowId: text("workflow_id").notNull(), - cronExpression: text("cron_expression"), - nextRunAt: timestamp("next_run_at", { mode: 'string' }), - lastRanAt: timestamp("last_ran_at", { mode: 'string' }), - triggerType: text("trigger_type").notNull(), - timezone: text().default('UTC').notNull(), - createdAt: timestamp("created_at", { mode: 'string' }).defaultNow().notNull(), - updatedAt: timestamp("updated_at", { mode: 'string' }).defaultNow().notNull(), - failedCount: integer("failed_count").default(0).notNull(), - status: text().default('active').notNull(), - lastFailedAt: timestamp("last_failed_at", { mode: 'string' }), -}, (table) => [ - foreignKey({ - columns: [table.workflowId], - foreignColumns: [workflow.id], - name: "workflow_schedule_workflow_id_workflow_id_fk" - }).onDelete("cascade"), - unique("workflow_schedule_workflow_id_unique").on(table.workflowId), -]); - -export const memory = pgTable("memory", { - id: text().primaryKey().notNull(), - workflowId: text("workflow_id"), - key: text().notNull(), - type: text().notNull(), - data: json().notNull(), - createdAt: timestamp("created_at", { mode: 'string' }).defaultNow().notNull(), - updatedAt: timestamp("updated_at", { mode: 'string' }).defaultNow().notNull(), - deletedAt: timestamp("deleted_at", { mode: 'string' }), -}, (table) => [ - index("memory_key_idx").using("btree", table.key.asc().nullsLast().op("text_ops")), - index("memory_workflow_idx").using("btree", table.workflowId.asc().nullsLast().op("text_ops")), - uniqueIndex("memory_workflow_key_idx").using("btree", table.workflowId.asc().nullsLast().op("text_ops"), table.key.asc().nullsLast().op("text_ops")), - foreignKey({ - columns: [table.workflowId], - foreignColumns: [workflow.id], - name: "memory_workflow_id_workflow_id_fk" - }).onDelete("cascade"), -]); - -export const knowledgeBase = pgTable("knowledge_base", { - id: text().primaryKey().notNull(), - userId: text("user_id").notNull(), - workspaceId: text("workspace_id"), - name: text().notNull(), - description: text(), - tokenCount: integer("token_count").default(0).notNull(), - embeddingModel: text("embedding_model").default('text-embedding-3-small').notNull(), - embeddingDimension: integer("embedding_dimension").default(1536).notNull(), - chunkingConfig: json("chunking_config").default({"maxSize":1024,"minSize":100,"overlap":200}).notNull(), - deletedAt: timestamp("deleted_at", { mode: 'string' }), - createdAt: timestamp("created_at", { mode: 'string' }).defaultNow().notNull(), - updatedAt: timestamp("updated_at", { mode: 'string' }).defaultNow().notNull(), -}, (table) => [ - index("kb_deleted_at_idx").using("btree", table.deletedAt.asc().nullsLast().op("timestamp_ops")), - index("kb_user_id_idx").using("btree", table.userId.asc().nullsLast().op("text_ops")), - index("kb_user_workspace_idx").using("btree", table.userId.asc().nullsLast().op("text_ops"), table.workspaceId.asc().nullsLast().op("text_ops")), - index("kb_workspace_id_idx").using("btree", table.workspaceId.asc().nullsLast().op("text_ops")), - foreignKey({ - columns: [table.userId], - foreignColumns: [user.id], - name: "knowledge_base_user_id_user_id_fk" - }).onDelete("cascade"), - foreignKey({ - columns: [table.workspaceId], - foreignColumns: [workspace.id], - name: "knowledge_base_workspace_id_workspace_id_fk" - }).onDelete("cascade"), -]); - -export const document = pgTable("document", { - id: text().primaryKey().notNull(), - knowledgeBaseId: text("knowledge_base_id").notNull(), - filename: text().notNull(), - fileUrl: text("file_url").notNull(), - fileSize: integer("file_size").notNull(), - mimeType: text("mime_type").notNull(), - fileHash: text("file_hash"), - chunkCount: integer("chunk_count").default(0).notNull(), - tokenCount: integer("token_count").default(0).notNull(), - characterCount: integer("character_count").default(0).notNull(), - enabled: boolean().default(true).notNull(), - deletedAt: timestamp("deleted_at", { mode: 'string' }), - uploadedAt: timestamp("uploaded_at", { mode: 'string' }).defaultNow().notNull(), - processingStatus: text("processing_status").default('pending').notNull(), - processingStartedAt: timestamp("processing_started_at", { mode: 'string' }), - processingCompletedAt: timestamp("processing_completed_at", { mode: 'string' }), - processingError: text("processing_error"), -}, (table) => [ - index("doc_file_hash_idx").using("btree", table.fileHash.asc().nullsLast().op("text_ops")), - index("doc_filename_idx").using("btree", table.filename.asc().nullsLast().op("text_ops")), - index("doc_kb_id_idx").using("btree", table.knowledgeBaseId.asc().nullsLast().op("text_ops")), - index("doc_kb_uploaded_at_idx").using("btree", table.knowledgeBaseId.asc().nullsLast().op("timestamp_ops"), table.uploadedAt.asc().nullsLast().op("timestamp_ops")), - index("doc_processing_status_idx").using("btree", table.knowledgeBaseId.asc().nullsLast().op("text_ops"), table.processingStatus.asc().nullsLast().op("text_ops")), - foreignKey({ - columns: [table.knowledgeBaseId], - foreignColumns: [knowledgeBase.id], - name: "document_knowledge_base_id_knowledge_base_id_fk" - }).onDelete("cascade"), -]); - -export const workflowFolder = pgTable("workflow_folder", { - id: text().primaryKey().notNull(), - name: text().notNull(), - userId: text("user_id").notNull(), - workspaceId: text("workspace_id").notNull(), - parentId: text("parent_id"), - color: text().default('#6B7280'), - isExpanded: boolean("is_expanded").default(true).notNull(), - sortOrder: integer("sort_order").default(0).notNull(), - createdAt: timestamp("created_at", { mode: 'string' }).defaultNow().notNull(), - updatedAt: timestamp("updated_at", { mode: 'string' }).defaultNow().notNull(), -}, (table) => [ - index("workflow_folder_parent_sort_idx").using("btree", table.parentId.asc().nullsLast().op("int4_ops"), table.sortOrder.asc().nullsLast().op("text_ops")), - index("workflow_folder_user_idx").using("btree", table.userId.asc().nullsLast().op("text_ops")), - index("workflow_folder_workspace_parent_idx").using("btree", table.workspaceId.asc().nullsLast().op("text_ops"), table.parentId.asc().nullsLast().op("text_ops")), - foreignKey({ - columns: [table.userId], - foreignColumns: [user.id], - name: "workflow_folder_user_id_user_id_fk" - }).onDelete("cascade"), - foreignKey({ - columns: [table.workspaceId], - foreignColumns: [workspace.id], - name: "workflow_folder_workspace_id_workspace_id_fk" - }).onDelete("cascade"), -]); - -export const embedding = pgTable("embedding", { - id: text().primaryKey().notNull(), - knowledgeBaseId: text("knowledge_base_id").notNull(), - documentId: text("document_id").notNull(), - chunkIndex: integer("chunk_index").notNull(), - chunkHash: text("chunk_hash").notNull(), - content: text().notNull(), - contentLength: integer("content_length").notNull(), - tokenCount: integer("token_count").notNull(), - embedding: vector({ dimensions: 1536 }), - embeddingModel: text("embedding_model").default('text-embedding-3-small').notNull(), - startOffset: integer("start_offset").notNull(), - endOffset: integer("end_offset").notNull(), - overlapTokens: integer("overlap_tokens").default(0).notNull(), - metadata: jsonb().default({}).notNull(), - searchRank: numeric("search_rank").default('1.0'), - accessCount: integer("access_count").default(0).notNull(), - lastAccessedAt: timestamp("last_accessed_at", { mode: 'string' }), - qualityScore: numeric("quality_score"), - createdAt: timestamp("created_at", { mode: 'string' }).defaultNow().notNull(), - updatedAt: timestamp("updated_at", { mode: 'string' }).defaultNow().notNull(), - // TODO: failed to parse database type 'tsvector' - contentTsv: unknown("content_tsv").generatedAlwaysAs(sql`to_tsvector('english'::regconfig, content)`), - enabled: boolean().default(true).notNull(), -}, (table) => [ - index("emb_chunk_hash_idx").using("btree", table.chunkHash.asc().nullsLast().op("text_ops")), - index("emb_content_fts_idx").using("gin", table.contentTsv.asc().nullsLast().op("tsvector_ops")), - uniqueIndex("emb_doc_chunk_idx").using("btree", table.documentId.asc().nullsLast().op("int4_ops"), table.chunkIndex.asc().nullsLast().op("int4_ops")), - index("emb_doc_enabled_idx").using("btree", table.documentId.asc().nullsLast().op("text_ops"), table.enabled.asc().nullsLast().op("bool_ops")), - index("emb_doc_id_idx").using("btree", table.documentId.asc().nullsLast().op("text_ops")), - index("emb_kb_access_idx").using("btree", table.knowledgeBaseId.asc().nullsLast().op("timestamp_ops"), table.lastAccessedAt.asc().nullsLast().op("text_ops")), - index("emb_kb_enabled_idx").using("btree", table.knowledgeBaseId.asc().nullsLast().op("bool_ops"), table.enabled.asc().nullsLast().op("bool_ops")), - index("emb_kb_id_idx").using("btree", table.knowledgeBaseId.asc().nullsLast().op("text_ops")), - index("emb_kb_model_idx").using("btree", table.knowledgeBaseId.asc().nullsLast().op("text_ops"), table.embeddingModel.asc().nullsLast().op("text_ops")), - index("emb_kb_rank_idx").using("btree", table.knowledgeBaseId.asc().nullsLast().op("text_ops"), table.searchRank.asc().nullsLast().op("text_ops")), - index("emb_metadata_gin_idx").using("gin", table.metadata.asc().nullsLast().op("jsonb_ops")), - index("embedding_vector_hnsw_idx").using("hnsw", table.embedding.asc().nullsLast().op("vector_cosine_ops")).with({m: "16",ef_construction: "64"}), - foreignKey({ - columns: [table.knowledgeBaseId], - foreignColumns: [knowledgeBase.id], - name: "embedding_knowledge_base_id_knowledge_base_id_fk" - }).onDelete("cascade"), - foreignKey({ - columns: [table.documentId], - foreignColumns: [document.id], - name: "embedding_document_id_document_id_fk" - }).onDelete("cascade"), - check("embedding_not_null_check", sql`embedding IS NOT NULL`), -]); - -export const workflowBlocks = pgTable("workflow_blocks", { - id: text().primaryKey().notNull(), - workflowId: text("workflow_id").notNull(), - type: text().notNull(), - name: text().notNull(), - positionX: integer("position_x").notNull(), - positionY: integer("position_y").notNull(), - enabled: boolean().default(true).notNull(), - horizontalHandles: boolean("horizontal_handles").default(true).notNull(), - isWide: boolean("is_wide").default(false).notNull(), - height: integer().default(0).notNull(), - subBlocks: jsonb("sub_blocks").default({}).notNull(), - outputs: jsonb().default({}).notNull(), - data: jsonb().default({}), - parentId: text("parent_id"), - extent: text(), - createdAt: timestamp("created_at", { mode: 'string' }).defaultNow().notNull(), - updatedAt: timestamp("updated_at", { mode: 'string' }).defaultNow().notNull(), - deployHash: text("deploy_hash"), -}, (table) => [ - index("workflow_blocks_deploy_hash_idx").using("btree", table.deployHash.asc().nullsLast().op("text_ops")), - index("workflow_blocks_parent_id_idx").using("btree", table.parentId.asc().nullsLast().op("text_ops")), - index("workflow_blocks_workflow_deploy_idx").using("btree", table.workflowId.asc().nullsLast().op("text_ops"), table.deployHash.asc().nullsLast().op("text_ops")), - index("workflow_blocks_workflow_id_idx").using("btree", table.workflowId.asc().nullsLast().op("text_ops")), - index("workflow_blocks_workflow_parent_idx").using("btree", table.workflowId.asc().nullsLast().op("text_ops"), table.parentId.asc().nullsLast().op("text_ops")), - index("workflow_blocks_workflow_type_idx").using("btree", table.workflowId.asc().nullsLast().op("text_ops"), table.type.asc().nullsLast().op("text_ops")), - foreignKey({ - columns: [table.workflowId], - foreignColumns: [workflow.id], - name: "workflow_blocks_workflow_id_workflow_id_fk" - }).onDelete("cascade"), - foreignKey({ - columns: [table.parentId], - foreignColumns: [table.id], - name: "workflow_blocks_parent_id_workflow_blocks_id_fk" - }).onDelete("cascade"), -]); - -export const workflowEdges = pgTable("workflow_edges", { - id: text().primaryKey().notNull(), - workflowId: text("workflow_id").notNull(), - sourceBlockId: text("source_block_id").notNull(), - targetBlockId: text("target_block_id").notNull(), - sourceHandle: text("source_handle"), - targetHandle: text("target_handle"), - createdAt: timestamp("created_at", { mode: 'string' }).defaultNow().notNull(), - deployHash: text("deploy_hash"), -}, (table) => [ - index("workflow_edges_deploy_hash_idx").using("btree", table.deployHash.asc().nullsLast().op("text_ops")), - index("workflow_edges_source_block_idx").using("btree", table.sourceBlockId.asc().nullsLast().op("text_ops")), - index("workflow_edges_target_block_idx").using("btree", table.targetBlockId.asc().nullsLast().op("text_ops")), - index("workflow_edges_workflow_deploy_idx").using("btree", table.workflowId.asc().nullsLast().op("text_ops"), table.deployHash.asc().nullsLast().op("text_ops")), - index("workflow_edges_workflow_id_idx").using("btree", table.workflowId.asc().nullsLast().op("text_ops")), - index("workflow_edges_workflow_source_idx").using("btree", table.workflowId.asc().nullsLast().op("text_ops"), table.sourceBlockId.asc().nullsLast().op("text_ops")), - index("workflow_edges_workflow_target_idx").using("btree", table.workflowId.asc().nullsLast().op("text_ops"), table.targetBlockId.asc().nullsLast().op("text_ops")), - foreignKey({ - columns: [table.workflowId], - foreignColumns: [workflow.id], - name: "workflow_edges_workflow_id_workflow_id_fk" - }).onDelete("cascade"), - foreignKey({ - columns: [table.sourceBlockId], - foreignColumns: [workflowBlocks.id], - name: "workflow_edges_source_block_id_workflow_blocks_id_fk" - }).onDelete("cascade"), - foreignKey({ - columns: [table.targetBlockId], - foreignColumns: [workflowBlocks.id], - name: "workflow_edges_target_block_id_workflow_blocks_id_fk" - }).onDelete("cascade"), -]); - -export const workflowSubflows = pgTable("workflow_subflows", { - id: text().primaryKey().notNull(), - workflowId: text("workflow_id").notNull(), - type: text().notNull(), - config: jsonb().default({}).notNull(), - createdAt: timestamp("created_at", { mode: 'string' }).defaultNow().notNull(), - updatedAt: timestamp("updated_at", { mode: 'string' }).defaultNow().notNull(), - deployHash: text("deploy_hash"), -}, (table) => [ - index("workflow_subflows_deploy_hash_idx").using("btree", table.deployHash.asc().nullsLast().op("text_ops")), - index("workflow_subflows_workflow_deploy_idx").using("btree", table.workflowId.asc().nullsLast().op("text_ops"), table.deployHash.asc().nullsLast().op("text_ops")), - index("workflow_subflows_workflow_id_idx").using("btree", table.workflowId.asc().nullsLast().op("text_ops")), - index("workflow_subflows_workflow_type_idx").using("btree", table.workflowId.asc().nullsLast().op("text_ops"), table.type.asc().nullsLast().op("text_ops")), - foreignKey({ - columns: [table.workflowId], - foreignColumns: [workflow.id], - name: "workflow_subflows_workflow_id_workflow_id_fk" - }).onDelete("cascade"), -]);