From b8ad52cf283ca0d507e73b8828e343f2888896e4 Mon Sep 17 00:00:00 2001 From: dal Date: Tue, 5 Aug 2025 11:38:43 -0600 Subject: [PATCH] change the schema content to be text for markdown streaming --- .../drizzle/0088_puzzling_vanisher.sql | 3 + .../database/drizzle/meta/0088_snapshot.json | 6827 +++++++++++++++++ packages/database/drizzle/meta/_journal.json | 7 + packages/database/src/schema.ts | 4075 +++++----- 4 files changed, 8912 insertions(+), 2000 deletions(-) create mode 100644 packages/database/drizzle/0088_puzzling_vanisher.sql create mode 100644 packages/database/drizzle/meta/0088_snapshot.json diff --git a/packages/database/drizzle/0088_puzzling_vanisher.sql b/packages/database/drizzle/0088_puzzling_vanisher.sql new file mode 100644 index 000000000..22e1d1bd9 --- /dev/null +++ b/packages/database/drizzle/0088_puzzling_vanisher.sql @@ -0,0 +1,3 @@ +ALTER TABLE "asset_search" ALTER COLUMN "asset_type" SET DATA TYPE text;--> statement-breakpoint +ALTER TABLE "dashboard_files" ALTER COLUMN "content" SET DEFAULT '[]'::jsonb;--> statement-breakpoint +ALTER TABLE "report_files" ALTER COLUMN "content" SET DATA TYPE text; \ No newline at end of file diff --git a/packages/database/drizzle/meta/0088_snapshot.json b/packages/database/drizzle/meta/0088_snapshot.json new file mode 100644 index 000000000..cca9ece4f --- /dev/null +++ b/packages/database/drizzle/meta/0088_snapshot.json @@ -0,0 +1,6827 @@ +{ + "id": "b39ccd38-6fd3-4358-95f5-40518f16c150", + "prevId": "3e249e77-9b1c-4ee4-8361-d495ed88a57b", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.api_keys": { + "name": "api_keys", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "owner_id": { + "name": "owner_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "key": { + "name": "key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "api_keys_organization_id_fkey": { + "name": "api_keys_organization_id_fkey", + "tableFrom": "api_keys", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "api_keys_owner_id_fkey": { + "name": "api_keys_owner_id_fkey", + "tableFrom": "api_keys", + "tableTo": "users", + "columnsFrom": [ + "owner_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "api_keys_key_key": { + "name": "api_keys_key_key", + "nullsNotDistinct": false, + "columns": [ + "key" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.asset_permissions": { + "name": "asset_permissions", + "schema": "", + "columns": { + "identity_id": { + "name": "identity_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "identity_type": { + "name": "identity_type", + "type": "identity_type_enum", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "asset_id": { + "name": "asset_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "asset_type": { + "name": "asset_type", + "type": "asset_type_enum", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "role": { + "name": "role", + "type": "asset_permission_role_enum", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "updated_by": { + "name": "updated_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "asset_permissions_created_by_fkey": { + "name": "asset_permissions_created_by_fkey", + "tableFrom": "asset_permissions", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "cascade" + }, + "asset_permissions_updated_by_fkey": { + "name": "asset_permissions_updated_by_fkey", + "tableFrom": "asset_permissions", + "tableTo": "users", + "columnsFrom": [ + "updated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": { + "asset_permissions_pkey": { + "name": "asset_permissions_pkey", + "columns": [ + "identity_id", + "identity_type", + "asset_id", + "asset_type" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.asset_search": { + "name": "asset_search", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "asset_id": { + "name": "asset_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "asset_type": { + "name": "asset_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "content": { + "name": "content", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "asset_search_asset_id_asset_type_idx": { + "name": "asset_search_asset_id_asset_type_idx", + "columns": [ + { + "expression": "asset_id", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "text_ops" + }, + { + "expression": "asset_type", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "text_ops" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "pgroonga_content_index": { + "name": "pgroonga_content_index", + "columns": [ + { + "expression": "content", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "pgroonga_text_full_text_search_ops_v2" + } + ], + "isUnique": false, + "concurrently": false, + "method": "pgroonga", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.chats": { + "name": "chats", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "updated_by": { + "name": "updated_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "publicly_accessible": { + "name": "publicly_accessible", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "publicly_enabled_by": { + "name": "publicly_enabled_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "public_expiry_date": { + "name": "public_expiry_date", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "most_recent_file_id": { + "name": "most_recent_file_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "most_recent_file_type": { + "name": "most_recent_file_type", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "most_recent_version_number": { + "name": "most_recent_version_number", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "slack_chat_authorization": { + "name": "slack_chat_authorization", + "type": "slack_chat_authorization_enum", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "slack_thread_ts": { + "name": "slack_thread_ts", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "slack_channel_id": { + "name": "slack_channel_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "workspace_sharing": { + "name": "workspace_sharing", + "type": "workspace_sharing_enum", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'none'" + }, + "workspace_sharing_enabled_by": { + "name": "workspace_sharing_enabled_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "workspace_sharing_enabled_at": { + "name": "workspace_sharing_enabled_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "chats_created_at_idx": { + "name": "chats_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "timestamptz_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "chats_created_by_idx": { + "name": "chats_created_by_idx", + "columns": [ + { + "expression": "created_by", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "uuid_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "chats_organization_id_idx": { + "name": "chats_organization_id_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "uuid_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_chats_most_recent_file_id": { + "name": "idx_chats_most_recent_file_id", + "columns": [ + { + "expression": "most_recent_file_id", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "uuid_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_chats_most_recent_file_type": { + "name": "idx_chats_most_recent_file_type", + "columns": [ + { + "expression": "most_recent_file_type", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "text_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "chats_organization_id_fkey": { + "name": "chats_organization_id_fkey", + "tableFrom": "chats", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "chats_created_by_fkey": { + "name": "chats_created_by_fkey", + "tableFrom": "chats", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "cascade" + }, + "chats_updated_by_fkey": { + "name": "chats_updated_by_fkey", + "tableFrom": "chats", + "tableTo": "users", + "columnsFrom": [ + "updated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "cascade" + }, + "chats_publicly_enabled_by_fkey": { + "name": "chats_publicly_enabled_by_fkey", + "tableFrom": "chats", + "tableTo": "users", + "columnsFrom": [ + "publicly_enabled_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "cascade" + }, + "chats_workspace_sharing_enabled_by_fkey": { + "name": "chats_workspace_sharing_enabled_by_fkey", + "tableFrom": "chats", + "tableTo": "users", + "columnsFrom": [ + "workspace_sharing_enabled_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.collections": { + "name": "collections", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "updated_by": { + "name": "updated_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "workspace_sharing": { + "name": "workspace_sharing", + "type": "workspace_sharing_enum", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'none'" + }, + "workspace_sharing_enabled_by": { + "name": "workspace_sharing_enabled_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "workspace_sharing_enabled_at": { + "name": "workspace_sharing_enabled_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "collections_organization_id_fkey": { + "name": "collections_organization_id_fkey", + "tableFrom": "collections", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "cascade" + }, + "collections_created_by_fkey": { + "name": "collections_created_by_fkey", + "tableFrom": "collections", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "cascade" + }, + "collections_updated_by_fkey": { + "name": "collections_updated_by_fkey", + "tableFrom": "collections", + "tableTo": "users", + "columnsFrom": [ + "updated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "cascade" + }, + "collections_workspace_sharing_enabled_by_fkey": { + "name": "collections_workspace_sharing_enabled_by_fkey", + "tableFrom": "collections", + "tableTo": "users", + "columnsFrom": [ + "workspace_sharing_enabled_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.collections_to_assets": { + "name": "collections_to_assets", + "schema": "", + "columns": { + "collection_id": { + "name": "collection_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "asset_id": { + "name": "asset_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "asset_type": { + "name": "asset_type", + "type": "asset_type_enum", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "updated_by": { + "name": "updated_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "collections_to_assets_created_by_fkey": { + "name": "collections_to_assets_created_by_fkey", + "tableFrom": "collections_to_assets", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "cascade" + }, + "collections_to_assets_updated_by_fkey": { + "name": "collections_to_assets_updated_by_fkey", + "tableFrom": "collections_to_assets", + "tableTo": "users", + "columnsFrom": [ + "updated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": { + "collections_to_assets_pkey": { + "name": "collections_to_assets_pkey", + "columns": [ + "collection_id", + "asset_id", + "asset_type" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.dashboard_files": { + "name": "dashboard_files", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "name": { + "name": "name", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "file_name": { + "name": "file_name", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "content": { + "name": "content", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "filter": { + "name": "filter", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "publicly_accessible": { + "name": "publicly_accessible", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "publicly_enabled_by": { + "name": "publicly_enabled_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "public_expiry_date": { + "name": "public_expiry_date", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "version_history": { + "name": "version_history", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "public_password": { + "name": "public_password", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "workspace_sharing": { + "name": "workspace_sharing", + "type": "workspace_sharing_enum", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'none'" + }, + "workspace_sharing_enabled_by": { + "name": "workspace_sharing_enabled_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "workspace_sharing_enabled_at": { + "name": "workspace_sharing_enabled_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "dashboard_files_created_by_idx": { + "name": "dashboard_files_created_by_idx", + "columns": [ + { + "expression": "created_by", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "uuid_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "dashboard_files_deleted_at_idx": { + "name": "dashboard_files_deleted_at_idx", + "columns": [ + { + "expression": "deleted_at", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "timestamptz_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "dashboard_files_organization_id_idx": { + "name": "dashboard_files_organization_id_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "uuid_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "dashboard_files_created_by_fkey": { + "name": "dashboard_files_created_by_fkey", + "tableFrom": "dashboard_files", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "cascade" + }, + "dashboard_files_publicly_enabled_by_fkey": { + "name": "dashboard_files_publicly_enabled_by_fkey", + "tableFrom": "dashboard_files", + "tableTo": "users", + "columnsFrom": [ + "publicly_enabled_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "cascade" + }, + "dashboard_files_workspace_sharing_enabled_by_fkey": { + "name": "dashboard_files_workspace_sharing_enabled_by_fkey", + "tableFrom": "dashboard_files", + "tableTo": "users", + "columnsFrom": [ + "workspace_sharing_enabled_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.dashboard_versions": { + "name": "dashboard_versions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "dashboard_id": { + "name": "dashboard_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "config": { + "name": "config", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "dashboard_versions_dashboard_id_fkey": { + "name": "dashboard_versions_dashboard_id_fkey", + "tableFrom": "dashboard_versions", + "tableTo": "dashboards", + "columnsFrom": [ + "dashboard_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.dashboards": { + "name": "dashboards", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "config": { + "name": "config", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "publicly_accessible": { + "name": "publicly_accessible", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "publicly_enabled_by": { + "name": "publicly_enabled_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "public_expiry_date": { + "name": "public_expiry_date", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "password_secret_id": { + "name": "password_secret_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "updated_by": { + "name": "updated_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "dashboards_publicly_enabled_by_fkey": { + "name": "dashboards_publicly_enabled_by_fkey", + "tableFrom": "dashboards", + "tableTo": "users", + "columnsFrom": [ + "publicly_enabled_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "cascade" + }, + "dashboards_organization_id_fkey": { + "name": "dashboards_organization_id_fkey", + "tableFrom": "dashboards", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "cascade" + }, + "dashboards_created_by_fkey": { + "name": "dashboards_created_by_fkey", + "tableFrom": "dashboards", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "cascade" + }, + "dashboards_updated_by_fkey": { + "name": "dashboards_updated_by_fkey", + "tableFrom": "dashboards", + "tableTo": "users", + "columnsFrom": [ + "updated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.data_sources": { + "name": "data_sources", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "secret_id": { + "name": "secret_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "onboarding_status": { + "name": "onboarding_status", + "type": "data_source_onboarding_status_enum", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'notStarted'" + }, + "onboarding_error": { + "name": "onboarding_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "updated_by": { + "name": "updated_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "env": { + "name": "env", + "type": "varchar", + "primaryKey": false, + "notNull": true, + "default": "'dev'" + } + }, + "indexes": {}, + "foreignKeys": { + "data_sources_organization_id_fkey": { + "name": "data_sources_organization_id_fkey", + "tableFrom": "data_sources", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "data_sources_created_by_fkey": { + "name": "data_sources_created_by_fkey", + "tableFrom": "data_sources", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "cascade" + }, + "data_sources_updated_by_fkey": { + "name": "data_sources_updated_by_fkey", + "tableFrom": "data_sources", + "tableTo": "users", + "columnsFrom": [ + "updated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "data_sources_name_organization_id_env_key": { + "name": "data_sources_name_organization_id_env_key", + "nullsNotDistinct": false, + "columns": [ + "name", + "organization_id", + "env" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.database_metadata": { + "name": "database_metadata", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "data_source_id": { + "name": "data_source_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "owner": { + "name": "owner", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "comment": { + "name": "comment", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created": { + "name": "created", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "last_modified": { + "name": "last_modified", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "database_metadata_data_source_id_idx": { + "name": "database_metadata_data_source_id_idx", + "columns": [ + { + "expression": "data_source_id", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "uuid_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "database_metadata_data_source_id_fkey": { + "name": "database_metadata_data_source_id_fkey", + "tableFrom": "database_metadata", + "tableTo": "data_sources", + "columnsFrom": [ + "data_source_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "database_metadata_data_source_id_name_key": { + "name": "database_metadata_data_source_id_name_key", + "nullsNotDistinct": false, + "columns": [ + "data_source_id", + "name" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.dataset_columns": { + "name": "dataset_columns", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "dataset_id": { + "name": "dataset_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "nullable": { + "name": "nullable", + "type": "boolean", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "stored_values": { + "name": "stored_values", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "stored_values_status": { + "name": "stored_values_status", + "type": "stored_values_status_enum", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "stored_values_error": { + "name": "stored_values_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "stored_values_count": { + "name": "stored_values_count", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "stored_values_last_synced": { + "name": "stored_values_last_synced", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "semantic_type": { + "name": "semantic_type", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "dim_type": { + "name": "dim_type", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "expr": { + "name": "expr", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "unique_dataset_column_name": { + "name": "unique_dataset_column_name", + "nullsNotDistinct": false, + "columns": [ + "dataset_id", + "name" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.dataset_groups": { + "name": "dataset_groups", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "dataset_groups_deleted_at_idx": { + "name": "dataset_groups_deleted_at_idx", + "columns": [ + { + "expression": "deleted_at", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "timestamptz_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "dataset_groups_organization_id_idx": { + "name": "dataset_groups_organization_id_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "uuid_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "dataset_groups_organization_id_fkey": { + "name": "dataset_groups_organization_id_fkey", + "tableFrom": "dataset_groups", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": { + "dataset_groups_policy": { + "name": "dataset_groups_policy", + "as": "PERMISSIVE", + "for": "ALL", + "to": [ + "authenticated" + ], + "using": "true" + } + }, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.dataset_groups_permissions": { + "name": "dataset_groups_permissions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "dataset_group_id": { + "name": "dataset_group_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "permission_id": { + "name": "permission_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "permission_type": { + "name": "permission_type", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "dataset_groups_permissions_dataset_group_id_idx": { + "name": "dataset_groups_permissions_dataset_group_id_idx", + "columns": [ + { + "expression": "dataset_group_id", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "uuid_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "dataset_groups_permissions_organization_id_idx": { + "name": "dataset_groups_permissions_organization_id_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "uuid_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "dataset_groups_permissions_permission_id_idx": { + "name": "dataset_groups_permissions_permission_id_idx", + "columns": [ + { + "expression": "permission_id", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "uuid_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "dataset_groups_permissions_dataset_group_id_fkey": { + "name": "dataset_groups_permissions_dataset_group_id_fkey", + "tableFrom": "dataset_groups_permissions", + "tableTo": "dataset_groups", + "columnsFrom": [ + "dataset_group_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "dataset_groups_permissions_organization_id_fkey": { + "name": "dataset_groups_permissions_organization_id_fkey", + "tableFrom": "dataset_groups_permissions", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "unique_dataset_group_permission": { + "name": "unique_dataset_group_permission", + "nullsNotDistinct": false, + "columns": [ + "dataset_group_id", + "permission_id", + "permission_type" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.dataset_permissions": { + "name": "dataset_permissions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "dataset_id": { + "name": "dataset_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "permission_id": { + "name": "permission_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "permission_type": { + "name": "permission_type", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "dataset_permissions_dataset_id_idx": { + "name": "dataset_permissions_dataset_id_idx", + "columns": [ + { + "expression": "dataset_id", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "uuid_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "dataset_permissions_deleted_at_idx": { + "name": "dataset_permissions_deleted_at_idx", + "columns": [ + { + "expression": "deleted_at", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "timestamptz_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "dataset_permissions_organization_id_idx": { + "name": "dataset_permissions_organization_id_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "uuid_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "dataset_permissions_permission_lookup_idx": { + "name": "dataset_permissions_permission_lookup_idx", + "columns": [ + { + "expression": "permission_id", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "uuid_ops" + }, + { + "expression": "permission_type", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "text_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "dataset_permissions_organization_id_fkey": { + "name": "dataset_permissions_organization_id_fkey", + "tableFrom": "dataset_permissions", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "dataset_permissions_dataset_id_fkey": { + "name": "dataset_permissions_dataset_id_fkey", + "tableFrom": "dataset_permissions", + "tableTo": "datasets", + "columnsFrom": [ + "dataset_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "dataset_permissions_dataset_id_permission_id_permission_typ_key": { + "name": "dataset_permissions_dataset_id_permission_id_permission_typ_key", + "nullsNotDistinct": false, + "columns": [ + "dataset_id", + "permission_id", + "permission_type" + ] + } + }, + "policies": { + "dataset_permissions_policy": { + "name": "dataset_permissions_policy", + "as": "PERMISSIVE", + "for": "ALL", + "to": [ + "authenticated" + ], + "using": "true" + } + }, + "checkConstraints": { + "dataset_permissions_permission_type_check": { + "name": "dataset_permissions_permission_type_check", + "value": "(permission_type)::text = ANY ((ARRAY['user'::character varying, 'dataset_group'::character varying, 'permission_group'::character varying])::text[])" + } + }, + "isRLSEnabled": false + }, + "public.datasets": { + "name": "datasets", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "database_name": { + "name": "database_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "when_to_use": { + "name": "when_to_use", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "when_not_to_use": { + "name": "when_not_to_use", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "type": { + "name": "type", + "type": "dataset_type_enum", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "definition": { + "name": "definition", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "schema": { + "name": "schema", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "enabled": { + "name": "enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "imported": { + "name": "imported", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "data_source_id": { + "name": "data_source_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "updated_by": { + "name": "updated_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "model": { + "name": "model", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "yml_file": { + "name": "yml_file", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "database_identifier": { + "name": "database_identifier", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "datasets_data_source_id_fkey": { + "name": "datasets_data_source_id_fkey", + "tableFrom": "datasets", + "tableTo": "data_sources", + "columnsFrom": [ + "data_source_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "datasets_organization_id_fkey": { + "name": "datasets_organization_id_fkey", + "tableFrom": "datasets", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "datasets_created_by_fkey": { + "name": "datasets_created_by_fkey", + "tableFrom": "datasets", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "cascade" + }, + "datasets_updated_by_fkey": { + "name": "datasets_updated_by_fkey", + "tableFrom": "datasets", + "tableTo": "users", + "columnsFrom": [ + "updated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "datasets_database_name_data_source_id_key": { + "name": "datasets_database_name_data_source_id_key", + "nullsNotDistinct": false, + "columns": [ + "database_name", + "data_source_id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.datasets_to_dataset_groups": { + "name": "datasets_to_dataset_groups", + "schema": "", + "columns": { + "dataset_id": { + "name": "dataset_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "dataset_group_id": { + "name": "dataset_group_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "datasets_to_dataset_groups_dataset_group_id_idx": { + "name": "datasets_to_dataset_groups_dataset_group_id_idx", + "columns": [ + { + "expression": "dataset_group_id", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "uuid_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "datasets_to_dataset_groups_dataset_id_fkey": { + "name": "datasets_to_dataset_groups_dataset_id_fkey", + "tableFrom": "datasets_to_dataset_groups", + "tableTo": "datasets", + "columnsFrom": [ + "dataset_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "datasets_to_dataset_groups_dataset_group_id_fkey": { + "name": "datasets_to_dataset_groups_dataset_group_id_fkey", + "tableFrom": "datasets_to_dataset_groups", + "tableTo": "dataset_groups", + "columnsFrom": [ + "dataset_group_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "datasets_to_dataset_groups_pkey": { + "name": "datasets_to_dataset_groups_pkey", + "columns": [ + "dataset_id", + "dataset_group_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": { + "datasets_to_dataset_groups_policy": { + "name": "datasets_to_dataset_groups_policy", + "as": "PERMISSIVE", + "for": "ALL", + "to": [ + "authenticated" + ], + "using": "true" + } + }, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.datasets_to_permission_groups": { + "name": "datasets_to_permission_groups", + "schema": "", + "columns": { + "dataset_id": { + "name": "dataset_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "permission_group_id": { + "name": "permission_group_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "datasets_to_permission_groups_dataset_id_fkey": { + "name": "datasets_to_permission_groups_dataset_id_fkey", + "tableFrom": "datasets_to_permission_groups", + "tableTo": "datasets", + "columnsFrom": [ + "dataset_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "datasets_to_permission_groups_permission_group_id_fkey": { + "name": "datasets_to_permission_groups_permission_group_id_fkey", + "tableFrom": "datasets_to_permission_groups", + "tableTo": "permission_groups", + "columnsFrom": [ + "permission_group_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "datasets_to_permission_groups_pkey": { + "name": "datasets_to_permission_groups_pkey", + "columns": [ + "dataset_id", + "permission_group_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": { + "datasets_to_permission_groups_policy": { + "name": "datasets_to_permission_groups_policy", + "as": "PERMISSIVE", + "for": "ALL", + "to": [ + "authenticated" + ], + "using": "true" + } + }, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.__diesel_schema_migrations": { + "name": "__diesel_schema_migrations", + "schema": "", + "columns": { + "version": { + "name": "version", + "type": "varchar(50)", + "primaryKey": true, + "notNull": true + }, + "run_on": { + "name": "run_on", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": { + "diesel_schema_migrations_policy": { + "name": "diesel_schema_migrations_policy", + "as": "PERMISSIVE", + "for": "ALL", + "to": [ + "authenticated" + ], + "using": "true" + } + }, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.entity_relationship": { + "name": "entity_relationship", + "schema": "", + "columns": { + "primary_dataset_id": { + "name": "primary_dataset_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "foreign_dataset_id": { + "name": "foreign_dataset_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "relationship_type": { + "name": "relationship_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": { + "entity_relationship_pkey": { + "name": "entity_relationship_pkey", + "columns": [ + "primary_dataset_id", + "foreign_dataset_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.github_integrations": { + "name": "github_integrations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "installation_id": { + "name": "installation_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "app_id": { + "name": "app_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "github_org_id": { + "name": "github_org_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "github_org_name": { + "name": "github_org_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "token_vault_key": { + "name": "token_vault_key", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "webhook_secret_vault_key": { + "name": "webhook_secret_vault_key", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "repository_permissions": { + "name": "repository_permissions", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'{}'::jsonb" + }, + "status": { + "name": "status", + "type": "github_integration_status_enum", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "installed_at": { + "name": "installed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "last_used_at": { + "name": "last_used_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "idx_github_integrations_org_id": { + "name": "idx_github_integrations_org_id", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "uuid_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_github_integrations_installation_id": { + "name": "idx_github_integrations_installation_id", + "columns": [ + { + "expression": "installation_id", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "text_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_github_integrations_github_org_id": { + "name": "idx_github_integrations_github_org_id", + "columns": [ + { + "expression": "github_org_id", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "text_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "github_integrations_organization_id_fkey": { + "name": "github_integrations_organization_id_fkey", + "tableFrom": "github_integrations", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "github_integrations_user_id_fkey": { + "name": "github_integrations_user_id_fkey", + "tableFrom": "github_integrations", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "github_integrations_token_vault_key_unique": { + "name": "github_integrations_token_vault_key_unique", + "nullsNotDistinct": false, + "columns": [ + "token_vault_key" + ] + }, + "github_integrations_org_installation_key": { + "name": "github_integrations_org_installation_key", + "nullsNotDistinct": false, + "columns": [ + "organization_id", + "installation_id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.messages": { + "name": "messages", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "request_message": { + "name": "request_message", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "response_messages": { + "name": "response_messages", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "reasoning": { + "name": "reasoning", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "raw_llm_messages": { + "name": "raw_llm_messages", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "final_reasoning_message": { + "name": "final_reasoning_message", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "chat_id": { + "name": "chat_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "feedback": { + "name": "feedback", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "is_completed": { + "name": "is_completed", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "post_processing_message": { + "name": "post_processing_message", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "trigger_run_id": { + "name": "trigger_run_id", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "messages_chat_id_idx": { + "name": "messages_chat_id_idx", + "columns": [ + { + "expression": "chat_id", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "uuid_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "messages_created_at_idx": { + "name": "messages_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "timestamptz_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "messages_created_by_idx": { + "name": "messages_created_by_idx", + "columns": [ + { + "expression": "created_by", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "uuid_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "messages_chat_id_fkey": { + "name": "messages_chat_id_fkey", + "tableFrom": "messages", + "tableTo": "chats", + "columnsFrom": [ + "chat_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "messages_created_by_fkey": { + "name": "messages_created_by_fkey", + "tableFrom": "messages", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.messages_deprecated": { + "name": "messages_deprecated", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "thread_id": { + "name": "thread_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "sent_by": { + "name": "sent_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "message": { + "name": "message", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "responses": { + "name": "responses", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "code": { + "name": "code", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "context": { + "name": "context", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "feedback": { + "name": "feedback", + "type": "message_feedback_enum", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "verification": { + "name": "verification", + "type": "verification_enum", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'notRequested'" + }, + "dataset_id": { + "name": "dataset_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "chart_config": { + "name": "chart_config", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'{}'::jsonb" + }, + "chart_recommendations": { + "name": "chart_recommendations", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'{}'::jsonb" + }, + "time_frame": { + "name": "time_frame", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "data_metadata": { + "name": "data_metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "draft_session_id": { + "name": "draft_session_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "draft_state": { + "name": "draft_state", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "summary_question": { + "name": "summary_question", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "sql_evaluation_id": { + "name": "sql_evaluation_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "messages_sent_by_fkey": { + "name": "messages_sent_by_fkey", + "tableFrom": "messages_deprecated", + "tableTo": "users", + "columnsFrom": [ + "sent_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "cascade" + }, + "messages_dataset_id_fkey": { + "name": "messages_dataset_id_fkey", + "tableFrom": "messages_deprecated", + "tableTo": "datasets", + "columnsFrom": [ + "dataset_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "messages_deprecated_sent_by_fkey": { + "name": "messages_deprecated_sent_by_fkey", + "tableFrom": "messages_deprecated", + "tableTo": "users", + "columnsFrom": [ + "sent_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.messages_to_files": { + "name": "messages_to_files", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "message_id": { + "name": "message_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "file_id": { + "name": "file_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "is_duplicate": { + "name": "is_duplicate", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "version_number": { + "name": "version_number", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + } + }, + "indexes": { + "messages_files_file_id_idx": { + "name": "messages_files_file_id_idx", + "columns": [ + { + "expression": "file_id", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "uuid_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "messages_files_message_id_idx": { + "name": "messages_files_message_id_idx", + "columns": [ + { + "expression": "message_id", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "uuid_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "messages_to_files_message_id_fkey": { + "name": "messages_to_files_message_id_fkey", + "tableFrom": "messages_to_files", + "tableTo": "messages", + "columnsFrom": [ + "message_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "messages_to_files_message_id_file_id_key": { + "name": "messages_to_files_message_id_file_id_key", + "nullsNotDistinct": false, + "columns": [ + "message_id", + "file_id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.messages_to_slack_messages": { + "name": "messages_to_slack_messages", + "schema": "", + "columns": { + "message_id": { + "name": "message_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "slack_message_id": { + "name": "slack_message_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "messages_to_slack_messages_message_id_idx": { + "name": "messages_to_slack_messages_message_id_idx", + "columns": [ + { + "expression": "message_id", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "uuid_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "messages_to_slack_messages_slack_message_id_idx": { + "name": "messages_to_slack_messages_slack_message_id_idx", + "columns": [ + { + "expression": "slack_message_id", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "uuid_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "messages_to_slack_messages_message_id_fkey": { + "name": "messages_to_slack_messages_message_id_fkey", + "tableFrom": "messages_to_slack_messages", + "tableTo": "messages", + "columnsFrom": [ + "message_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "messages_to_slack_messages_slack_message_id_fkey": { + "name": "messages_to_slack_messages_slack_message_id_fkey", + "tableFrom": "messages_to_slack_messages", + "tableTo": "slack_message_tracking", + "columnsFrom": [ + "slack_message_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "messages_to_slack_messages_pkey": { + "name": "messages_to_slack_messages_pkey", + "columns": [ + "message_id", + "slack_message_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.metric_files": { + "name": "metric_files", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "name": { + "name": "name", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "file_name": { + "name": "file_name", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "content": { + "name": "content", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "verification": { + "name": "verification", + "type": "verification_enum", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'notRequested'" + }, + "evaluation_obj": { + "name": "evaluation_obj", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "evaluation_summary": { + "name": "evaluation_summary", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "evaluation_score": { + "name": "evaluation_score", + "type": "double precision", + "primaryKey": false, + "notNull": false + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "publicly_accessible": { + "name": "publicly_accessible", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "publicly_enabled_by": { + "name": "publicly_enabled_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "public_expiry_date": { + "name": "public_expiry_date", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "version_history": { + "name": "version_history", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "data_metadata": { + "name": "data_metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "public_password": { + "name": "public_password", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "data_source_id": { + "name": "data_source_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "workspace_sharing": { + "name": "workspace_sharing", + "type": "workspace_sharing_enum", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'none'" + }, + "workspace_sharing_enabled_by": { + "name": "workspace_sharing_enabled_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "workspace_sharing_enabled_at": { + "name": "workspace_sharing_enabled_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "metric_files_created_by_idx": { + "name": "metric_files_created_by_idx", + "columns": [ + { + "expression": "created_by", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "uuid_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "metric_files_data_metadata_idx": { + "name": "metric_files_data_metadata_idx", + "columns": [ + { + "expression": "data_metadata", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "jsonb_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "gin", + "with": {} + }, + "metric_files_deleted_at_idx": { + "name": "metric_files_deleted_at_idx", + "columns": [ + { + "expression": "deleted_at", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "timestamptz_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "metric_files_organization_id_idx": { + "name": "metric_files_organization_id_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "uuid_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "metric_files_created_by_fkey": { + "name": "metric_files_created_by_fkey", + "tableFrom": "metric_files", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "cascade" + }, + "metric_files_publicly_enabled_by_fkey": { + "name": "metric_files_publicly_enabled_by_fkey", + "tableFrom": "metric_files", + "tableTo": "users", + "columnsFrom": [ + "publicly_enabled_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "cascade" + }, + "fk_data_source": { + "name": "fk_data_source", + "tableFrom": "metric_files", + "tableTo": "data_sources", + "columnsFrom": [ + "data_source_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "metric_files_workspace_sharing_enabled_by_fkey": { + "name": "metric_files_workspace_sharing_enabled_by_fkey", + "tableFrom": "metric_files", + "tableTo": "users", + "columnsFrom": [ + "workspace_sharing_enabled_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.metric_files_to_dashboard_files": { + "name": "metric_files_to_dashboard_files", + "schema": "", + "columns": { + "metric_file_id": { + "name": "metric_file_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "dashboard_file_id": { + "name": "dashboard_file_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "metric_files_to_dashboard_files_dashboard_id_idx": { + "name": "metric_files_to_dashboard_files_dashboard_id_idx", + "columns": [ + { + "expression": "dashboard_file_id", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "uuid_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "metric_files_to_dashboard_files_deleted_at_idx": { + "name": "metric_files_to_dashboard_files_deleted_at_idx", + "columns": [ + { + "expression": "deleted_at", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "timestamptz_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "metric_files_to_dashboard_files_metric_id_idx": { + "name": "metric_files_to_dashboard_files_metric_id_idx", + "columns": [ + { + "expression": "metric_file_id", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "uuid_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "metric_files_to_dashboard_files_metric_file_id_fkey": { + "name": "metric_files_to_dashboard_files_metric_file_id_fkey", + "tableFrom": "metric_files_to_dashboard_files", + "tableTo": "metric_files", + "columnsFrom": [ + "metric_file_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "metric_files_to_dashboard_files_dashboard_file_id_fkey": { + "name": "metric_files_to_dashboard_files_dashboard_file_id_fkey", + "tableFrom": "metric_files_to_dashboard_files", + "tableTo": "dashboard_files", + "columnsFrom": [ + "dashboard_file_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "metric_files_to_dashboard_files_created_by_fkey": { + "name": "metric_files_to_dashboard_files_created_by_fkey", + "tableFrom": "metric_files_to_dashboard_files", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": { + "metric_files_to_dashboard_files_pkey": { + "name": "metric_files_to_dashboard_files_pkey", + "columns": [ + "metric_file_id", + "dashboard_file_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.metric_files_to_datasets": { + "name": "metric_files_to_datasets", + "schema": "", + "columns": { + "metric_file_id": { + "name": "metric_file_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "dataset_id": { + "name": "dataset_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "metric_version_number": { + "name": "metric_version_number", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "fk_metric_file": { + "name": "fk_metric_file", + "tableFrom": "metric_files_to_datasets", + "tableTo": "metric_files", + "columnsFrom": [ + "metric_file_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "fk_dataset": { + "name": "fk_dataset", + "tableFrom": "metric_files_to_datasets", + "tableTo": "datasets", + "columnsFrom": [ + "dataset_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "metric_files_to_datasets_pkey": { + "name": "metric_files_to_datasets_pkey", + "columns": [ + "metric_file_id", + "dataset_id", + "metric_version_number" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.organizations": { + "name": "organizations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "domain": { + "name": "domain", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "payment_required": { + "name": "payment_required", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "domains": { + "name": "domains", + "type": "text[]", + "primaryKey": false, + "notNull": false + }, + "restrict_new_user_invitations": { + "name": "restrict_new_user_invitations", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "default_role": { + "name": "default_role", + "type": "user_organization_role_enum", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'restricted_querier'" + }, + "organization_color_palettes": { + "name": "organization_color_palettes", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{\"selectedId\": null, \"palettes\": [], \"selectedDictionaryPalette\": null}'::jsonb" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "organizations_name_key": { + "name": "organizations_name_key", + "nullsNotDistinct": false, + "columns": [ + "name" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.permission_groups": { + "name": "permission_groups", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "updated_by": { + "name": "updated_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "permission_groups_organization_id_fkey": { + "name": "permission_groups_organization_id_fkey", + "tableFrom": "permission_groups", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "permission_groups_created_by_fkey": { + "name": "permission_groups_created_by_fkey", + "tableFrom": "permission_groups", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "cascade" + }, + "permission_groups_updated_by_fkey": { + "name": "permission_groups_updated_by_fkey", + "tableFrom": "permission_groups", + "tableTo": "users", + "columnsFrom": [ + "updated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.permission_groups_to_identities": { + "name": "permission_groups_to_identities", + "schema": "", + "columns": { + "permission_group_id": { + "name": "permission_group_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "identity_id": { + "name": "identity_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "identity_type": { + "name": "identity_type", + "type": "identity_type_enum", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "updated_by": { + "name": "updated_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "permission_groups_to_identities_created_by_fkey": { + "name": "permission_groups_to_identities_created_by_fkey", + "tableFrom": "permission_groups_to_identities", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "cascade" + }, + "permission_groups_to_identities_updated_by_fkey": { + "name": "permission_groups_to_identities_updated_by_fkey", + "tableFrom": "permission_groups_to_identities", + "tableTo": "users", + "columnsFrom": [ + "updated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": { + "permission_groups_to_identities_pkey": { + "name": "permission_groups_to_identities_pkey", + "columns": [ + "permission_group_id", + "identity_id", + "identity_type" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.permission_groups_to_users": { + "name": "permission_groups_to_users", + "schema": "", + "columns": { + "permission_group_id": { + "name": "permission_group_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "permission_groups_to_users_user_id_idx": { + "name": "permission_groups_to_users_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "uuid_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "permission_groups_to_users_permission_group_id_fkey": { + "name": "permission_groups_to_users_permission_group_id_fkey", + "tableFrom": "permission_groups_to_users", + "tableTo": "permission_groups", + "columnsFrom": [ + "permission_group_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "permission_groups_to_users_user_id_fkey": { + "name": "permission_groups_to_users_user_id_fkey", + "tableFrom": "permission_groups_to_users", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": { + "permission_groups_to_users_pkey": { + "name": "permission_groups_to_users_pkey", + "columns": [ + "permission_group_id", + "user_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": { + "permission_groups_to_users_policy": { + "name": "permission_groups_to_users_policy", + "as": "PERMISSIVE", + "for": "ALL", + "to": [ + "authenticated" + ], + "using": "true" + } + }, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.report_files": { + "name": "report_files", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "name": { + "name": "name", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "content": { + "name": "content", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "publicly_accessible": { + "name": "publicly_accessible", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "publicly_enabled_by": { + "name": "publicly_enabled_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "public_expiry_date": { + "name": "public_expiry_date", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "version_history": { + "name": "version_history", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "public_password": { + "name": "public_password", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "workspace_sharing": { + "name": "workspace_sharing", + "type": "workspace_sharing_enum", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'none'" + }, + "workspace_sharing_enabled_by": { + "name": "workspace_sharing_enabled_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "workspace_sharing_enabled_at": { + "name": "workspace_sharing_enabled_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "report_files_created_by_idx": { + "name": "report_files_created_by_idx", + "columns": [ + { + "expression": "created_by", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "uuid_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "report_files_deleted_at_idx": { + "name": "report_files_deleted_at_idx", + "columns": [ + { + "expression": "deleted_at", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "timestamptz_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "report_files_organization_id_idx": { + "name": "report_files_organization_id_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "uuid_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "report_files_created_by_fkey": { + "name": "report_files_created_by_fkey", + "tableFrom": "report_files", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "cascade" + }, + "report_files_publicly_enabled_by_fkey": { + "name": "report_files_publicly_enabled_by_fkey", + "tableFrom": "report_files", + "tableTo": "users", + "columnsFrom": [ + "publicly_enabled_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "cascade" + }, + "report_files_workspace_sharing_enabled_by_fkey": { + "name": "report_files_workspace_sharing_enabled_by_fkey", + "tableFrom": "report_files", + "tableTo": "users", + "columnsFrom": [ + "workspace_sharing_enabled_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "cascade" + }, + "report_files_organization_id_fkey": { + "name": "report_files_organization_id_fkey", + "tableFrom": "report_files", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.schema_metadata": { + "name": "schema_metadata", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "data_source_id": { + "name": "data_source_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "database_id": { + "name": "database_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "database_name": { + "name": "database_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "owner": { + "name": "owner", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "comment": { + "name": "comment", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created": { + "name": "created", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "last_modified": { + "name": "last_modified", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "schema_metadata_data_source_id_idx": { + "name": "schema_metadata_data_source_id_idx", + "columns": [ + { + "expression": "data_source_id", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "uuid_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "schema_metadata_database_id_idx": { + "name": "schema_metadata_database_id_idx", + "columns": [ + { + "expression": "database_id", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "uuid_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "schema_metadata_data_source_id_fkey": { + "name": "schema_metadata_data_source_id_fkey", + "tableFrom": "schema_metadata", + "tableTo": "data_sources", + "columnsFrom": [ + "data_source_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "schema_metadata_database_id_fkey": { + "name": "schema_metadata_database_id_fkey", + "tableFrom": "schema_metadata", + "tableTo": "database_metadata", + "columnsFrom": [ + "database_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "schema_metadata_data_source_id_database_id_name_key": { + "name": "schema_metadata_data_source_id_database_id_name_key", + "nullsNotDistinct": false, + "columns": [ + "data_source_id", + "database_id", + "name" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.slack_integrations": { + "name": "slack_integrations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "oauth_state": { + "name": "oauth_state", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "oauth_expires_at": { + "name": "oauth_expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "oauth_metadata": { + "name": "oauth_metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'{}'::jsonb" + }, + "team_id": { + "name": "team_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "team_name": { + "name": "team_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "team_domain": { + "name": "team_domain", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "enterprise_id": { + "name": "enterprise_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "bot_user_id": { + "name": "bot_user_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "scope": { + "name": "scope", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "token_vault_key": { + "name": "token_vault_key", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "installed_by_slack_user_id": { + "name": "installed_by_slack_user_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "installed_at": { + "name": "installed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "last_used_at": { + "name": "last_used_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "slack_integration_status_enum", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "default_channel": { + "name": "default_channel", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'{}'::jsonb" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "default_sharing_permissions": { + "name": "default_sharing_permissions", + "type": "slack_sharing_permission_enum", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'shareWithChannel'" + } + }, + "indexes": { + "idx_slack_integrations_org_id": { + "name": "idx_slack_integrations_org_id", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "uuid_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_slack_integrations_team_id": { + "name": "idx_slack_integrations_team_id", + "columns": [ + { + "expression": "team_id", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "text_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_slack_integrations_oauth_state": { + "name": "idx_slack_integrations_oauth_state", + "columns": [ + { + "expression": "oauth_state", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "text_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_slack_integrations_oauth_expires": { + "name": "idx_slack_integrations_oauth_expires", + "columns": [ + { + "expression": "oauth_expires_at", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "timestamptz_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "slack_integrations_organization_id_fkey": { + "name": "slack_integrations_organization_id_fkey", + "tableFrom": "slack_integrations", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "slack_integrations_user_id_fkey": { + "name": "slack_integrations_user_id_fkey", + "tableFrom": "slack_integrations", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "slack_integrations_oauth_state_unique": { + "name": "slack_integrations_oauth_state_unique", + "nullsNotDistinct": false, + "columns": [ + "oauth_state" + ] + }, + "slack_integrations_token_vault_key_unique": { + "name": "slack_integrations_token_vault_key_unique", + "nullsNotDistinct": false, + "columns": [ + "token_vault_key" + ] + }, + "slack_integrations_org_team_key": { + "name": "slack_integrations_org_team_key", + "nullsNotDistinct": false, + "columns": [ + "organization_id", + "team_id" + ] + } + }, + "policies": {}, + "checkConstraints": { + "slack_integrations_status_check": { + "name": "slack_integrations_status_check", + "value": "(status = 'pending' AND oauth_state IS NOT NULL) OR (status != 'pending' AND team_id IS NOT NULL)" + } + }, + "isRLSEnabled": false + }, + "public.slack_message_tracking": { + "name": "slack_message_tracking", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "integration_id": { + "name": "integration_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "internal_message_id": { + "name": "internal_message_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "slack_channel_id": { + "name": "slack_channel_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "slack_message_ts": { + "name": "slack_message_ts", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "slack_thread_ts": { + "name": "slack_thread_ts", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "message_type": { + "name": "message_type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "content": { + "name": "content", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "sender_info": { + "name": "sender_info", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "sent_at": { + "name": "sent_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "idx_message_tracking_integration": { + "name": "idx_message_tracking_integration", + "columns": [ + { + "expression": "integration_id", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "uuid_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_message_tracking_channel": { + "name": "idx_message_tracking_channel", + "columns": [ + { + "expression": "slack_channel_id", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "text_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_message_tracking_thread": { + "name": "idx_message_tracking_thread", + "columns": [ + { + "expression": "slack_thread_ts", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "text_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "slack_message_tracking_integration_id_fkey": { + "name": "slack_message_tracking_integration_id_fkey", + "tableFrom": "slack_message_tracking", + "tableTo": "slack_integrations", + "columnsFrom": [ + "integration_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "slack_message_tracking_internal_message_id_unique": { + "name": "slack_message_tracking_internal_message_id_unique", + "nullsNotDistinct": false, + "columns": [ + "internal_message_id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.sql_evaluations": { + "name": "sql_evaluations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuid_generate_v4()" + }, + "evaluation_obj": { + "name": "evaluation_obj", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "evaluation_summary": { + "name": "evaluation_summary", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "score": { + "name": "score", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.stored_values_sync_jobs": { + "name": "stored_values_sync_jobs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "data_source_id": { + "name": "data_source_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "database_name": { + "name": "database_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "schema_name": { + "name": "schema_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "table_name": { + "name": "table_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "column_name": { + "name": "column_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "last_synced_at": { + "name": "last_synced_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "error_message": { + "name": "error_message", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "idx_stored_values_sync_jobs_data_source_id": { + "name": "idx_stored_values_sync_jobs_data_source_id", + "columns": [ + { + "expression": "data_source_id", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "uuid_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_stored_values_sync_jobs_db_schema_table_column": { + "name": "idx_stored_values_sync_jobs_db_schema_table_column", + "columns": [ + { + "expression": "database_name", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "text_ops" + }, + { + "expression": "schema_name", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "text_ops" + }, + { + "expression": "table_name", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "text_ops" + }, + { + "expression": "column_name", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "text_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_stored_values_sync_jobs_status": { + "name": "idx_stored_values_sync_jobs_status", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "text_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "stored_values_sync_jobs_data_source_id_fkey": { + "name": "stored_values_sync_jobs_data_source_id_fkey", + "tableFrom": "stored_values_sync_jobs", + "tableTo": "data_sources", + "columnsFrom": [ + "data_source_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.table_metadata": { + "name": "table_metadata", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "data_source_id": { + "name": "data_source_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "database_id": { + "name": "database_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "schema_id": { + "name": "schema_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "schema_name": { + "name": "schema_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "database_name": { + "name": "database_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "type": { + "name": "type", + "type": "table_type_enum", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "row_count": { + "name": "row_count", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "size_bytes": { + "name": "size_bytes", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "comment": { + "name": "comment", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created": { + "name": "created", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "last_modified": { + "name": "last_modified", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "clustering_keys": { + "name": "clustering_keys", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "columns": { + "name": "columns", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "table_metadata_data_source_id_idx": { + "name": "table_metadata_data_source_id_idx", + "columns": [ + { + "expression": "data_source_id", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "uuid_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "table_metadata_database_id_idx": { + "name": "table_metadata_database_id_idx", + "columns": [ + { + "expression": "database_id", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "uuid_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "table_metadata_schema_id_idx": { + "name": "table_metadata_schema_id_idx", + "columns": [ + { + "expression": "schema_id", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "uuid_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "table_metadata_data_source_id_fkey": { + "name": "table_metadata_data_source_id_fkey", + "tableFrom": "table_metadata", + "tableTo": "data_sources", + "columnsFrom": [ + "data_source_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "table_metadata_database_id_fkey": { + "name": "table_metadata_database_id_fkey", + "tableFrom": "table_metadata", + "tableTo": "database_metadata", + "columnsFrom": [ + "database_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "table_metadata_schema_id_fkey": { + "name": "table_metadata_schema_id_fkey", + "tableFrom": "table_metadata", + "tableTo": "schema_metadata", + "columnsFrom": [ + "schema_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "table_metadata_data_source_id_schema_id_name_key": { + "name": "table_metadata_data_source_id_schema_id_name_key", + "nullsNotDistinct": false, + "columns": [ + "data_source_id", + "schema_id", + "name" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.teams": { + "name": "teams", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "sharing_setting": { + "name": "sharing_setting", + "type": "sharing_setting_enum", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'none'" + }, + "edit_sql": { + "name": "edit_sql", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "upload_csv": { + "name": "upload_csv", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "export_assets": { + "name": "export_assets", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "email_slack_enabled": { + "name": "email_slack_enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "teams_organization_id_fkey": { + "name": "teams_organization_id_fkey", + "tableFrom": "teams", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "teams_created_by_fkey": { + "name": "teams_created_by_fkey", + "tableFrom": "teams", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "teams_name_key": { + "name": "teams_name_key", + "nullsNotDistinct": false, + "columns": [ + "name" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.teams_to_users": { + "name": "teams_to_users", + "schema": "", + "columns": { + "team_id": { + "name": "team_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "role": { + "name": "role", + "type": "team_role_enum", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'member'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "teams_to_users_team_id_fkey": { + "name": "teams_to_users_team_id_fkey", + "tableFrom": "teams_to_users", + "tableTo": "teams", + "columnsFrom": [ + "team_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "teams_to_users_user_id_fkey": { + "name": "teams_to_users_user_id_fkey", + "tableFrom": "teams_to_users", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": { + "teams_to_users_pkey": { + "name": "teams_to_users_pkey", + "columns": [ + "team_id", + "user_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.terms": { + "name": "terms", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "definition": { + "name": "definition", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "sql_snippet": { + "name": "sql_snippet", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "updated_by": { + "name": "updated_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "terms_organization_id_fkey": { + "name": "terms_organization_id_fkey", + "tableFrom": "terms", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "terms_created_by_fkey": { + "name": "terms_created_by_fkey", + "tableFrom": "terms", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "cascade" + }, + "terms_updated_by_fkey": { + "name": "terms_updated_by_fkey", + "tableFrom": "terms", + "tableTo": "users", + "columnsFrom": [ + "updated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.terms_to_datasets": { + "name": "terms_to_datasets", + "schema": "", + "columns": { + "term_id": { + "name": "term_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "dataset_id": { + "name": "dataset_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "terms_to_datasets_term_id_fkey": { + "name": "terms_to_datasets_term_id_fkey", + "tableFrom": "terms_to_datasets", + "tableTo": "terms", + "columnsFrom": [ + "term_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "terms_to_datasets_dataset_id_fkey": { + "name": "terms_to_datasets_dataset_id_fkey", + "tableFrom": "terms_to_datasets", + "tableTo": "datasets", + "columnsFrom": [ + "dataset_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "terms_to_datasets_pkey": { + "name": "terms_to_datasets_pkey", + "columns": [ + "term_id", + "dataset_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.threads_deprecated": { + "name": "threads_deprecated", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "updated_by": { + "name": "updated_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "publicly_accessible": { + "name": "publicly_accessible", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "publicly_enabled_by": { + "name": "publicly_enabled_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "public_expiry_date": { + "name": "public_expiry_date", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "password_secret_id": { + "name": "password_secret_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "state_message_id": { + "name": "state_message_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "parent_thread_id": { + "name": "parent_thread_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "threads_created_by_fkey": { + "name": "threads_created_by_fkey", + "tableFrom": "threads_deprecated", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "cascade" + }, + "threads_updated_by_fkey": { + "name": "threads_updated_by_fkey", + "tableFrom": "threads_deprecated", + "tableTo": "users", + "columnsFrom": [ + "updated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "cascade" + }, + "threads_publicly_enabled_by_fkey": { + "name": "threads_publicly_enabled_by_fkey", + "tableFrom": "threads_deprecated", + "tableTo": "users", + "columnsFrom": [ + "publicly_enabled_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "cascade" + }, + "threads_parent_thread_id_fkey": { + "name": "threads_parent_thread_id_fkey", + "tableFrom": "threads_deprecated", + "tableTo": "threads_deprecated", + "columnsFrom": [ + "parent_thread_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "cascade" + }, + "threads_organization_id_fkey": { + "name": "threads_organization_id_fkey", + "tableFrom": "threads_deprecated", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "threads_deprecated_created_by_fkey": { + "name": "threads_deprecated_created_by_fkey", + "tableFrom": "threads_deprecated", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "cascade" + }, + "threads_deprecated_updated_by_fkey": { + "name": "threads_deprecated_updated_by_fkey", + "tableFrom": "threads_deprecated", + "tableTo": "users", + "columnsFrom": [ + "updated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "cascade" + }, + "threads_deprecated_publicly_enabled_by_fkey": { + "name": "threads_deprecated_publicly_enabled_by_fkey", + "tableFrom": "threads_deprecated", + "tableTo": "users", + "columnsFrom": [ + "publicly_enabled_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.threads_to_dashboards": { + "name": "threads_to_dashboards", + "schema": "", + "columns": { + "thread_id": { + "name": "thread_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "dashboard_id": { + "name": "dashboard_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "added_by": { + "name": "added_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "threads_to_dashboards_thread_id_fkey": { + "name": "threads_to_dashboards_thread_id_fkey", + "tableFrom": "threads_to_dashboards", + "tableTo": "threads_deprecated", + "columnsFrom": [ + "thread_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "threads_to_dashboards_dashboard_id_fkey": { + "name": "threads_to_dashboards_dashboard_id_fkey", + "tableFrom": "threads_to_dashboards", + "tableTo": "dashboards", + "columnsFrom": [ + "dashboard_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "threads_to_dashboards_added_by_fkey": { + "name": "threads_to_dashboards_added_by_fkey", + "tableFrom": "threads_to_dashboards", + "tableTo": "users", + "columnsFrom": [ + "added_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": { + "threads_to_dashboards_pkey": { + "name": "threads_to_dashboards_pkey", + "columns": [ + "thread_id", + "dashboard_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.user_favorites": { + "name": "user_favorites", + "schema": "", + "columns": { + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "asset_id": { + "name": "asset_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "asset_type": { + "name": "asset_type", + "type": "asset_type_enum", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "order_index": { + "name": "order_index", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "user_favorites_user_id_fkey": { + "name": "user_favorites_user_id_fkey", + "tableFrom": "user_favorites", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": { + "user_favorites_pkey": { + "name": "user_favorites_pkey", + "columns": [ + "user_id", + "asset_id", + "asset_type" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.users": { + "name": "users", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "config": { + "name": "config", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "attributes": { + "name": "attributes", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "avatar_url": { + "name": "avatar_url", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "users_email_key": { + "name": "users_email_key", + "nullsNotDistinct": false, + "columns": [ + "email" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.users_to_organizations": { + "name": "users_to_organizations", + "schema": "", + "columns": { + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "role": { + "name": "role", + "type": "user_organization_role_enum", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'querier'" + }, + "sharing_setting": { + "name": "sharing_setting", + "type": "sharing_setting_enum", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'none'" + }, + "edit_sql": { + "name": "edit_sql", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "upload_csv": { + "name": "upload_csv", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "export_assets": { + "name": "export_assets", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "email_slack_enabled": { + "name": "email_slack_enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "updated_by": { + "name": "updated_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "deleted_by": { + "name": "deleted_by", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "user_organization_status_enum", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'active'" + } + }, + "indexes": {}, + "foreignKeys": { + "users_to_organizations_organization_id_fkey": { + "name": "users_to_organizations_organization_id_fkey", + "tableFrom": "users_to_organizations", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "users_to_organizations_user_id_fkey": { + "name": "users_to_organizations_user_id_fkey", + "tableFrom": "users_to_organizations", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "cascade" + }, + "users_to_organizations_created_by_fkey": { + "name": "users_to_organizations_created_by_fkey", + "tableFrom": "users_to_organizations", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "cascade" + }, + "users_to_organizations_updated_by_fkey": { + "name": "users_to_organizations_updated_by_fkey", + "tableFrom": "users_to_organizations", + "tableTo": "users", + "columnsFrom": [ + "updated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "cascade" + }, + "users_to_organizations_deleted_by_fkey": { + "name": "users_to_organizations_deleted_by_fkey", + "tableFrom": "users_to_organizations", + "tableTo": "users", + "columnsFrom": [ + "deleted_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": { + "users_to_organizations_pkey": { + "name": "users_to_organizations_pkey", + "columns": [ + "user_id", + "organization_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": { + "public.asset_permission_role_enum": { + "name": "asset_permission_role_enum", + "schema": "public", + "values": [ + "owner", + "viewer", + "full_access", + "can_edit", + "can_filter", + "can_view" + ] + }, + "public.asset_type_enum": { + "name": "asset_type_enum", + "schema": "public", + "values": [ + "dashboard", + "thread", + "collection", + "chat", + "metric_file", + "dashboard_file", + "report_file" + ] + }, + "public.data_source_onboarding_status_enum": { + "name": "data_source_onboarding_status_enum", + "schema": "public", + "values": [ + "notStarted", + "inProgress", + "completed", + "failed" + ] + }, + "public.dataset_type_enum": { + "name": "dataset_type_enum", + "schema": "public", + "values": [ + "table", + "view", + "materializedView" + ] + }, + "public.github_integration_status_enum": { + "name": "github_integration_status_enum", + "schema": "public", + "values": [ + "pending", + "active", + "suspended", + "revoked" + ] + }, + "public.identity_type_enum": { + "name": "identity_type_enum", + "schema": "public", + "values": [ + "user", + "team", + "organization" + ] + }, + "public.message_feedback_enum": { + "name": "message_feedback_enum", + "schema": "public", + "values": [ + "positive", + "negative" + ] + }, + "public.sharing_setting_enum": { + "name": "sharing_setting_enum", + "schema": "public", + "values": [ + "none", + "team", + "organization", + "public" + ] + }, + "public.slack_chat_authorization_enum": { + "name": "slack_chat_authorization_enum", + "schema": "public", + "values": [ + "unauthorized", + "authorized", + "auto_added" + ] + }, + "public.slack_integration_status_enum": { + "name": "slack_integration_status_enum", + "schema": "public", + "values": [ + "pending", + "active", + "failed", + "revoked" + ] + }, + "public.slack_sharing_permission_enum": { + "name": "slack_sharing_permission_enum", + "schema": "public", + "values": [ + "shareWithWorkspace", + "shareWithChannel", + "noSharing" + ] + }, + "public.stored_values_status_enum": { + "name": "stored_values_status_enum", + "schema": "public", + "values": [ + "syncing", + "success", + "failed" + ] + }, + "public.table_type_enum": { + "name": "table_type_enum", + "schema": "public", + "values": [ + "TABLE", + "VIEW", + "MATERIALIZED_VIEW", + "EXTERNAL_TABLE", + "TEMPORARY_TABLE" + ] + }, + "public.team_role_enum": { + "name": "team_role_enum", + "schema": "public", + "values": [ + "manager", + "member" + ] + }, + "public.user_organization_role_enum": { + "name": "user_organization_role_enum", + "schema": "public", + "values": [ + "workspace_admin", + "data_admin", + "querier", + "restricted_querier", + "viewer" + ] + }, + "public.user_organization_status_enum": { + "name": "user_organization_status_enum", + "schema": "public", + "values": [ + "active", + "inactive", + "pending", + "guest" + ] + }, + "public.verification_enum": { + "name": "verification_enum", + "schema": "public", + "values": [ + "verified", + "backlogged", + "inReview", + "requested", + "notRequested" + ] + }, + "public.workspace_sharing_enum": { + "name": "workspace_sharing_enum", + "schema": "public", + "values": [ + "none", + "can_view", + "can_edit", + "full_access" + ] + } + }, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/packages/database/drizzle/meta/_journal.json b/packages/database/drizzle/meta/_journal.json index 4856cccdf..7cf066aa0 100644 --- a/packages/database/drizzle/meta/_journal.json +++ b/packages/database/drizzle/meta/_journal.json @@ -617,6 +617,13 @@ "when": 1754359807604, "tag": "0087_create_report_table_foreign_keys", "breakpoints": true + }, + { + "idx": 88, + "version": "7", + "when": 1754415507954, + "tag": "0088_puzzling_vanisher", + "breakpoints": true } ] } \ No newline at end of file diff --git a/packages/database/src/schema.ts b/packages/database/src/schema.ts index d44e6f40a..e0f665cb8 100644 --- a/packages/database/src/schema.ts +++ b/packages/database/src/schema.ts @@ -1,2183 +1,2258 @@ -import { sql } from 'drizzle-orm'; +import { sql } from "drizzle-orm"; import { - bigint, - boolean, - check, - doublePrecision, - foreignKey, - index, - integer, - jsonb, - pgEnum, - pgPolicy, - pgTable, - primaryKey, - text, - timestamp, - unique, - uniqueIndex, - uuid, - varchar, -} from 'drizzle-orm/pg-core'; -import type { OrganizationColorPalettes, ReportElements } from './schema-types'; + bigint, + boolean, + check, + doublePrecision, + foreignKey, + index, + integer, + jsonb, + pgEnum, + pgPolicy, + pgTable, + primaryKey, + text, + timestamp, + unique, + uniqueIndex, + uuid, + varchar, +} from "drizzle-orm/pg-core"; +import type { OrganizationColorPalettes, ReportElements } from "./schema-types"; -export const assetPermissionRoleEnum = pgEnum('asset_permission_role_enum', [ - 'owner', - 'viewer', - 'full_access', - 'can_edit', - 'can_filter', - 'can_view', +export const assetPermissionRoleEnum = pgEnum("asset_permission_role_enum", [ + "owner", + "viewer", + "full_access", + "can_edit", + "can_filter", + "can_view", ]); -export const assetTypeEnum = pgEnum('asset_type_enum', [ - 'dashboard', - 'thread', - 'collection', - 'chat', - 'metric_file', - 'dashboard_file', - 'report_file', +export const assetTypeEnum = pgEnum("asset_type_enum", [ + "dashboard", + "thread", + "collection", + "chat", + "metric_file", + "dashboard_file", + "report_file", ]); // Asset type enum removed - now using text for all asset_type columns -export const dataSourceOnboardingStatusEnum = pgEnum('data_source_onboarding_status_enum', [ - 'notStarted', - 'inProgress', - 'completed', - 'failed', +export const dataSourceOnboardingStatusEnum = pgEnum( + "data_source_onboarding_status_enum", + ["notStarted", "inProgress", "completed", "failed"], +); +export const datasetTypeEnum = pgEnum("dataset_type_enum", [ + "table", + "view", + "materializedView", ]); -export const datasetTypeEnum = pgEnum('dataset_type_enum', ['table', 'view', 'materializedView']); -export const identityTypeEnum = pgEnum('identity_type_enum', ['user', 'team', 'organization']); -export const messageFeedbackEnum = pgEnum('message_feedback_enum', ['positive', 'negative']); -export const sharingSettingEnum = pgEnum('sharing_setting_enum', [ - 'none', - 'team', - 'organization', - 'public', +export const identityTypeEnum = pgEnum("identity_type_enum", [ + "user", + "team", + "organization", ]); -export const storedValuesStatusEnum = pgEnum('stored_values_status_enum', [ - 'syncing', - 'success', - 'failed', +export const messageFeedbackEnum = pgEnum("message_feedback_enum", [ + "positive", + "negative", ]); -export const teamRoleEnum = pgEnum('team_role_enum', ['manager', 'member']); -export const userOrganizationRoleEnum = pgEnum('user_organization_role_enum', [ - 'workspace_admin', - 'data_admin', - 'querier', - 'restricted_querier', - 'viewer', +export const sharingSettingEnum = pgEnum("sharing_setting_enum", [ + "none", + "team", + "organization", + "public", ]); -export const userOrganizationStatusEnum = pgEnum('user_organization_status_enum', [ - 'active', - 'inactive', - 'pending', - 'guest', +export const storedValuesStatusEnum = pgEnum("stored_values_status_enum", [ + "syncing", + "success", + "failed", ]); -export const verificationEnum = pgEnum('verification_enum', [ - 'verified', - 'backlogged', - 'inReview', - 'requested', - 'notRequested', +export const teamRoleEnum = pgEnum("team_role_enum", ["manager", "member"]); +export const userOrganizationRoleEnum = pgEnum("user_organization_role_enum", [ + "workspace_admin", + "data_admin", + "querier", + "restricted_querier", + "viewer", ]); -export const tableTypeEnum = pgEnum('table_type_enum', [ - 'TABLE', - 'VIEW', - 'MATERIALIZED_VIEW', - 'EXTERNAL_TABLE', - 'TEMPORARY_TABLE', +export const userOrganizationStatusEnum = pgEnum( + "user_organization_status_enum", + ["active", "inactive", "pending", "guest"], +); +export const verificationEnum = pgEnum("verification_enum", [ + "verified", + "backlogged", + "inReview", + "requested", + "notRequested", ]); -export const slackIntegrationStatusEnum = pgEnum('slack_integration_status_enum', [ - 'pending', - 'active', - 'failed', - 'revoked', +export const tableTypeEnum = pgEnum("table_type_enum", [ + "TABLE", + "VIEW", + "MATERIALIZED_VIEW", + "EXTERNAL_TABLE", + "TEMPORARY_TABLE", ]); +export const slackIntegrationStatusEnum = pgEnum( + "slack_integration_status_enum", + ["pending", "active", "failed", "revoked"], +); -export const slackChatAuthorizationEnum = pgEnum('slack_chat_authorization_enum', [ - 'unauthorized', - 'authorized', - 'auto_added', -]); +export const slackChatAuthorizationEnum = pgEnum( + "slack_chat_authorization_enum", + ["unauthorized", "authorized", "auto_added"], +); -export const slackSharingPermissionEnum = pgEnum('slack_sharing_permission_enum', [ - 'shareWithWorkspace', - 'shareWithChannel', - 'noSharing', -]); +export const slackSharingPermissionEnum = pgEnum( + "slack_sharing_permission_enum", + ["shareWithWorkspace", "shareWithChannel", "noSharing"], +); -export const githubIntegrationStatusEnum = pgEnum('github_integration_status_enum', [ - 'pending', - 'active', - 'suspended', - 'revoked', -]); +export const githubIntegrationStatusEnum = pgEnum( + "github_integration_status_enum", + ["pending", "active", "suspended", "revoked"], +); -export const workspaceSharingEnum = pgEnum('workspace_sharing_enum', [ - 'none', - 'can_view', - 'can_edit', - 'full_access', +export const workspaceSharingEnum = pgEnum("workspace_sharing_enum", [ + "none", + "can_view", + "can_edit", + "full_access", ]); export const apiKeys = pgTable( - 'api_keys', - { - id: uuid().defaultRandom().primaryKey().notNull(), - ownerId: uuid('owner_id').notNull(), - key: text().notNull(), - organizationId: uuid('organization_id').notNull(), - createdAt: timestamp('created_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - updatedAt: timestamp('updated_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - deletedAt: timestamp('deleted_at', { withTimezone: true, mode: 'string' }), - }, - (table) => [ - foreignKey({ - columns: [table.organizationId], - foreignColumns: [organizations.id], - name: 'api_keys_organization_id_fkey', - }).onDelete('cascade'), - foreignKey({ - columns: [table.ownerId], - foreignColumns: [users.id], - name: 'api_keys_owner_id_fkey', - }).onUpdate('cascade'), - unique('api_keys_key_key').on(table.key), - ] + "api_keys", + { + id: uuid().defaultRandom().primaryKey().notNull(), + ownerId: uuid("owner_id").notNull(), + key: text().notNull(), + organizationId: uuid("organization_id").notNull(), + createdAt: timestamp("created_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + updatedAt: timestamp("updated_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + deletedAt: timestamp("deleted_at", { withTimezone: true, mode: "string" }), + }, + (table) => [ + foreignKey({ + columns: [table.organizationId], + foreignColumns: [organizations.id], + name: "api_keys_organization_id_fkey", + }).onDelete("cascade"), + foreignKey({ + columns: [table.ownerId], + foreignColumns: [users.id], + name: "api_keys_owner_id_fkey", + }).onUpdate("cascade"), + unique("api_keys_key_key").on(table.key), + ], ); export const teams = pgTable( - 'teams', - { - id: uuid().defaultRandom().primaryKey().notNull(), - name: text().notNull(), - organizationId: uuid('organization_id').notNull(), - sharingSetting: sharingSettingEnum('sharing_setting').default('none').notNull(), - editSql: boolean('edit_sql').default(false).notNull(), - uploadCsv: boolean('upload_csv').default(false).notNull(), - exportAssets: boolean('export_assets').default(false).notNull(), - emailSlackEnabled: boolean('email_slack_enabled').default(false).notNull(), - createdBy: uuid('created_by').notNull(), - createdAt: timestamp('created_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - updatedAt: timestamp('updated_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - deletedAt: timestamp('deleted_at', { withTimezone: true, mode: 'string' }), - }, - (table) => [ - foreignKey({ - columns: [table.organizationId], - foreignColumns: [organizations.id], - name: 'teams_organization_id_fkey', - }).onDelete('cascade'), - foreignKey({ - columns: [table.createdBy], - foreignColumns: [users.id], - name: 'teams_created_by_fkey', - }).onUpdate('cascade'), - unique('teams_name_key').on(table.name), - ] + "teams", + { + id: uuid().defaultRandom().primaryKey().notNull(), + name: text().notNull(), + organizationId: uuid("organization_id").notNull(), + sharingSetting: sharingSettingEnum("sharing_setting") + .default("none") + .notNull(), + editSql: boolean("edit_sql").default(false).notNull(), + uploadCsv: boolean("upload_csv").default(false).notNull(), + exportAssets: boolean("export_assets").default(false).notNull(), + emailSlackEnabled: boolean("email_slack_enabled").default(false).notNull(), + createdBy: uuid("created_by").notNull(), + createdAt: timestamp("created_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + updatedAt: timestamp("updated_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + deletedAt: timestamp("deleted_at", { withTimezone: true, mode: "string" }), + }, + (table) => [ + foreignKey({ + columns: [table.organizationId], + foreignColumns: [organizations.id], + name: "teams_organization_id_fkey", + }).onDelete("cascade"), + foreignKey({ + columns: [table.createdBy], + foreignColumns: [users.id], + name: "teams_created_by_fkey", + }).onUpdate("cascade"), + unique("teams_name_key").on(table.name), + ], ); export const permissionGroups = pgTable( - 'permission_groups', - { - id: uuid().defaultRandom().primaryKey().notNull(), - name: text().notNull(), - organizationId: uuid('organization_id').notNull(), - createdBy: uuid('created_by').notNull(), - updatedBy: uuid('updated_by').notNull(), - createdAt: timestamp('created_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - updatedAt: timestamp('updated_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - deletedAt: timestamp('deleted_at', { withTimezone: true, mode: 'string' }), - }, - (table) => [ - foreignKey({ - columns: [table.organizationId], - foreignColumns: [organizations.id], - name: 'permission_groups_organization_id_fkey', - }).onDelete('cascade'), - foreignKey({ - columns: [table.createdBy], - foreignColumns: [users.id], - name: 'permission_groups_created_by_fkey', - }).onUpdate('cascade'), - foreignKey({ - columns: [table.updatedBy], - foreignColumns: [users.id], - name: 'permission_groups_updated_by_fkey', - }).onUpdate('cascade'), - ] + "permission_groups", + { + id: uuid().defaultRandom().primaryKey().notNull(), + name: text().notNull(), + organizationId: uuid("organization_id").notNull(), + createdBy: uuid("created_by").notNull(), + updatedBy: uuid("updated_by").notNull(), + createdAt: timestamp("created_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + updatedAt: timestamp("updated_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + deletedAt: timestamp("deleted_at", { withTimezone: true, mode: "string" }), + }, + (table) => [ + foreignKey({ + columns: [table.organizationId], + foreignColumns: [organizations.id], + name: "permission_groups_organization_id_fkey", + }).onDelete("cascade"), + foreignKey({ + columns: [table.createdBy], + foreignColumns: [users.id], + name: "permission_groups_created_by_fkey", + }).onUpdate("cascade"), + foreignKey({ + columns: [table.updatedBy], + foreignColumns: [users.id], + name: "permission_groups_updated_by_fkey", + }).onUpdate("cascade"), + ], ); export const terms = pgTable( - 'terms', - { - id: uuid().defaultRandom().primaryKey().notNull(), - name: text().notNull(), - definition: text(), - sqlSnippet: text('sql_snippet'), - organizationId: uuid('organization_id').notNull(), - createdBy: uuid('created_by').notNull(), - updatedBy: uuid('updated_by').notNull(), - createdAt: timestamp('created_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - updatedAt: timestamp('updated_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - deletedAt: timestamp('deleted_at', { withTimezone: true, mode: 'string' }), - }, - (table) => [ - foreignKey({ - columns: [table.organizationId], - foreignColumns: [organizations.id], - name: 'terms_organization_id_fkey', - }).onDelete('cascade'), - foreignKey({ - columns: [table.createdBy], - foreignColumns: [users.id], - name: 'terms_created_by_fkey', - }).onUpdate('cascade'), - foreignKey({ - columns: [table.updatedBy], - foreignColumns: [users.id], - name: 'terms_updated_by_fkey', - }).onUpdate('cascade'), - ] + "terms", + { + id: uuid().defaultRandom().primaryKey().notNull(), + name: text().notNull(), + definition: text(), + sqlSnippet: text("sql_snippet"), + organizationId: uuid("organization_id").notNull(), + createdBy: uuid("created_by").notNull(), + updatedBy: uuid("updated_by").notNull(), + createdAt: timestamp("created_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + updatedAt: timestamp("updated_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + deletedAt: timestamp("deleted_at", { withTimezone: true, mode: "string" }), + }, + (table) => [ + foreignKey({ + columns: [table.organizationId], + foreignColumns: [organizations.id], + name: "terms_organization_id_fkey", + }).onDelete("cascade"), + foreignKey({ + columns: [table.createdBy], + foreignColumns: [users.id], + name: "terms_created_by_fkey", + }).onUpdate("cascade"), + foreignKey({ + columns: [table.updatedBy], + foreignColumns: [users.id], + name: "terms_updated_by_fkey", + }).onUpdate("cascade"), + ], ); export const collections = pgTable( - 'collections', - { - id: uuid().defaultRandom().primaryKey().notNull(), - name: text().notNull(), - description: text(), - createdBy: uuid('created_by').notNull(), - updatedBy: uuid('updated_by').notNull(), - createdAt: timestamp('created_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - updatedAt: timestamp('updated_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - deletedAt: timestamp('deleted_at', { withTimezone: true, mode: 'string' }), - organizationId: uuid('organization_id').notNull(), - workspaceSharing: workspaceSharingEnum('workspace_sharing').default('none').notNull(), - workspaceSharingEnabledBy: uuid('workspace_sharing_enabled_by'), - workspaceSharingEnabledAt: timestamp('workspace_sharing_enabled_at', { - withTimezone: true, - mode: 'string', - }), - }, - (table) => [ - foreignKey({ - columns: [table.organizationId], - foreignColumns: [organizations.id], - name: 'collections_organization_id_fkey', - }).onUpdate('cascade'), - foreignKey({ - columns: [table.createdBy], - foreignColumns: [users.id], - name: 'collections_created_by_fkey', - }).onUpdate('cascade'), - foreignKey({ - columns: [table.updatedBy], - foreignColumns: [users.id], - name: 'collections_updated_by_fkey', - }).onUpdate('cascade'), - foreignKey({ - columns: [table.workspaceSharingEnabledBy], - foreignColumns: [users.id], - name: 'collections_workspace_sharing_enabled_by_fkey', - }).onUpdate('cascade'), - ] + "collections", + { + id: uuid().defaultRandom().primaryKey().notNull(), + name: text().notNull(), + description: text(), + createdBy: uuid("created_by").notNull(), + updatedBy: uuid("updated_by").notNull(), + createdAt: timestamp("created_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + updatedAt: timestamp("updated_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + deletedAt: timestamp("deleted_at", { withTimezone: true, mode: "string" }), + organizationId: uuid("organization_id").notNull(), + workspaceSharing: workspaceSharingEnum("workspace_sharing") + .default("none") + .notNull(), + workspaceSharingEnabledBy: uuid("workspace_sharing_enabled_by"), + workspaceSharingEnabledAt: timestamp("workspace_sharing_enabled_at", { + withTimezone: true, + mode: "string", + }), + }, + (table) => [ + foreignKey({ + columns: [table.organizationId], + foreignColumns: [organizations.id], + name: "collections_organization_id_fkey", + }).onUpdate("cascade"), + foreignKey({ + columns: [table.createdBy], + foreignColumns: [users.id], + name: "collections_created_by_fkey", + }).onUpdate("cascade"), + foreignKey({ + columns: [table.updatedBy], + foreignColumns: [users.id], + name: "collections_updated_by_fkey", + }).onUpdate("cascade"), + foreignKey({ + columns: [table.workspaceSharingEnabledBy], + foreignColumns: [users.id], + name: "collections_workspace_sharing_enabled_by_fkey", + }).onUpdate("cascade"), + ], ); export const dashboards = pgTable( - 'dashboards', - { - id: uuid().defaultRandom().primaryKey().notNull(), - name: text().notNull(), - description: text(), - config: jsonb().notNull(), - publiclyAccessible: boolean('publicly_accessible').default(false).notNull(), - publiclyEnabledBy: uuid('publicly_enabled_by'), - publicExpiryDate: timestamp('public_expiry_date', { - withTimezone: true, - mode: 'string', - }), - passwordSecretId: uuid('password_secret_id'), - createdBy: uuid('created_by').notNull(), - updatedBy: uuid('updated_by').notNull(), - createdAt: timestamp('created_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - updatedAt: timestamp('updated_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - deletedAt: timestamp('deleted_at', { withTimezone: true, mode: 'string' }), - organizationId: uuid('organization_id').notNull(), - }, - (table) => [ - foreignKey({ - columns: [table.publiclyEnabledBy], - foreignColumns: [users.id], - name: 'dashboards_publicly_enabled_by_fkey', - }).onUpdate('cascade'), - foreignKey({ - columns: [table.organizationId], - foreignColumns: [organizations.id], - name: 'dashboards_organization_id_fkey', - }).onUpdate('cascade'), - foreignKey({ - columns: [table.createdBy], - foreignColumns: [users.id], - name: 'dashboards_created_by_fkey', - }).onUpdate('cascade'), - foreignKey({ - columns: [table.updatedBy], - foreignColumns: [users.id], - name: 'dashboards_updated_by_fkey', - }).onUpdate('cascade'), - ] + "dashboards", + { + id: uuid().defaultRandom().primaryKey().notNull(), + name: text().notNull(), + description: text(), + config: jsonb().notNull(), + publiclyAccessible: boolean("publicly_accessible").default(false).notNull(), + publiclyEnabledBy: uuid("publicly_enabled_by"), + publicExpiryDate: timestamp("public_expiry_date", { + withTimezone: true, + mode: "string", + }), + passwordSecretId: uuid("password_secret_id"), + createdBy: uuid("created_by").notNull(), + updatedBy: uuid("updated_by").notNull(), + createdAt: timestamp("created_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + updatedAt: timestamp("updated_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + deletedAt: timestamp("deleted_at", { withTimezone: true, mode: "string" }), + organizationId: uuid("organization_id").notNull(), + }, + (table) => [ + foreignKey({ + columns: [table.publiclyEnabledBy], + foreignColumns: [users.id], + name: "dashboards_publicly_enabled_by_fkey", + }).onUpdate("cascade"), + foreignKey({ + columns: [table.organizationId], + foreignColumns: [organizations.id], + name: "dashboards_organization_id_fkey", + }).onUpdate("cascade"), + foreignKey({ + columns: [table.createdBy], + foreignColumns: [users.id], + name: "dashboards_created_by_fkey", + }).onUpdate("cascade"), + foreignKey({ + columns: [table.updatedBy], + foreignColumns: [users.id], + name: "dashboards_updated_by_fkey", + }).onUpdate("cascade"), + ], ); export const dashboardVersions = pgTable( - 'dashboard_versions', - { - id: uuid().defaultRandom().primaryKey().notNull(), - dashboardId: uuid('dashboard_id').notNull(), - config: jsonb().notNull(), - createdAt: timestamp('created_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - updatedAt: timestamp('updated_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - deletedAt: timestamp('deleted_at', { withTimezone: true, mode: 'string' }), - }, - (table) => [ - foreignKey({ - columns: [table.dashboardId], - foreignColumns: [dashboards.id], - name: 'dashboard_versions_dashboard_id_fkey', - }).onDelete('cascade'), - ] + "dashboard_versions", + { + id: uuid().defaultRandom().primaryKey().notNull(), + dashboardId: uuid("dashboard_id").notNull(), + config: jsonb().notNull(), + createdAt: timestamp("created_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + updatedAt: timestamp("updated_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + deletedAt: timestamp("deleted_at", { withTimezone: true, mode: "string" }), + }, + (table) => [ + foreignKey({ + columns: [table.dashboardId], + foreignColumns: [dashboards.id], + name: "dashboard_versions_dashboard_id_fkey", + }).onDelete("cascade"), + ], ); export const dataSources = pgTable( - 'data_sources', - { - id: uuid().defaultRandom().primaryKey().notNull(), - name: text().notNull(), - type: text().notNull(), - secretId: uuid('secret_id').notNull(), - onboardingStatus: dataSourceOnboardingStatusEnum('onboarding_status') - .default('notStarted') - .notNull(), - onboardingError: text('onboarding_error'), - organizationId: uuid('organization_id').notNull(), - createdBy: uuid('created_by').notNull(), - updatedBy: uuid('updated_by').notNull(), - createdAt: timestamp('created_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - updatedAt: timestamp('updated_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - deletedAt: timestamp('deleted_at', { withTimezone: true, mode: 'string' }), - env: varchar().default('dev').notNull(), - }, - (table) => [ - foreignKey({ - columns: [table.organizationId], - foreignColumns: [organizations.id], - name: 'data_sources_organization_id_fkey', - }).onDelete('cascade'), - foreignKey({ - columns: [table.createdBy], - foreignColumns: [users.id], - name: 'data_sources_created_by_fkey', - }).onUpdate('cascade'), - foreignKey({ - columns: [table.updatedBy], - foreignColumns: [users.id], - name: 'data_sources_updated_by_fkey', - }).onUpdate('cascade'), - unique('data_sources_name_organization_id_env_key').on( - table.name, - table.organizationId, - table.env - ), - ] + "data_sources", + { + id: uuid().defaultRandom().primaryKey().notNull(), + name: text().notNull(), + type: text().notNull(), + secretId: uuid("secret_id").notNull(), + onboardingStatus: dataSourceOnboardingStatusEnum("onboarding_status") + .default("notStarted") + .notNull(), + onboardingError: text("onboarding_error"), + organizationId: uuid("organization_id").notNull(), + createdBy: uuid("created_by").notNull(), + updatedBy: uuid("updated_by").notNull(), + createdAt: timestamp("created_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + updatedAt: timestamp("updated_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + deletedAt: timestamp("deleted_at", { withTimezone: true, mode: "string" }), + env: varchar().default("dev").notNull(), + }, + (table) => [ + foreignKey({ + columns: [table.organizationId], + foreignColumns: [organizations.id], + name: "data_sources_organization_id_fkey", + }).onDelete("cascade"), + foreignKey({ + columns: [table.createdBy], + foreignColumns: [users.id], + name: "data_sources_created_by_fkey", + }).onUpdate("cascade"), + foreignKey({ + columns: [table.updatedBy], + foreignColumns: [users.id], + name: "data_sources_updated_by_fkey", + }).onUpdate("cascade"), + unique("data_sources_name_organization_id_env_key").on( + table.name, + table.organizationId, + table.env, + ), + ], ); export const datasetColumns = pgTable( - 'dataset_columns', - { - id: uuid().primaryKey().notNull(), - datasetId: uuid('dataset_id').notNull(), - name: text().notNull(), - type: text().notNull(), - description: text(), - nullable: boolean().notNull(), - createdAt: timestamp('created_at', { - withTimezone: true, - mode: 'string', - }).notNull(), - updatedAt: timestamp('updated_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - deletedAt: timestamp('deleted_at', { withTimezone: true, mode: 'string' }), - storedValues: boolean('stored_values').default(false), - storedValuesStatus: storedValuesStatusEnum('stored_values_status'), - storedValuesError: text('stored_values_error'), - // You can use { mode: "bigint" } if numbers are exceeding js number limitations - storedValuesCount: bigint('stored_values_count', { mode: 'number' }), - storedValuesLastSynced: timestamp('stored_values_last_synced', { - withTimezone: true, - mode: 'string', - }), - semanticType: text('semantic_type'), - dimType: text('dim_type'), - expr: text(), - }, - (table) => [unique('unique_dataset_column_name').on(table.datasetId, table.name)] + "dataset_columns", + { + id: uuid().primaryKey().notNull(), + datasetId: uuid("dataset_id").notNull(), + name: text().notNull(), + type: text().notNull(), + description: text(), + nullable: boolean().notNull(), + createdAt: timestamp("created_at", { + withTimezone: true, + mode: "string", + }).notNull(), + updatedAt: timestamp("updated_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + deletedAt: timestamp("deleted_at", { withTimezone: true, mode: "string" }), + storedValues: boolean("stored_values").default(false), + storedValuesStatus: storedValuesStatusEnum("stored_values_status"), + storedValuesError: text("stored_values_error"), + // You can use { mode: "bigint" } if numbers are exceeding js number limitations + storedValuesCount: bigint("stored_values_count", { mode: "number" }), + storedValuesLastSynced: timestamp("stored_values_last_synced", { + withTimezone: true, + mode: "string", + }), + semanticType: text("semantic_type"), + dimType: text("dim_type"), + expr: text(), + }, + (table) => [ + unique("unique_dataset_column_name").on(table.datasetId, table.name), + ], ); -export const sqlEvaluations = pgTable('sql_evaluations', { - id: uuid().default(sql`uuid_generate_v4()`).primaryKey().notNull(), - evaluationObj: jsonb('evaluation_obj').notNull(), - evaluationSummary: text('evaluation_summary').notNull(), - score: text().notNull(), - createdAt: timestamp('created_at', { withTimezone: true, mode: 'string' }).defaultNow().notNull(), - updatedAt: timestamp('updated_at', { withTimezone: true, mode: 'string' }).defaultNow().notNull(), - deletedAt: timestamp('deleted_at', { withTimezone: true, mode: 'string' }), +export const sqlEvaluations = pgTable("sql_evaluations", { + id: uuid().default(sql`uuid_generate_v4()`).primaryKey().notNull(), + evaluationObj: jsonb("evaluation_obj").notNull(), + evaluationSummary: text("evaluation_summary").notNull(), + score: text().notNull(), + createdAt: timestamp("created_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + updatedAt: timestamp("updated_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + deletedAt: timestamp("deleted_at", { withTimezone: true, mode: "string" }), }); export const assetSearch = pgTable( - 'asset_search', - { - id: uuid().defaultRandom().primaryKey().notNull(), - assetId: uuid('asset_id').notNull(), - // The assetType column is a plain string (text), not an enum. - assetType: text('asset_type').notNull(), - content: text().notNull(), - organizationId: uuid('organization_id').notNull(), - createdAt: timestamp('created_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - updatedAt: timestamp('updated_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - deletedAt: timestamp('deleted_at', { withTimezone: true, mode: 'string' }), - }, - (table) => [ - uniqueIndex('asset_search_asset_id_asset_type_idx').using( - 'btree', - table.assetId.asc().nullsLast().op('text_ops'), - table.assetType.asc().nullsLast().op('text_ops') - ), - index('pgroonga_content_index').using( - 'pgroonga', - table.content.asc().nullsLast().op('pgroonga_text_full_text_search_ops_v2') - ), - ] + "asset_search", + { + id: uuid().defaultRandom().primaryKey().notNull(), + assetId: uuid("asset_id").notNull(), + // The assetType column is a plain string (text), not an enum. + assetType: text("asset_type").notNull(), + content: text().notNull(), + organizationId: uuid("organization_id").notNull(), + createdAt: timestamp("created_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + updatedAt: timestamp("updated_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + deletedAt: timestamp("deleted_at", { withTimezone: true, mode: "string" }), + }, + (table) => [ + uniqueIndex("asset_search_asset_id_asset_type_idx").using( + "btree", + table.assetId.asc().nullsLast().op("text_ops"), + table.assetType.asc().nullsLast().op("text_ops"), + ), + index("pgroonga_content_index").using( + "pgroonga", + table.content + .asc() + .nullsLast() + .op("pgroonga_text_full_text_search_ops_v2"), + ), + ], ); export const datasetGroups = pgTable( - 'dataset_groups', - { - id: uuid().defaultRandom().primaryKey().notNull(), - organizationId: uuid('organization_id').notNull(), - name: varchar().notNull(), - createdAt: timestamp('created_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - updatedAt: timestamp('updated_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - deletedAt: timestamp('deleted_at', { withTimezone: true, mode: 'string' }), - }, - (table) => [ - index('dataset_groups_deleted_at_idx').using( - 'btree', - table.deletedAt.asc().nullsLast().op('timestamptz_ops') - ), - index('dataset_groups_organization_id_idx').using( - 'btree', - table.organizationId.asc().nullsLast().op('uuid_ops') - ), - foreignKey({ - columns: [table.organizationId], - foreignColumns: [organizations.id], - name: 'dataset_groups_organization_id_fkey', - }).onDelete('cascade'), - pgPolicy('dataset_groups_policy', { - as: 'permissive', - for: 'all', - to: ['authenticated'], - using: sql`true`, - }), - ] + "dataset_groups", + { + id: uuid().defaultRandom().primaryKey().notNull(), + organizationId: uuid("organization_id").notNull(), + name: varchar().notNull(), + createdAt: timestamp("created_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + updatedAt: timestamp("updated_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + deletedAt: timestamp("deleted_at", { withTimezone: true, mode: "string" }), + }, + (table) => [ + index("dataset_groups_deleted_at_idx").using( + "btree", + table.deletedAt.asc().nullsLast().op("timestamptz_ops"), + ), + index("dataset_groups_organization_id_idx").using( + "btree", + table.organizationId.asc().nullsLast().op("uuid_ops"), + ), + foreignKey({ + columns: [table.organizationId], + foreignColumns: [organizations.id], + name: "dataset_groups_organization_id_fkey", + }).onDelete("cascade"), + pgPolicy("dataset_groups_policy", { + as: "permissive", + for: "all", + to: ["authenticated"], + using: sql`true`, + }), + ], ); export const datasetPermissions = pgTable( - 'dataset_permissions', - { - id: uuid().defaultRandom().primaryKey().notNull(), - organizationId: uuid('organization_id').notNull(), - datasetId: uuid('dataset_id').notNull(), - permissionId: uuid('permission_id').notNull(), - permissionType: varchar('permission_type').notNull(), - createdAt: timestamp('created_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - updatedAt: timestamp('updated_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - deletedAt: timestamp('deleted_at', { withTimezone: true, mode: 'string' }), - }, - (table) => [ - index('dataset_permissions_dataset_id_idx').using( - 'btree', - table.datasetId.asc().nullsLast().op('uuid_ops') - ), - index('dataset_permissions_deleted_at_idx').using( - 'btree', - table.deletedAt.asc().nullsLast().op('timestamptz_ops') - ), - index('dataset_permissions_organization_id_idx').using( - 'btree', - table.organizationId.asc().nullsLast().op('uuid_ops') - ), - index('dataset_permissions_permission_lookup_idx').using( - 'btree', - table.permissionId.asc().nullsLast().op('uuid_ops'), - table.permissionType.asc().nullsLast().op('text_ops') - ), - foreignKey({ - columns: [table.organizationId], - foreignColumns: [organizations.id], - name: 'dataset_permissions_organization_id_fkey', - }).onDelete('cascade'), - foreignKey({ - columns: [table.datasetId], - foreignColumns: [datasets.id], - name: 'dataset_permissions_dataset_id_fkey', - }).onDelete('cascade'), - unique('dataset_permissions_dataset_id_permission_id_permission_typ_key').on( - table.datasetId, - table.permissionId, - table.permissionType - ), - pgPolicy('dataset_permissions_policy', { - as: 'permissive', - for: 'all', - to: ['authenticated'], - using: sql`true`, - }), - check( - 'dataset_permissions_permission_type_check', - sql`(permission_type)::text = ANY ((ARRAY['user'::character varying, 'dataset_group'::character varying, 'permission_group'::character varying])::text[])` - ), - ] + "dataset_permissions", + { + id: uuid().defaultRandom().primaryKey().notNull(), + organizationId: uuid("organization_id").notNull(), + datasetId: uuid("dataset_id").notNull(), + permissionId: uuid("permission_id").notNull(), + permissionType: varchar("permission_type").notNull(), + createdAt: timestamp("created_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + updatedAt: timestamp("updated_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + deletedAt: timestamp("deleted_at", { withTimezone: true, mode: "string" }), + }, + (table) => [ + index("dataset_permissions_dataset_id_idx").using( + "btree", + table.datasetId.asc().nullsLast().op("uuid_ops"), + ), + index("dataset_permissions_deleted_at_idx").using( + "btree", + table.deletedAt.asc().nullsLast().op("timestamptz_ops"), + ), + index("dataset_permissions_organization_id_idx").using( + "btree", + table.organizationId.asc().nullsLast().op("uuid_ops"), + ), + index("dataset_permissions_permission_lookup_idx").using( + "btree", + table.permissionId.asc().nullsLast().op("uuid_ops"), + table.permissionType.asc().nullsLast().op("text_ops"), + ), + foreignKey({ + columns: [table.organizationId], + foreignColumns: [organizations.id], + name: "dataset_permissions_organization_id_fkey", + }).onDelete("cascade"), + foreignKey({ + columns: [table.datasetId], + foreignColumns: [datasets.id], + name: "dataset_permissions_dataset_id_fkey", + }).onDelete("cascade"), + unique( + "dataset_permissions_dataset_id_permission_id_permission_typ_key", + ).on(table.datasetId, table.permissionId, table.permissionType), + pgPolicy("dataset_permissions_policy", { + as: "permissive", + for: "all", + to: ["authenticated"], + using: sql`true`, + }), + check( + "dataset_permissions_permission_type_check", + sql`(permission_type)::text = ANY ((ARRAY['user'::character varying, 'dataset_group'::character varying, 'permission_group'::character varying])::text[])`, + ), + ], ); export const dieselSchemaMigrations = pgTable( - '__diesel_schema_migrations', - { - version: varchar({ length: 50 }).primaryKey().notNull(), - runOn: timestamp('run_on', { mode: 'string' }).default(sql`CURRENT_TIMESTAMP`).notNull(), - }, - (_table) => [ - pgPolicy('diesel_schema_migrations_policy', { - as: 'permissive', - for: 'all', - to: ['authenticated'], - using: sql`true`, - }), - ] + "__diesel_schema_migrations", + { + version: varchar({ length: 50 }).primaryKey().notNull(), + runOn: timestamp("run_on", { mode: "string" }) + .default(sql`CURRENT_TIMESTAMP`) + .notNull(), + }, + (_table) => [ + pgPolicy("diesel_schema_migrations_policy", { + as: "permissive", + for: "all", + to: ["authenticated"], + using: sql`true`, + }), + ], ); export const datasetGroupsPermissions = pgTable( - 'dataset_groups_permissions', - { - id: uuid().defaultRandom().primaryKey().notNull(), - datasetGroupId: uuid('dataset_group_id').notNull(), - permissionId: uuid('permission_id').notNull(), - permissionType: varchar('permission_type').notNull(), - organizationId: uuid('organization_id').notNull(), - createdAt: timestamp('created_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - updatedAt: timestamp('updated_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - deletedAt: timestamp('deleted_at', { withTimezone: true, mode: 'string' }), - }, - (table) => [ - index('dataset_groups_permissions_dataset_group_id_idx').using( - 'btree', - table.datasetGroupId.asc().nullsLast().op('uuid_ops') - ), - index('dataset_groups_permissions_organization_id_idx').using( - 'btree', - table.organizationId.asc().nullsLast().op('uuid_ops') - ), - index('dataset_groups_permissions_permission_id_idx').using( - 'btree', - table.permissionId.asc().nullsLast().op('uuid_ops') - ), - foreignKey({ - columns: [table.datasetGroupId], - foreignColumns: [datasetGroups.id], - name: 'dataset_groups_permissions_dataset_group_id_fkey', - }), - foreignKey({ - columns: [table.organizationId], - foreignColumns: [organizations.id], - name: 'dataset_groups_permissions_organization_id_fkey', - }), - unique('unique_dataset_group_permission').on( - table.datasetGroupId, - table.permissionId, - table.permissionType - ), - ] + "dataset_groups_permissions", + { + id: uuid().defaultRandom().primaryKey().notNull(), + datasetGroupId: uuid("dataset_group_id").notNull(), + permissionId: uuid("permission_id").notNull(), + permissionType: varchar("permission_type").notNull(), + organizationId: uuid("organization_id").notNull(), + createdAt: timestamp("created_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + updatedAt: timestamp("updated_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + deletedAt: timestamp("deleted_at", { withTimezone: true, mode: "string" }), + }, + (table) => [ + index("dataset_groups_permissions_dataset_group_id_idx").using( + "btree", + table.datasetGroupId.asc().nullsLast().op("uuid_ops"), + ), + index("dataset_groups_permissions_organization_id_idx").using( + "btree", + table.organizationId.asc().nullsLast().op("uuid_ops"), + ), + index("dataset_groups_permissions_permission_id_idx").using( + "btree", + table.permissionId.asc().nullsLast().op("uuid_ops"), + ), + foreignKey({ + columns: [table.datasetGroupId], + foreignColumns: [datasetGroups.id], + name: "dataset_groups_permissions_dataset_group_id_fkey", + }), + foreignKey({ + columns: [table.organizationId], + foreignColumns: [organizations.id], + name: "dataset_groups_permissions_organization_id_fkey", + }), + unique("unique_dataset_group_permission").on( + table.datasetGroupId, + table.permissionId, + table.permissionType, + ), + ], ); export const threadsDeprecated = pgTable( - 'threads_deprecated', - { - id: uuid().defaultRandom().primaryKey().notNull(), - createdBy: uuid('created_by').notNull(), - updatedBy: uuid('updated_by').notNull(), - publiclyAccessible: boolean('publicly_accessible').default(false).notNull(), - publiclyEnabledBy: uuid('publicly_enabled_by'), - publicExpiryDate: timestamp('public_expiry_date', { - withTimezone: true, - mode: 'string', - }), - passwordSecretId: uuid('password_secret_id'), - stateMessageId: uuid('state_message_id'), - parentThreadId: uuid('parent_thread_id'), - createdAt: timestamp('created_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - updatedAt: timestamp('updated_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - deletedAt: timestamp('deleted_at', { withTimezone: true, mode: 'string' }), - organizationId: uuid('organization_id').notNull(), - }, - (table) => [ - foreignKey({ - columns: [table.createdBy], - foreignColumns: [users.id], - name: 'threads_created_by_fkey', - }).onUpdate('cascade'), - foreignKey({ - columns: [table.updatedBy], - foreignColumns: [users.id], - name: 'threads_updated_by_fkey', - }).onUpdate('cascade'), - foreignKey({ - columns: [table.publiclyEnabledBy], - foreignColumns: [users.id], - name: 'threads_publicly_enabled_by_fkey', - }).onUpdate('cascade'), - foreignKey({ - columns: [table.parentThreadId], - foreignColumns: [table.id], - name: 'threads_parent_thread_id_fkey', - }).onUpdate('cascade'), - foreignKey({ - columns: [table.organizationId], - foreignColumns: [organizations.id], - name: 'threads_organization_id_fkey', - }), - foreignKey({ - columns: [table.createdBy], - foreignColumns: [users.id], - name: 'threads_deprecated_created_by_fkey', - }).onUpdate('cascade'), - foreignKey({ - columns: [table.updatedBy], - foreignColumns: [users.id], - name: 'threads_deprecated_updated_by_fkey', - }).onUpdate('cascade'), - foreignKey({ - columns: [table.publiclyEnabledBy], - foreignColumns: [users.id], - name: 'threads_deprecated_publicly_enabled_by_fkey', - }).onUpdate('cascade'), - ] + "threads_deprecated", + { + id: uuid().defaultRandom().primaryKey().notNull(), + createdBy: uuid("created_by").notNull(), + updatedBy: uuid("updated_by").notNull(), + publiclyAccessible: boolean("publicly_accessible").default(false).notNull(), + publiclyEnabledBy: uuid("publicly_enabled_by"), + publicExpiryDate: timestamp("public_expiry_date", { + withTimezone: true, + mode: "string", + }), + passwordSecretId: uuid("password_secret_id"), + stateMessageId: uuid("state_message_id"), + parentThreadId: uuid("parent_thread_id"), + createdAt: timestamp("created_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + updatedAt: timestamp("updated_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + deletedAt: timestamp("deleted_at", { withTimezone: true, mode: "string" }), + organizationId: uuid("organization_id").notNull(), + }, + (table) => [ + foreignKey({ + columns: [table.createdBy], + foreignColumns: [users.id], + name: "threads_created_by_fkey", + }).onUpdate("cascade"), + foreignKey({ + columns: [table.updatedBy], + foreignColumns: [users.id], + name: "threads_updated_by_fkey", + }).onUpdate("cascade"), + foreignKey({ + columns: [table.publiclyEnabledBy], + foreignColumns: [users.id], + name: "threads_publicly_enabled_by_fkey", + }).onUpdate("cascade"), + foreignKey({ + columns: [table.parentThreadId], + foreignColumns: [table.id], + name: "threads_parent_thread_id_fkey", + }).onUpdate("cascade"), + foreignKey({ + columns: [table.organizationId], + foreignColumns: [organizations.id], + name: "threads_organization_id_fkey", + }), + foreignKey({ + columns: [table.createdBy], + foreignColumns: [users.id], + name: "threads_deprecated_created_by_fkey", + }).onUpdate("cascade"), + foreignKey({ + columns: [table.updatedBy], + foreignColumns: [users.id], + name: "threads_deprecated_updated_by_fkey", + }).onUpdate("cascade"), + foreignKey({ + columns: [table.publiclyEnabledBy], + foreignColumns: [users.id], + name: "threads_deprecated_publicly_enabled_by_fkey", + }).onUpdate("cascade"), + ], ); export const messagesDeprecated = pgTable( - 'messages_deprecated', - { - id: uuid().defaultRandom().primaryKey().notNull(), - threadId: uuid('thread_id').notNull(), - sentBy: uuid('sent_by').notNull(), - message: text().notNull(), - responses: jsonb(), - code: text(), - context: jsonb(), - title: text(), - feedback: messageFeedbackEnum(), - verification: verificationEnum().default('notRequested').notNull(), - datasetId: uuid('dataset_id'), - chartConfig: jsonb('chart_config').default({}), - chartRecommendations: jsonb('chart_recommendations').default({}), - timeFrame: text('time_frame'), - dataMetadata: jsonb('data_metadata'), - draftSessionId: uuid('draft_session_id'), - createdAt: timestamp('created_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - updatedAt: timestamp('updated_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - deletedAt: timestamp('deleted_at', { withTimezone: true, mode: 'string' }), - draftState: jsonb('draft_state'), - summaryQuestion: text('summary_question'), - sqlEvaluationId: uuid('sql_evaluation_id'), - }, - (table) => [ - foreignKey({ - columns: [table.sentBy], - foreignColumns: [users.id], - name: 'messages_sent_by_fkey', - }).onUpdate('cascade'), - foreignKey({ - columns: [table.datasetId], - foreignColumns: [datasets.id], - name: 'messages_dataset_id_fkey', - }).onDelete('cascade'), - foreignKey({ - columns: [table.sentBy], - foreignColumns: [users.id], - name: 'messages_deprecated_sent_by_fkey', - }).onUpdate('cascade'), - ] + "messages_deprecated", + { + id: uuid().defaultRandom().primaryKey().notNull(), + threadId: uuid("thread_id").notNull(), + sentBy: uuid("sent_by").notNull(), + message: text().notNull(), + responses: jsonb(), + code: text(), + context: jsonb(), + title: text(), + feedback: messageFeedbackEnum(), + verification: verificationEnum().default("notRequested").notNull(), + datasetId: uuid("dataset_id"), + chartConfig: jsonb("chart_config").default({}), + chartRecommendations: jsonb("chart_recommendations").default({}), + timeFrame: text("time_frame"), + dataMetadata: jsonb("data_metadata"), + draftSessionId: uuid("draft_session_id"), + createdAt: timestamp("created_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + updatedAt: timestamp("updated_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + deletedAt: timestamp("deleted_at", { withTimezone: true, mode: "string" }), + draftState: jsonb("draft_state"), + summaryQuestion: text("summary_question"), + sqlEvaluationId: uuid("sql_evaluation_id"), + }, + (table) => [ + foreignKey({ + columns: [table.sentBy], + foreignColumns: [users.id], + name: "messages_sent_by_fkey", + }).onUpdate("cascade"), + foreignKey({ + columns: [table.datasetId], + foreignColumns: [datasets.id], + name: "messages_dataset_id_fkey", + }).onDelete("cascade"), + foreignKey({ + columns: [table.sentBy], + foreignColumns: [users.id], + name: "messages_deprecated_sent_by_fkey", + }).onUpdate("cascade"), + ], ); export const datasets = pgTable( - 'datasets', - { - id: uuid().defaultRandom().primaryKey().notNull(), - name: text().notNull(), - databaseName: text('database_name').notNull(), - whenToUse: text('when_to_use'), - whenNotToUse: text('when_not_to_use'), - type: datasetTypeEnum().notNull(), - definition: text().notNull(), - schema: text().notNull(), - enabled: boolean().default(false).notNull(), - imported: boolean().default(false).notNull(), - dataSourceId: uuid('data_source_id').notNull(), - organizationId: uuid('organization_id').notNull(), - createdBy: uuid('created_by').notNull(), - updatedBy: uuid('updated_by').notNull(), - createdAt: timestamp('created_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - updatedAt: timestamp('updated_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - deletedAt: timestamp('deleted_at', { withTimezone: true, mode: 'string' }), - model: text(), - ymlFile: text('yml_file'), - databaseIdentifier: text('database_identifier'), - }, - (table) => [ - foreignKey({ - columns: [table.dataSourceId], - foreignColumns: [dataSources.id], - name: 'datasets_data_source_id_fkey', - }).onDelete('cascade'), - foreignKey({ - columns: [table.organizationId], - foreignColumns: [organizations.id], - name: 'datasets_organization_id_fkey', - }).onDelete('cascade'), - foreignKey({ - columns: [table.createdBy], - foreignColumns: [users.id], - name: 'datasets_created_by_fkey', - }).onUpdate('cascade'), - foreignKey({ - columns: [table.updatedBy], - foreignColumns: [users.id], - name: 'datasets_updated_by_fkey', - }).onUpdate('cascade'), - unique('datasets_database_name_data_source_id_key').on(table.databaseName, table.dataSourceId), - ] + "datasets", + { + id: uuid().defaultRandom().primaryKey().notNull(), + name: text().notNull(), + databaseName: text("database_name").notNull(), + whenToUse: text("when_to_use"), + whenNotToUse: text("when_not_to_use"), + type: datasetTypeEnum().notNull(), + definition: text().notNull(), + schema: text().notNull(), + enabled: boolean().default(false).notNull(), + imported: boolean().default(false).notNull(), + dataSourceId: uuid("data_source_id").notNull(), + organizationId: uuid("organization_id").notNull(), + createdBy: uuid("created_by").notNull(), + updatedBy: uuid("updated_by").notNull(), + createdAt: timestamp("created_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + updatedAt: timestamp("updated_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + deletedAt: timestamp("deleted_at", { withTimezone: true, mode: "string" }), + model: text(), + ymlFile: text("yml_file"), + databaseIdentifier: text("database_identifier"), + }, + (table) => [ + foreignKey({ + columns: [table.dataSourceId], + foreignColumns: [dataSources.id], + name: "datasets_data_source_id_fkey", + }).onDelete("cascade"), + foreignKey({ + columns: [table.organizationId], + foreignColumns: [organizations.id], + name: "datasets_organization_id_fkey", + }).onDelete("cascade"), + foreignKey({ + columns: [table.createdBy], + foreignColumns: [users.id], + name: "datasets_created_by_fkey", + }).onUpdate("cascade"), + foreignKey({ + columns: [table.updatedBy], + foreignColumns: [users.id], + name: "datasets_updated_by_fkey", + }).onUpdate("cascade"), + unique("datasets_database_name_data_source_id_key").on( + table.databaseName, + table.dataSourceId, + ), + ], ); export const users = pgTable( - 'users', - { - id: uuid().defaultRandom().primaryKey().notNull(), - email: text().notNull(), - name: text(), - config: jsonb().default({}).notNull(), - createdAt: timestamp('created_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - updatedAt: timestamp('updated_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - attributes: jsonb().default({}).notNull(), - avatarUrl: text('avatar_url'), - }, - (table) => [unique('users_email_key').on(table.email)] + "users", + { + id: uuid().defaultRandom().primaryKey().notNull(), + email: text().notNull(), + name: text(), + config: jsonb().default({}).notNull(), + createdAt: timestamp("created_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + updatedAt: timestamp("updated_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + attributes: jsonb().default({}).notNull(), + avatarUrl: text("avatar_url"), + }, + (table) => [unique("users_email_key").on(table.email)], ); export const messages = pgTable( - 'messages', - { - id: uuid().defaultRandom().primaryKey().notNull(), - requestMessage: text('request_message'), - responseMessages: jsonb('response_messages').notNull(), - reasoning: jsonb().notNull(), - title: text().notNull(), - rawLlmMessages: jsonb('raw_llm_messages').notNull(), - finalReasoningMessage: text('final_reasoning_message'), - chatId: uuid('chat_id').notNull(), - createdAt: timestamp('created_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - updatedAt: timestamp('updated_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - deletedAt: timestamp('deleted_at', { withTimezone: true, mode: 'string' }), - createdBy: uuid('created_by').notNull(), - feedback: text(), - isCompleted: boolean('is_completed').default(false).notNull(), - postProcessingMessage: jsonb('post_processing_message'), - triggerRunId: text('trigger_run_id'), - }, - (table) => [ - index('messages_chat_id_idx').using('btree', table.chatId.asc().nullsLast().op('uuid_ops')), - index('messages_created_at_idx').using( - 'btree', - table.createdAt.asc().nullsLast().op('timestamptz_ops') - ), - index('messages_created_by_idx').using( - 'btree', - table.createdBy.asc().nullsLast().op('uuid_ops') - ), - foreignKey({ - columns: [table.chatId], - foreignColumns: [chats.id], - name: 'messages_chat_id_fkey', - }), - foreignKey({ - columns: [table.createdBy], - foreignColumns: [users.id], - name: 'messages_created_by_fkey', - }).onUpdate('cascade'), - ] + "messages", + { + id: uuid().defaultRandom().primaryKey().notNull(), + requestMessage: text("request_message"), + responseMessages: jsonb("response_messages").notNull(), + reasoning: jsonb().notNull(), + title: text().notNull(), + rawLlmMessages: jsonb("raw_llm_messages").notNull(), + finalReasoningMessage: text("final_reasoning_message"), + chatId: uuid("chat_id").notNull(), + createdAt: timestamp("created_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + updatedAt: timestamp("updated_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + deletedAt: timestamp("deleted_at", { withTimezone: true, mode: "string" }), + createdBy: uuid("created_by").notNull(), + feedback: text(), + isCompleted: boolean("is_completed").default(false).notNull(), + postProcessingMessage: jsonb("post_processing_message"), + triggerRunId: text("trigger_run_id"), + }, + (table) => [ + index("messages_chat_id_idx").using( + "btree", + table.chatId.asc().nullsLast().op("uuid_ops"), + ), + index("messages_created_at_idx").using( + "btree", + table.createdAt.asc().nullsLast().op("timestamptz_ops"), + ), + index("messages_created_by_idx").using( + "btree", + table.createdBy.asc().nullsLast().op("uuid_ops"), + ), + foreignKey({ + columns: [table.chatId], + foreignColumns: [chats.id], + name: "messages_chat_id_fkey", + }), + foreignKey({ + columns: [table.createdBy], + foreignColumns: [users.id], + name: "messages_created_by_fkey", + }).onUpdate("cascade"), + ], ); export const messagesToFiles = pgTable( - 'messages_to_files', - { - id: uuid().primaryKey().notNull(), - messageId: uuid('message_id').notNull(), - fileId: uuid('file_id').notNull(), - createdAt: timestamp('created_at', { withTimezone: true, mode: 'string' }) - .default(sql`CURRENT_TIMESTAMP`) - .notNull(), - updatedAt: timestamp('updated_at', { withTimezone: true, mode: 'string' }) - .default(sql`CURRENT_TIMESTAMP`) - .notNull(), - deletedAt: timestamp('deleted_at', { withTimezone: true, mode: 'string' }), - isDuplicate: boolean('is_duplicate').default(false).notNull(), - versionNumber: integer('version_number').default(1).notNull(), - }, - (table) => [ - index('messages_files_file_id_idx').using( - 'btree', - table.fileId.asc().nullsLast().op('uuid_ops') - ), - index('messages_files_message_id_idx').using( - 'btree', - table.messageId.asc().nullsLast().op('uuid_ops') - ), - foreignKey({ - columns: [table.messageId], - foreignColumns: [messages.id], - name: 'messages_to_files_message_id_fkey', - }), - unique('messages_to_files_message_id_file_id_key').on(table.messageId, table.fileId), - ] + "messages_to_files", + { + id: uuid().primaryKey().notNull(), + messageId: uuid("message_id").notNull(), + fileId: uuid("file_id").notNull(), + createdAt: timestamp("created_at", { withTimezone: true, mode: "string" }) + .default(sql`CURRENT_TIMESTAMP`) + .notNull(), + updatedAt: timestamp("updated_at", { withTimezone: true, mode: "string" }) + .default(sql`CURRENT_TIMESTAMP`) + .notNull(), + deletedAt: timestamp("deleted_at", { withTimezone: true, mode: "string" }), + isDuplicate: boolean("is_duplicate").default(false).notNull(), + versionNumber: integer("version_number").default(1).notNull(), + }, + (table) => [ + index("messages_files_file_id_idx").using( + "btree", + table.fileId.asc().nullsLast().op("uuid_ops"), + ), + index("messages_files_message_id_idx").using( + "btree", + table.messageId.asc().nullsLast().op("uuid_ops"), + ), + foreignKey({ + columns: [table.messageId], + foreignColumns: [messages.id], + name: "messages_to_files_message_id_fkey", + }), + unique("messages_to_files_message_id_file_id_key").on( + table.messageId, + table.fileId, + ), + ], ); export const dashboardFiles = pgTable( - 'dashboard_files', - { - id: uuid().defaultRandom().primaryKey().notNull(), - name: varchar().notNull(), - fileName: varchar('file_name').notNull(), - content: jsonb().notNull().default([]), - filter: varchar(), - organizationId: uuid('organization_id').notNull(), - createdBy: uuid('created_by').notNull(), - createdAt: timestamp('created_at', { withTimezone: true, mode: 'string' }) - .default(sql`CURRENT_TIMESTAMP`) - .notNull(), - updatedAt: timestamp('updated_at', { withTimezone: true, mode: 'string' }) - .default(sql`CURRENT_TIMESTAMP`) - .notNull(), - deletedAt: timestamp('deleted_at', { withTimezone: true, mode: 'string' }), - publiclyAccessible: boolean('publicly_accessible').default(false).notNull(), - publiclyEnabledBy: uuid('publicly_enabled_by'), - publicExpiryDate: timestamp('public_expiry_date', { - withTimezone: true, - mode: 'string', - }), - versionHistory: jsonb('version_history').default({}).notNull(), - publicPassword: text('public_password'), - workspaceSharing: workspaceSharingEnum('workspace_sharing').default('none').notNull(), - workspaceSharingEnabledBy: uuid('workspace_sharing_enabled_by'), - workspaceSharingEnabledAt: timestamp('workspace_sharing_enabled_at', { - withTimezone: true, - mode: 'string', - }), - }, - (table) => [ - index('dashboard_files_created_by_idx').using( - 'btree', - table.createdBy.asc().nullsLast().op('uuid_ops') - ), - index('dashboard_files_deleted_at_idx').using( - 'btree', - table.deletedAt.asc().nullsLast().op('timestamptz_ops') - ), - index('dashboard_files_organization_id_idx').using( - 'btree', - table.organizationId.asc().nullsLast().op('uuid_ops') - ), - foreignKey({ - columns: [table.createdBy], - foreignColumns: [users.id], - name: 'dashboard_files_created_by_fkey', - }).onUpdate('cascade'), - foreignKey({ - columns: [table.publiclyEnabledBy], - foreignColumns: [users.id], - name: 'dashboard_files_publicly_enabled_by_fkey', - }).onUpdate('cascade'), - foreignKey({ - columns: [table.workspaceSharingEnabledBy], - foreignColumns: [users.id], - name: 'dashboard_files_workspace_sharing_enabled_by_fkey', - }).onUpdate('cascade'), - ] + "dashboard_files", + { + id: uuid().defaultRandom().primaryKey().notNull(), + name: varchar().notNull(), + fileName: varchar("file_name").notNull(), + content: jsonb().notNull().default([]), + filter: varchar(), + organizationId: uuid("organization_id").notNull(), + createdBy: uuid("created_by").notNull(), + createdAt: timestamp("created_at", { withTimezone: true, mode: "string" }) + .default(sql`CURRENT_TIMESTAMP`) + .notNull(), + updatedAt: timestamp("updated_at", { withTimezone: true, mode: "string" }) + .default(sql`CURRENT_TIMESTAMP`) + .notNull(), + deletedAt: timestamp("deleted_at", { withTimezone: true, mode: "string" }), + publiclyAccessible: boolean("publicly_accessible").default(false).notNull(), + publiclyEnabledBy: uuid("publicly_enabled_by"), + publicExpiryDate: timestamp("public_expiry_date", { + withTimezone: true, + mode: "string", + }), + versionHistory: jsonb("version_history").default({}).notNull(), + publicPassword: text("public_password"), + workspaceSharing: workspaceSharingEnum("workspace_sharing") + .default("none") + .notNull(), + workspaceSharingEnabledBy: uuid("workspace_sharing_enabled_by"), + workspaceSharingEnabledAt: timestamp("workspace_sharing_enabled_at", { + withTimezone: true, + mode: "string", + }), + }, + (table) => [ + index("dashboard_files_created_by_idx").using( + "btree", + table.createdBy.asc().nullsLast().op("uuid_ops"), + ), + index("dashboard_files_deleted_at_idx").using( + "btree", + table.deletedAt.asc().nullsLast().op("timestamptz_ops"), + ), + index("dashboard_files_organization_id_idx").using( + "btree", + table.organizationId.asc().nullsLast().op("uuid_ops"), + ), + foreignKey({ + columns: [table.createdBy], + foreignColumns: [users.id], + name: "dashboard_files_created_by_fkey", + }).onUpdate("cascade"), + foreignKey({ + columns: [table.publiclyEnabledBy], + foreignColumns: [users.id], + name: "dashboard_files_publicly_enabled_by_fkey", + }).onUpdate("cascade"), + foreignKey({ + columns: [table.workspaceSharingEnabledBy], + foreignColumns: [users.id], + name: "dashboard_files_workspace_sharing_enabled_by_fkey", + }).onUpdate("cascade"), + ], ); export const reportFiles = pgTable( - 'report_files', - { - id: uuid().defaultRandom().primaryKey().notNull(), - name: varchar().notNull(), - content: jsonb('content').$type().notNull(), - organizationId: uuid('organization_id').notNull(), - createdBy: uuid('created_by').notNull(), - createdAt: timestamp('created_at', { withTimezone: true, mode: 'string' }) - .default(sql`CURRENT_TIMESTAMP`) - .notNull(), - updatedAt: timestamp('updated_at', { withTimezone: true, mode: 'string' }) - .default(sql`CURRENT_TIMESTAMP`) - .notNull(), - deletedAt: timestamp('deleted_at', { withTimezone: true, mode: 'string' }), - publiclyAccessible: boolean('publicly_accessible').default(false).notNull(), - publiclyEnabledBy: uuid('publicly_enabled_by'), - publicExpiryDate: timestamp('public_expiry_date', { - withTimezone: true, - mode: 'string', - }), - versionHistory: jsonb('version_history') - .$type< - Record< - string, //version number as a string - { - content: ReportElements; - updated_at: string; - version_number: number; - } - > - >() - .default({}) - .notNull(), - publicPassword: text('public_password'), - workspaceSharing: workspaceSharingEnum('workspace_sharing').default('none').notNull(), - workspaceSharingEnabledBy: uuid('workspace_sharing_enabled_by'), - workspaceSharingEnabledAt: timestamp('workspace_sharing_enabled_at', { - withTimezone: true, - mode: 'string', - }), - }, - (table) => [ - index('report_files_created_by_idx').using( - 'btree', - table.createdBy.asc().nullsLast().op('uuid_ops') - ), - index('report_files_deleted_at_idx').using( - 'btree', - table.deletedAt.asc().nullsLast().op('timestamptz_ops') - ), - index('report_files_organization_id_idx').using( - 'btree', - table.organizationId.asc().nullsLast().op('uuid_ops') - ), - foreignKey({ - columns: [table.createdBy], - foreignColumns: [users.id], - name: 'report_files_created_by_fkey', - }).onUpdate('cascade'), - foreignKey({ - columns: [table.publiclyEnabledBy], - foreignColumns: [users.id], - name: 'report_files_publicly_enabled_by_fkey', - }).onUpdate('cascade'), - foreignKey({ - columns: [table.workspaceSharingEnabledBy], - foreignColumns: [users.id], - name: 'report_files_workspace_sharing_enabled_by_fkey', - }).onUpdate('cascade'), - foreignKey({ - columns: [table.organizationId], - foreignColumns: [organizations.id], - name: 'report_files_organization_id_fkey', - }).onUpdate('cascade'), - ] + "report_files", + { + id: uuid().defaultRandom().primaryKey().notNull(), + name: varchar().notNull(), + content: text("content").notNull(), + organizationId: uuid("organization_id").notNull(), + createdBy: uuid("created_by").notNull(), + createdAt: timestamp("created_at", { withTimezone: true, mode: "string" }) + .default(sql`CURRENT_TIMESTAMP`) + .notNull(), + updatedAt: timestamp("updated_at", { withTimezone: true, mode: "string" }) + .default(sql`CURRENT_TIMESTAMP`) + .notNull(), + deletedAt: timestamp("deleted_at", { withTimezone: true, mode: "string" }), + publiclyAccessible: boolean("publicly_accessible").default(false).notNull(), + publiclyEnabledBy: uuid("publicly_enabled_by"), + publicExpiryDate: timestamp("public_expiry_date", { + withTimezone: true, + mode: "string", + }), + versionHistory: jsonb("version_history") + .$type< + Record< + string, //version number as a string + { + content: ReportElements; + updated_at: string; + version_number: number; + } + > + >() + .default({}) + .notNull(), + publicPassword: text("public_password"), + workspaceSharing: workspaceSharingEnum("workspace_sharing") + .default("none") + .notNull(), + workspaceSharingEnabledBy: uuid("workspace_sharing_enabled_by"), + workspaceSharingEnabledAt: timestamp("workspace_sharing_enabled_at", { + withTimezone: true, + mode: "string", + }), + }, + (table) => [ + index("report_files_created_by_idx").using( + "btree", + table.createdBy.asc().nullsLast().op("uuid_ops"), + ), + index("report_files_deleted_at_idx").using( + "btree", + table.deletedAt.asc().nullsLast().op("timestamptz_ops"), + ), + index("report_files_organization_id_idx").using( + "btree", + table.organizationId.asc().nullsLast().op("uuid_ops"), + ), + foreignKey({ + columns: [table.createdBy], + foreignColumns: [users.id], + name: "report_files_created_by_fkey", + }).onUpdate("cascade"), + foreignKey({ + columns: [table.publiclyEnabledBy], + foreignColumns: [users.id], + name: "report_files_publicly_enabled_by_fkey", + }).onUpdate("cascade"), + foreignKey({ + columns: [table.workspaceSharingEnabledBy], + foreignColumns: [users.id], + name: "report_files_workspace_sharing_enabled_by_fkey", + }).onUpdate("cascade"), + foreignKey({ + columns: [table.organizationId], + foreignColumns: [organizations.id], + name: "report_files_organization_id_fkey", + }).onUpdate("cascade"), + ], ); export const chats = pgTable( - 'chats', - { - id: uuid().defaultRandom().primaryKey().notNull(), - title: text().notNull(), - organizationId: uuid('organization_id').notNull(), - createdAt: timestamp('created_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - updatedAt: timestamp('updated_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - deletedAt: timestamp('deleted_at', { withTimezone: true, mode: 'string' }), - createdBy: uuid('created_by').notNull(), - updatedBy: uuid('updated_by').notNull(), - publiclyAccessible: boolean('publicly_accessible').default(false).notNull(), - publiclyEnabledBy: uuid('publicly_enabled_by'), - publicExpiryDate: timestamp('public_expiry_date', { - withTimezone: true, - mode: 'string', - }), - mostRecentFileId: uuid('most_recent_file_id'), - mostRecentFileType: varchar('most_recent_file_type', { length: 255 }), - mostRecentVersionNumber: integer('most_recent_version_number'), - slackChatAuthorization: slackChatAuthorizationEnum('slack_chat_authorization'), - slackThreadTs: text('slack_thread_ts'), - slackChannelId: text('slack_channel_id'), - workspaceSharing: workspaceSharingEnum('workspace_sharing').default('none').notNull(), - workspaceSharingEnabledBy: uuid('workspace_sharing_enabled_by'), - workspaceSharingEnabledAt: timestamp('workspace_sharing_enabled_at', { - withTimezone: true, - mode: 'string', - }), - }, - (table) => [ - index('chats_created_at_idx').using( - 'btree', - table.createdAt.asc().nullsLast().op('timestamptz_ops') - ), - index('chats_created_by_idx').using('btree', table.createdBy.asc().nullsLast().op('uuid_ops')), - index('chats_organization_id_idx').using( - 'btree', - table.organizationId.asc().nullsLast().op('uuid_ops') - ), - index('idx_chats_most_recent_file_id').using( - 'btree', - table.mostRecentFileId.asc().nullsLast().op('uuid_ops') - ), - index('idx_chats_most_recent_file_type').using( - 'btree', - table.mostRecentFileType.asc().nullsLast().op('text_ops') - ), - foreignKey({ - columns: [table.organizationId], - foreignColumns: [organizations.id], - name: 'chats_organization_id_fkey', - }), - foreignKey({ - columns: [table.createdBy], - foreignColumns: [users.id], - name: 'chats_created_by_fkey', - }).onUpdate('cascade'), - foreignKey({ - columns: [table.updatedBy], - foreignColumns: [users.id], - name: 'chats_updated_by_fkey', - }).onUpdate('cascade'), - foreignKey({ - columns: [table.publiclyEnabledBy], - foreignColumns: [users.id], - name: 'chats_publicly_enabled_by_fkey', - }).onUpdate('cascade'), - foreignKey({ - columns: [table.workspaceSharingEnabledBy], - foreignColumns: [users.id], - name: 'chats_workspace_sharing_enabled_by_fkey', - }).onUpdate('cascade'), - ] + "chats", + { + id: uuid().defaultRandom().primaryKey().notNull(), + title: text().notNull(), + organizationId: uuid("organization_id").notNull(), + createdAt: timestamp("created_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + updatedAt: timestamp("updated_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + deletedAt: timestamp("deleted_at", { withTimezone: true, mode: "string" }), + createdBy: uuid("created_by").notNull(), + updatedBy: uuid("updated_by").notNull(), + publiclyAccessible: boolean("publicly_accessible").default(false).notNull(), + publiclyEnabledBy: uuid("publicly_enabled_by"), + publicExpiryDate: timestamp("public_expiry_date", { + withTimezone: true, + mode: "string", + }), + mostRecentFileId: uuid("most_recent_file_id"), + mostRecentFileType: varchar("most_recent_file_type", { length: 255 }), + mostRecentVersionNumber: integer("most_recent_version_number"), + slackChatAuthorization: slackChatAuthorizationEnum( + "slack_chat_authorization", + ), + slackThreadTs: text("slack_thread_ts"), + slackChannelId: text("slack_channel_id"), + workspaceSharing: workspaceSharingEnum("workspace_sharing") + .default("none") + .notNull(), + workspaceSharingEnabledBy: uuid("workspace_sharing_enabled_by"), + workspaceSharingEnabledAt: timestamp("workspace_sharing_enabled_at", { + withTimezone: true, + mode: "string", + }), + }, + (table) => [ + index("chats_created_at_idx").using( + "btree", + table.createdAt.asc().nullsLast().op("timestamptz_ops"), + ), + index("chats_created_by_idx").using( + "btree", + table.createdBy.asc().nullsLast().op("uuid_ops"), + ), + index("chats_organization_id_idx").using( + "btree", + table.organizationId.asc().nullsLast().op("uuid_ops"), + ), + index("idx_chats_most_recent_file_id").using( + "btree", + table.mostRecentFileId.asc().nullsLast().op("uuid_ops"), + ), + index("idx_chats_most_recent_file_type").using( + "btree", + table.mostRecentFileType.asc().nullsLast().op("text_ops"), + ), + foreignKey({ + columns: [table.organizationId], + foreignColumns: [organizations.id], + name: "chats_organization_id_fkey", + }), + foreignKey({ + columns: [table.createdBy], + foreignColumns: [users.id], + name: "chats_created_by_fkey", + }).onUpdate("cascade"), + foreignKey({ + columns: [table.updatedBy], + foreignColumns: [users.id], + name: "chats_updated_by_fkey", + }).onUpdate("cascade"), + foreignKey({ + columns: [table.publiclyEnabledBy], + foreignColumns: [users.id], + name: "chats_publicly_enabled_by_fkey", + }).onUpdate("cascade"), + foreignKey({ + columns: [table.workspaceSharingEnabledBy], + foreignColumns: [users.id], + name: "chats_workspace_sharing_enabled_by_fkey", + }).onUpdate("cascade"), + ], ); export const organizations = pgTable( - 'organizations', - { - id: uuid().defaultRandom().primaryKey().notNull(), - name: text().notNull(), - domain: text(), - createdAt: timestamp('created_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - updatedAt: timestamp('updated_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - deletedAt: timestamp('deleted_at', { withTimezone: true, mode: 'string' }), - paymentRequired: boolean('payment_required').default(false).notNull(), - domains: text('domains').array(), - restrictNewUserInvitations: boolean('restrict_new_user_invitations').default(false).notNull(), - defaultRole: userOrganizationRoleEnum('default_role').default('restricted_querier').notNull(), - organizationColorPalettes: jsonb('organization_color_palettes') - .$type() - .default( - sql`'{"selectedId": null, "palettes": [], "selectedDictionaryPalette": null}'::jsonb` - ) - .notNull(), - }, - (table) => [unique('organizations_name_key').on(table.name)] + "organizations", + { + id: uuid().defaultRandom().primaryKey().notNull(), + name: text().notNull(), + domain: text(), + createdAt: timestamp("created_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + updatedAt: timestamp("updated_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + deletedAt: timestamp("deleted_at", { withTimezone: true, mode: "string" }), + paymentRequired: boolean("payment_required").default(false).notNull(), + domains: text("domains").array(), + restrictNewUserInvitations: boolean("restrict_new_user_invitations") + .default(false) + .notNull(), + defaultRole: userOrganizationRoleEnum("default_role") + .default("restricted_querier") + .notNull(), + organizationColorPalettes: jsonb("organization_color_palettes") + .$type() + .default( + sql`'{"selectedId": null, "palettes": [], "selectedDictionaryPalette": null}'::jsonb`, + ) + .notNull(), + }, + (table) => [unique("organizations_name_key").on(table.name)], ); export const storedValuesSyncJobs = pgTable( - 'stored_values_sync_jobs', - { - id: uuid().defaultRandom().primaryKey().notNull(), - dataSourceId: uuid('data_source_id').notNull(), - databaseName: text('database_name').notNull(), - schemaName: text('schema_name').notNull(), - tableName: text('table_name').notNull(), - columnName: text('column_name').notNull(), - lastSyncedAt: timestamp('last_synced_at', { - withTimezone: true, - mode: 'string', - }), - createdAt: timestamp('created_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - status: text().notNull(), - errorMessage: text('error_message'), - }, - (table) => [ - index('idx_stored_values_sync_jobs_data_source_id').using( - 'btree', - table.dataSourceId.asc().nullsLast().op('uuid_ops') - ), - index('idx_stored_values_sync_jobs_db_schema_table_column').using( - 'btree', - table.databaseName.asc().nullsLast().op('text_ops'), - table.schemaName.asc().nullsLast().op('text_ops'), - table.tableName.asc().nullsLast().op('text_ops'), - table.columnName.asc().nullsLast().op('text_ops') - ), - index('idx_stored_values_sync_jobs_status').using( - 'btree', - table.status.asc().nullsLast().op('text_ops') - ), - foreignKey({ - columns: [table.dataSourceId], - foreignColumns: [dataSources.id], - name: 'stored_values_sync_jobs_data_source_id_fkey', - }).onDelete('cascade'), - ] + "stored_values_sync_jobs", + { + id: uuid().defaultRandom().primaryKey().notNull(), + dataSourceId: uuid("data_source_id").notNull(), + databaseName: text("database_name").notNull(), + schemaName: text("schema_name").notNull(), + tableName: text("table_name").notNull(), + columnName: text("column_name").notNull(), + lastSyncedAt: timestamp("last_synced_at", { + withTimezone: true, + mode: "string", + }), + createdAt: timestamp("created_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + status: text().notNull(), + errorMessage: text("error_message"), + }, + (table) => [ + index("idx_stored_values_sync_jobs_data_source_id").using( + "btree", + table.dataSourceId.asc().nullsLast().op("uuid_ops"), + ), + index("idx_stored_values_sync_jobs_db_schema_table_column").using( + "btree", + table.databaseName.asc().nullsLast().op("text_ops"), + table.schemaName.asc().nullsLast().op("text_ops"), + table.tableName.asc().nullsLast().op("text_ops"), + table.columnName.asc().nullsLast().op("text_ops"), + ), + index("idx_stored_values_sync_jobs_status").using( + "btree", + table.status.asc().nullsLast().op("text_ops"), + ), + foreignKey({ + columns: [table.dataSourceId], + foreignColumns: [dataSources.id], + name: "stored_values_sync_jobs_data_source_id_fkey", + }).onDelete("cascade"), + ], ); export const metricFiles = pgTable( - 'metric_files', - { - id: uuid().defaultRandom().primaryKey().notNull(), - name: varchar().notNull(), - fileName: varchar('file_name').notNull(), - content: jsonb().notNull(), - verification: verificationEnum().default('notRequested').notNull(), - evaluationObj: jsonb('evaluation_obj'), - evaluationSummary: text('evaluation_summary'), - evaluationScore: doublePrecision('evaluation_score'), - organizationId: uuid('organization_id').notNull(), - createdBy: uuid('created_by').notNull(), - createdAt: timestamp('created_at', { withTimezone: true, mode: 'string' }) - .default(sql`CURRENT_TIMESTAMP`) - .notNull(), - updatedAt: timestamp('updated_at', { withTimezone: true, mode: 'string' }) - .default(sql`CURRENT_TIMESTAMP`) - .notNull(), - deletedAt: timestamp('deleted_at', { withTimezone: true, mode: 'string' }), - publiclyAccessible: boolean('publicly_accessible').default(false).notNull(), - publiclyEnabledBy: uuid('publicly_enabled_by'), - publicExpiryDate: timestamp('public_expiry_date', { - withTimezone: true, - mode: 'string', - }), - versionHistory: jsonb('version_history').default({}).notNull(), - dataMetadata: jsonb('data_metadata'), - publicPassword: text('public_password'), - dataSourceId: uuid('data_source_id').notNull(), - workspaceSharing: workspaceSharingEnum('workspace_sharing').default('none').notNull(), - workspaceSharingEnabledBy: uuid('workspace_sharing_enabled_by'), - workspaceSharingEnabledAt: timestamp('workspace_sharing_enabled_at', { - withTimezone: true, - mode: 'string', - }), - }, - (table) => [ - index('metric_files_created_by_idx').using( - 'btree', - table.createdBy.asc().nullsLast().op('uuid_ops') - ), - index('metric_files_data_metadata_idx').using( - 'gin', - table.dataMetadata.asc().nullsLast().op('jsonb_ops') - ), - index('metric_files_deleted_at_idx').using( - 'btree', - table.deletedAt.asc().nullsLast().op('timestamptz_ops') - ), - index('metric_files_organization_id_idx').using( - 'btree', - table.organizationId.asc().nullsLast().op('uuid_ops') - ), - foreignKey({ - columns: [table.createdBy], - foreignColumns: [users.id], - name: 'metric_files_created_by_fkey', - }).onUpdate('cascade'), - foreignKey({ - columns: [table.publiclyEnabledBy], - foreignColumns: [users.id], - name: 'metric_files_publicly_enabled_by_fkey', - }).onUpdate('cascade'), - foreignKey({ - columns: [table.dataSourceId], - foreignColumns: [dataSources.id], - name: 'fk_data_source', - }), - foreignKey({ - columns: [table.workspaceSharingEnabledBy], - foreignColumns: [users.id], - name: 'metric_files_workspace_sharing_enabled_by_fkey', - }).onUpdate('cascade'), - ] + "metric_files", + { + id: uuid().defaultRandom().primaryKey().notNull(), + name: varchar().notNull(), + fileName: varchar("file_name").notNull(), + content: jsonb().notNull(), + verification: verificationEnum().default("notRequested").notNull(), + evaluationObj: jsonb("evaluation_obj"), + evaluationSummary: text("evaluation_summary"), + evaluationScore: doublePrecision("evaluation_score"), + organizationId: uuid("organization_id").notNull(), + createdBy: uuid("created_by").notNull(), + createdAt: timestamp("created_at", { withTimezone: true, mode: "string" }) + .default(sql`CURRENT_TIMESTAMP`) + .notNull(), + updatedAt: timestamp("updated_at", { withTimezone: true, mode: "string" }) + .default(sql`CURRENT_TIMESTAMP`) + .notNull(), + deletedAt: timestamp("deleted_at", { withTimezone: true, mode: "string" }), + publiclyAccessible: boolean("publicly_accessible").default(false).notNull(), + publiclyEnabledBy: uuid("publicly_enabled_by"), + publicExpiryDate: timestamp("public_expiry_date", { + withTimezone: true, + mode: "string", + }), + versionHistory: jsonb("version_history").default({}).notNull(), + dataMetadata: jsonb("data_metadata"), + publicPassword: text("public_password"), + dataSourceId: uuid("data_source_id").notNull(), + workspaceSharing: workspaceSharingEnum("workspace_sharing") + .default("none") + .notNull(), + workspaceSharingEnabledBy: uuid("workspace_sharing_enabled_by"), + workspaceSharingEnabledAt: timestamp("workspace_sharing_enabled_at", { + withTimezone: true, + mode: "string", + }), + }, + (table) => [ + index("metric_files_created_by_idx").using( + "btree", + table.createdBy.asc().nullsLast().op("uuid_ops"), + ), + index("metric_files_data_metadata_idx").using( + "gin", + table.dataMetadata.asc().nullsLast().op("jsonb_ops"), + ), + index("metric_files_deleted_at_idx").using( + "btree", + table.deletedAt.asc().nullsLast().op("timestamptz_ops"), + ), + index("metric_files_organization_id_idx").using( + "btree", + table.organizationId.asc().nullsLast().op("uuid_ops"), + ), + foreignKey({ + columns: [table.createdBy], + foreignColumns: [users.id], + name: "metric_files_created_by_fkey", + }).onUpdate("cascade"), + foreignKey({ + columns: [table.publiclyEnabledBy], + foreignColumns: [users.id], + name: "metric_files_publicly_enabled_by_fkey", + }).onUpdate("cascade"), + foreignKey({ + columns: [table.dataSourceId], + foreignColumns: [dataSources.id], + name: "fk_data_source", + }), + foreignKey({ + columns: [table.workspaceSharingEnabledBy], + foreignColumns: [users.id], + name: "metric_files_workspace_sharing_enabled_by_fkey", + }).onUpdate("cascade"), + ], ); export const permissionGroupsToUsers = pgTable( - 'permission_groups_to_users', - { - permissionGroupId: uuid('permission_group_id').notNull(), - userId: uuid('user_id').notNull(), - createdAt: timestamp('created_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - }, - (table) => [ - index('permission_groups_to_users_user_id_idx').using( - 'btree', - table.userId.asc().nullsLast().op('uuid_ops') - ), - foreignKey({ - columns: [table.permissionGroupId], - foreignColumns: [permissionGroups.id], - name: 'permission_groups_to_users_permission_group_id_fkey', - }).onDelete('cascade'), - foreignKey({ - columns: [table.userId], - foreignColumns: [users.id], - name: 'permission_groups_to_users_user_id_fkey', - }).onUpdate('cascade'), - primaryKey({ - columns: [table.permissionGroupId, table.userId], - name: 'permission_groups_to_users_pkey', - }), - pgPolicy('permission_groups_to_users_policy', { - as: 'permissive', - for: 'all', - to: ['authenticated'], - using: sql`true`, - }), - ] + "permission_groups_to_users", + { + permissionGroupId: uuid("permission_group_id").notNull(), + userId: uuid("user_id").notNull(), + createdAt: timestamp("created_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + }, + (table) => [ + index("permission_groups_to_users_user_id_idx").using( + "btree", + table.userId.asc().nullsLast().op("uuid_ops"), + ), + foreignKey({ + columns: [table.permissionGroupId], + foreignColumns: [permissionGroups.id], + name: "permission_groups_to_users_permission_group_id_fkey", + }).onDelete("cascade"), + foreignKey({ + columns: [table.userId], + foreignColumns: [users.id], + name: "permission_groups_to_users_user_id_fkey", + }).onUpdate("cascade"), + primaryKey({ + columns: [table.permissionGroupId, table.userId], + name: "permission_groups_to_users_pkey", + }), + pgPolicy("permission_groups_to_users_policy", { + as: "permissive", + for: "all", + to: ["authenticated"], + using: sql`true`, + }), + ], ); export const entityRelationship = pgTable( - 'entity_relationship', - { - primaryDatasetId: uuid('primary_dataset_id').notNull(), - foreignDatasetId: uuid('foreign_dataset_id').notNull(), - relationshipType: text('relationship_type').notNull(), - createdAt: timestamp('created_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - }, - (table) => [ - primaryKey({ - columns: [table.primaryDatasetId, table.foreignDatasetId], - name: 'entity_relationship_pkey', - }), - ] + "entity_relationship", + { + primaryDatasetId: uuid("primary_dataset_id").notNull(), + foreignDatasetId: uuid("foreign_dataset_id").notNull(), + relationshipType: text("relationship_type").notNull(), + createdAt: timestamp("created_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + }, + (table) => [ + primaryKey({ + columns: [table.primaryDatasetId, table.foreignDatasetId], + name: "entity_relationship_pkey", + }), + ], ); export const metricFilesToDatasets = pgTable( - 'metric_files_to_datasets', - { - metricFileId: uuid('metric_file_id').notNull(), - datasetId: uuid('dataset_id').notNull(), - metricVersionNumber: integer('metric_version_number').notNull(), - createdAt: timestamp('created_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - }, - (table) => [ - foreignKey({ - columns: [table.metricFileId], - foreignColumns: [metricFiles.id], - name: 'fk_metric_file', - }).onDelete('cascade'), - foreignKey({ - columns: [table.datasetId], - foreignColumns: [datasets.id], - name: 'fk_dataset', - }).onDelete('cascade'), - primaryKey({ - columns: [table.metricFileId, table.datasetId, table.metricVersionNumber], - name: 'metric_files_to_datasets_pkey', - }), - ] + "metric_files_to_datasets", + { + metricFileId: uuid("metric_file_id").notNull(), + datasetId: uuid("dataset_id").notNull(), + metricVersionNumber: integer("metric_version_number").notNull(), + createdAt: timestamp("created_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + }, + (table) => [ + foreignKey({ + columns: [table.metricFileId], + foreignColumns: [metricFiles.id], + name: "fk_metric_file", + }).onDelete("cascade"), + foreignKey({ + columns: [table.datasetId], + foreignColumns: [datasets.id], + name: "fk_dataset", + }).onDelete("cascade"), + primaryKey({ + columns: [table.metricFileId, table.datasetId, table.metricVersionNumber], + name: "metric_files_to_datasets_pkey", + }), + ], ); export const termsToDatasets = pgTable( - 'terms_to_datasets', - { - termId: uuid('term_id').notNull(), - datasetId: uuid('dataset_id').notNull(), - createdAt: timestamp('created_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - updatedAt: timestamp('updated_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - deletedAt: timestamp('deleted_at', { withTimezone: true, mode: 'string' }), - }, - (table) => [ - foreignKey({ - columns: [table.termId], - foreignColumns: [terms.id], - name: 'terms_to_datasets_term_id_fkey', - }).onDelete('cascade'), - foreignKey({ - columns: [table.datasetId], - foreignColumns: [datasets.id], - name: 'terms_to_datasets_dataset_id_fkey', - }).onDelete('cascade'), - primaryKey({ - columns: [table.termId, table.datasetId], - name: 'terms_to_datasets_pkey', - }), - ] + "terms_to_datasets", + { + termId: uuid("term_id").notNull(), + datasetId: uuid("dataset_id").notNull(), + createdAt: timestamp("created_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + updatedAt: timestamp("updated_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + deletedAt: timestamp("deleted_at", { withTimezone: true, mode: "string" }), + }, + (table) => [ + foreignKey({ + columns: [table.termId], + foreignColumns: [terms.id], + name: "terms_to_datasets_term_id_fkey", + }).onDelete("cascade"), + foreignKey({ + columns: [table.datasetId], + foreignColumns: [datasets.id], + name: "terms_to_datasets_dataset_id_fkey", + }).onDelete("cascade"), + primaryKey({ + columns: [table.termId, table.datasetId], + name: "terms_to_datasets_pkey", + }), + ], ); export const datasetsToPermissionGroups = pgTable( - 'datasets_to_permission_groups', - { - datasetId: uuid('dataset_id').notNull(), - permissionGroupId: uuid('permission_group_id').notNull(), - createdAt: timestamp('created_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - updatedAt: timestamp('updated_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - deletedAt: timestamp('deleted_at', { withTimezone: true, mode: 'string' }), - }, - (table) => [ - foreignKey({ - columns: [table.datasetId], - foreignColumns: [datasets.id], - name: 'datasets_to_permission_groups_dataset_id_fkey', - }).onDelete('cascade'), - foreignKey({ - columns: [table.permissionGroupId], - foreignColumns: [permissionGroups.id], - name: 'datasets_to_permission_groups_permission_group_id_fkey', - }).onDelete('cascade'), - primaryKey({ - columns: [table.datasetId, table.permissionGroupId], - name: 'datasets_to_permission_groups_pkey', - }), - pgPolicy('datasets_to_permission_groups_policy', { - as: 'permissive', - for: 'all', - to: ['authenticated'], - using: sql`true`, - }), - ] + "datasets_to_permission_groups", + { + datasetId: uuid("dataset_id").notNull(), + permissionGroupId: uuid("permission_group_id").notNull(), + createdAt: timestamp("created_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + updatedAt: timestamp("updated_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + deletedAt: timestamp("deleted_at", { withTimezone: true, mode: "string" }), + }, + (table) => [ + foreignKey({ + columns: [table.datasetId], + foreignColumns: [datasets.id], + name: "datasets_to_permission_groups_dataset_id_fkey", + }).onDelete("cascade"), + foreignKey({ + columns: [table.permissionGroupId], + foreignColumns: [permissionGroups.id], + name: "datasets_to_permission_groups_permission_group_id_fkey", + }).onDelete("cascade"), + primaryKey({ + columns: [table.datasetId, table.permissionGroupId], + name: "datasets_to_permission_groups_pkey", + }), + pgPolicy("datasets_to_permission_groups_policy", { + as: "permissive", + for: "all", + to: ["authenticated"], + using: sql`true`, + }), + ], ); export const datasetsToDatasetGroups = pgTable( - 'datasets_to_dataset_groups', - { - datasetId: uuid('dataset_id').notNull(), - datasetGroupId: uuid('dataset_group_id').notNull(), - createdAt: timestamp('created_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - updatedAt: timestamp('updated_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - deletedAt: timestamp('deleted_at', { withTimezone: true, mode: 'string' }), - }, - (table) => [ - index('datasets_to_dataset_groups_dataset_group_id_idx').using( - 'btree', - table.datasetGroupId.asc().nullsLast().op('uuid_ops') - ), - foreignKey({ - columns: [table.datasetId], - foreignColumns: [datasets.id], - name: 'datasets_to_dataset_groups_dataset_id_fkey', - }).onDelete('cascade'), - foreignKey({ - columns: [table.datasetGroupId], - foreignColumns: [datasetGroups.id], - name: 'datasets_to_dataset_groups_dataset_group_id_fkey', - }).onDelete('cascade'), - primaryKey({ - columns: [table.datasetId, table.datasetGroupId], - name: 'datasets_to_dataset_groups_pkey', - }), - pgPolicy('datasets_to_dataset_groups_policy', { - as: 'permissive', - for: 'all', - to: ['authenticated'], - using: sql`true`, - }), - ] + "datasets_to_dataset_groups", + { + datasetId: uuid("dataset_id").notNull(), + datasetGroupId: uuid("dataset_group_id").notNull(), + createdAt: timestamp("created_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + updatedAt: timestamp("updated_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + deletedAt: timestamp("deleted_at", { withTimezone: true, mode: "string" }), + }, + (table) => [ + index("datasets_to_dataset_groups_dataset_group_id_idx").using( + "btree", + table.datasetGroupId.asc().nullsLast().op("uuid_ops"), + ), + foreignKey({ + columns: [table.datasetId], + foreignColumns: [datasets.id], + name: "datasets_to_dataset_groups_dataset_id_fkey", + }).onDelete("cascade"), + foreignKey({ + columns: [table.datasetGroupId], + foreignColumns: [datasetGroups.id], + name: "datasets_to_dataset_groups_dataset_group_id_fkey", + }).onDelete("cascade"), + primaryKey({ + columns: [table.datasetId, table.datasetGroupId], + name: "datasets_to_dataset_groups_pkey", + }), + pgPolicy("datasets_to_dataset_groups_policy", { + as: "permissive", + for: "all", + to: ["authenticated"], + using: sql`true`, + }), + ], ); export const threadsToDashboards = pgTable( - 'threads_to_dashboards', - { - threadId: uuid('thread_id').notNull(), - dashboardId: uuid('dashboard_id').notNull(), - addedBy: uuid('added_by').notNull(), - createdAt: timestamp('created_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - updatedAt: timestamp('updated_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - deletedAt: timestamp('deleted_at', { withTimezone: true, mode: 'string' }), - }, - (table) => [ - foreignKey({ - columns: [table.threadId], - foreignColumns: [threadsDeprecated.id], - name: 'threads_to_dashboards_thread_id_fkey', - }).onDelete('cascade'), - foreignKey({ - columns: [table.dashboardId], - foreignColumns: [dashboards.id], - name: 'threads_to_dashboards_dashboard_id_fkey', - }).onDelete('cascade'), - foreignKey({ - columns: [table.addedBy], - foreignColumns: [users.id], - name: 'threads_to_dashboards_added_by_fkey', - }).onUpdate('cascade'), - primaryKey({ - columns: [table.threadId, table.dashboardId], - name: 'threads_to_dashboards_pkey', - }), - ] + "threads_to_dashboards", + { + threadId: uuid("thread_id").notNull(), + dashboardId: uuid("dashboard_id").notNull(), + addedBy: uuid("added_by").notNull(), + createdAt: timestamp("created_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + updatedAt: timestamp("updated_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + deletedAt: timestamp("deleted_at", { withTimezone: true, mode: "string" }), + }, + (table) => [ + foreignKey({ + columns: [table.threadId], + foreignColumns: [threadsDeprecated.id], + name: "threads_to_dashboards_thread_id_fkey", + }).onDelete("cascade"), + foreignKey({ + columns: [table.dashboardId], + foreignColumns: [dashboards.id], + name: "threads_to_dashboards_dashboard_id_fkey", + }).onDelete("cascade"), + foreignKey({ + columns: [table.addedBy], + foreignColumns: [users.id], + name: "threads_to_dashboards_added_by_fkey", + }).onUpdate("cascade"), + primaryKey({ + columns: [table.threadId, table.dashboardId], + name: "threads_to_dashboards_pkey", + }), + ], ); export const userFavorites = pgTable( - 'user_favorites', - { - userId: uuid('user_id').notNull(), - assetId: uuid('asset_id').notNull(), - assetType: assetTypeEnum('asset_type').notNull(), - orderIndex: integer('order_index').notNull(), - createdAt: timestamp('created_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - deletedAt: timestamp('deleted_at', { withTimezone: true, mode: 'string' }), - }, - (table) => [ - foreignKey({ - columns: [table.userId], - foreignColumns: [users.id], - name: 'user_favorites_user_id_fkey', - }).onUpdate('cascade'), - primaryKey({ - columns: [table.userId, table.assetId, table.assetType], - name: 'user_favorites_pkey', - }), - ] + "user_favorites", + { + userId: uuid("user_id").notNull(), + assetId: uuid("asset_id").notNull(), + assetType: assetTypeEnum("asset_type").notNull(), + orderIndex: integer("order_index").notNull(), + createdAt: timestamp("created_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + deletedAt: timestamp("deleted_at", { withTimezone: true, mode: "string" }), + }, + (table) => [ + foreignKey({ + columns: [table.userId], + foreignColumns: [users.id], + name: "user_favorites_user_id_fkey", + }).onUpdate("cascade"), + primaryKey({ + columns: [table.userId, table.assetId, table.assetType], + name: "user_favorites_pkey", + }), + ], ); export const teamsToUsers = pgTable( - 'teams_to_users', - { - teamId: uuid('team_id').notNull(), - userId: uuid('user_id').notNull(), - role: teamRoleEnum().default('member').notNull(), - createdAt: timestamp('created_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - updatedAt: timestamp('updated_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - deletedAt: timestamp('deleted_at', { withTimezone: true, mode: 'string' }), - }, - (table) => [ - foreignKey({ - columns: [table.teamId], - foreignColumns: [teams.id], - name: 'teams_to_users_team_id_fkey', - }).onDelete('cascade'), - foreignKey({ - columns: [table.userId], - foreignColumns: [users.id], - name: 'teams_to_users_user_id_fkey', - }).onUpdate('cascade'), - primaryKey({ - columns: [table.teamId, table.userId], - name: 'teams_to_users_pkey', - }), - ] + "teams_to_users", + { + teamId: uuid("team_id").notNull(), + userId: uuid("user_id").notNull(), + role: teamRoleEnum().default("member").notNull(), + createdAt: timestamp("created_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + updatedAt: timestamp("updated_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + deletedAt: timestamp("deleted_at", { withTimezone: true, mode: "string" }), + }, + (table) => [ + foreignKey({ + columns: [table.teamId], + foreignColumns: [teams.id], + name: "teams_to_users_team_id_fkey", + }).onDelete("cascade"), + foreignKey({ + columns: [table.userId], + foreignColumns: [users.id], + name: "teams_to_users_user_id_fkey", + }).onUpdate("cascade"), + primaryKey({ + columns: [table.teamId, table.userId], + name: "teams_to_users_pkey", + }), + ], ); export const metricFilesToDashboardFiles = pgTable( - 'metric_files_to_dashboard_files', - { - metricFileId: uuid('metric_file_id').notNull(), - dashboardFileId: uuid('dashboard_file_id').notNull(), - createdAt: timestamp('created_at', { withTimezone: true, mode: 'string' }) - .default(sql`CURRENT_TIMESTAMP`) - .notNull(), - updatedAt: timestamp('updated_at', { withTimezone: true, mode: 'string' }) - .default(sql`CURRENT_TIMESTAMP`) - .notNull(), - deletedAt: timestamp('deleted_at', { withTimezone: true, mode: 'string' }), - createdBy: uuid('created_by').notNull(), - }, - (table) => [ - index('metric_files_to_dashboard_files_dashboard_id_idx').using( - 'btree', - table.dashboardFileId.asc().nullsLast().op('uuid_ops') - ), - index('metric_files_to_dashboard_files_deleted_at_idx').using( - 'btree', - table.deletedAt.asc().nullsLast().op('timestamptz_ops') - ), - index('metric_files_to_dashboard_files_metric_id_idx').using( - 'btree', - table.metricFileId.asc().nullsLast().op('uuid_ops') - ), - foreignKey({ - columns: [table.metricFileId], - foreignColumns: [metricFiles.id], - name: 'metric_files_to_dashboard_files_metric_file_id_fkey', - }), - foreignKey({ - columns: [table.dashboardFileId], - foreignColumns: [dashboardFiles.id], - name: 'metric_files_to_dashboard_files_dashboard_file_id_fkey', - }), - foreignKey({ - columns: [table.createdBy], - foreignColumns: [users.id], - name: 'metric_files_to_dashboard_files_created_by_fkey', - }).onUpdate('cascade'), - primaryKey({ - columns: [table.metricFileId, table.dashboardFileId], - name: 'metric_files_to_dashboard_files_pkey', - }), - ] + "metric_files_to_dashboard_files", + { + metricFileId: uuid("metric_file_id").notNull(), + dashboardFileId: uuid("dashboard_file_id").notNull(), + createdAt: timestamp("created_at", { withTimezone: true, mode: "string" }) + .default(sql`CURRENT_TIMESTAMP`) + .notNull(), + updatedAt: timestamp("updated_at", { withTimezone: true, mode: "string" }) + .default(sql`CURRENT_TIMESTAMP`) + .notNull(), + deletedAt: timestamp("deleted_at", { withTimezone: true, mode: "string" }), + createdBy: uuid("created_by").notNull(), + }, + (table) => [ + index("metric_files_to_dashboard_files_dashboard_id_idx").using( + "btree", + table.dashboardFileId.asc().nullsLast().op("uuid_ops"), + ), + index("metric_files_to_dashboard_files_deleted_at_idx").using( + "btree", + table.deletedAt.asc().nullsLast().op("timestamptz_ops"), + ), + index("metric_files_to_dashboard_files_metric_id_idx").using( + "btree", + table.metricFileId.asc().nullsLast().op("uuid_ops"), + ), + foreignKey({ + columns: [table.metricFileId], + foreignColumns: [metricFiles.id], + name: "metric_files_to_dashboard_files_metric_file_id_fkey", + }), + foreignKey({ + columns: [table.dashboardFileId], + foreignColumns: [dashboardFiles.id], + name: "metric_files_to_dashboard_files_dashboard_file_id_fkey", + }), + foreignKey({ + columns: [table.createdBy], + foreignColumns: [users.id], + name: "metric_files_to_dashboard_files_created_by_fkey", + }).onUpdate("cascade"), + primaryKey({ + columns: [table.metricFileId, table.dashboardFileId], + name: "metric_files_to_dashboard_files_pkey", + }), + ], ); export const collectionsToAssets = pgTable( - 'collections_to_assets', - { - collectionId: uuid('collection_id').notNull(), - assetId: uuid('asset_id').notNull(), - assetType: assetTypeEnum('asset_type').notNull(), - createdAt: timestamp('created_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - updatedAt: timestamp('updated_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - deletedAt: timestamp('deleted_at', { withTimezone: true, mode: 'string' }), - createdBy: uuid('created_by').notNull(), - updatedBy: uuid('updated_by').notNull(), - }, - (table) => [ - foreignKey({ - columns: [table.createdBy], - foreignColumns: [users.id], - name: 'collections_to_assets_created_by_fkey', - }).onUpdate('cascade'), - foreignKey({ - columns: [table.updatedBy], - foreignColumns: [users.id], - name: 'collections_to_assets_updated_by_fkey', - }).onUpdate('cascade'), - primaryKey({ - columns: [table.collectionId, table.assetId, table.assetType], - name: 'collections_to_assets_pkey', - }), - ] + "collections_to_assets", + { + collectionId: uuid("collection_id").notNull(), + assetId: uuid("asset_id").notNull(), + assetType: assetTypeEnum("asset_type").notNull(), + createdAt: timestamp("created_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + updatedAt: timestamp("updated_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + deletedAt: timestamp("deleted_at", { withTimezone: true, mode: "string" }), + createdBy: uuid("created_by").notNull(), + updatedBy: uuid("updated_by").notNull(), + }, + (table) => [ + foreignKey({ + columns: [table.createdBy], + foreignColumns: [users.id], + name: "collections_to_assets_created_by_fkey", + }).onUpdate("cascade"), + foreignKey({ + columns: [table.updatedBy], + foreignColumns: [users.id], + name: "collections_to_assets_updated_by_fkey", + }).onUpdate("cascade"), + primaryKey({ + columns: [table.collectionId, table.assetId, table.assetType], + name: "collections_to_assets_pkey", + }), + ], ); export const permissionGroupsToIdentities = pgTable( - 'permission_groups_to_identities', - { - permissionGroupId: uuid('permission_group_id').notNull(), - identityId: uuid('identity_id').notNull(), - identityType: identityTypeEnum('identity_type').notNull(), - createdAt: timestamp('created_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - updatedAt: timestamp('updated_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - deletedAt: timestamp('deleted_at', { withTimezone: true, mode: 'string' }), - createdBy: uuid('created_by').notNull(), - updatedBy: uuid('updated_by').notNull(), - }, - (table) => [ - foreignKey({ - columns: [table.createdBy], - foreignColumns: [users.id], - name: 'permission_groups_to_identities_created_by_fkey', - }).onUpdate('cascade'), - foreignKey({ - columns: [table.updatedBy], - foreignColumns: [users.id], - name: 'permission_groups_to_identities_updated_by_fkey', - }).onUpdate('cascade'), - primaryKey({ - columns: [table.permissionGroupId, table.identityId, table.identityType], - name: 'permission_groups_to_identities_pkey', - }), - ] + "permission_groups_to_identities", + { + permissionGroupId: uuid("permission_group_id").notNull(), + identityId: uuid("identity_id").notNull(), + identityType: identityTypeEnum("identity_type").notNull(), + createdAt: timestamp("created_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + updatedAt: timestamp("updated_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + deletedAt: timestamp("deleted_at", { withTimezone: true, mode: "string" }), + createdBy: uuid("created_by").notNull(), + updatedBy: uuid("updated_by").notNull(), + }, + (table) => [ + foreignKey({ + columns: [table.createdBy], + foreignColumns: [users.id], + name: "permission_groups_to_identities_created_by_fkey", + }).onUpdate("cascade"), + foreignKey({ + columns: [table.updatedBy], + foreignColumns: [users.id], + name: "permission_groups_to_identities_updated_by_fkey", + }).onUpdate("cascade"), + primaryKey({ + columns: [table.permissionGroupId, table.identityId, table.identityType], + name: "permission_groups_to_identities_pkey", + }), + ], ); export const assetPermissions = pgTable( - 'asset_permissions', - { - identityId: uuid('identity_id').notNull(), - identityType: identityTypeEnum('identity_type').notNull(), - assetId: uuid('asset_id').notNull(), - assetType: assetTypeEnum('asset_type').notNull(), - role: assetPermissionRoleEnum().notNull(), - createdAt: timestamp('created_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - updatedAt: timestamp('updated_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - deletedAt: timestamp('deleted_at', { withTimezone: true, mode: 'string' }), - createdBy: uuid('created_by').notNull(), - updatedBy: uuid('updated_by').notNull(), - }, - (table) => [ - foreignKey({ - columns: [table.createdBy], - foreignColumns: [users.id], - name: 'asset_permissions_created_by_fkey', - }).onUpdate('cascade'), - foreignKey({ - columns: [table.updatedBy], - foreignColumns: [users.id], - name: 'asset_permissions_updated_by_fkey', - }).onUpdate('cascade'), - primaryKey({ - columns: [table.identityId, table.identityType, table.assetId, table.assetType], - name: 'asset_permissions_pkey', - }), - ] + "asset_permissions", + { + identityId: uuid("identity_id").notNull(), + identityType: identityTypeEnum("identity_type").notNull(), + assetId: uuid("asset_id").notNull(), + assetType: assetTypeEnum("asset_type").notNull(), + role: assetPermissionRoleEnum().notNull(), + createdAt: timestamp("created_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + updatedAt: timestamp("updated_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + deletedAt: timestamp("deleted_at", { withTimezone: true, mode: "string" }), + createdBy: uuid("created_by").notNull(), + updatedBy: uuid("updated_by").notNull(), + }, + (table) => [ + foreignKey({ + columns: [table.createdBy], + foreignColumns: [users.id], + name: "asset_permissions_created_by_fkey", + }).onUpdate("cascade"), + foreignKey({ + columns: [table.updatedBy], + foreignColumns: [users.id], + name: "asset_permissions_updated_by_fkey", + }).onUpdate("cascade"), + primaryKey({ + columns: [ + table.identityId, + table.identityType, + table.assetId, + table.assetType, + ], + name: "asset_permissions_pkey", + }), + ], ); export const usersToOrganizations = pgTable( - 'users_to_organizations', - { - userId: uuid('user_id').notNull(), - organizationId: uuid('organization_id').notNull(), - role: userOrganizationRoleEnum().default('querier').notNull(), - sharingSetting: sharingSettingEnum('sharing_setting').default('none').notNull(), - editSql: boolean('edit_sql').default(false).notNull(), - uploadCsv: boolean('upload_csv').default(false).notNull(), - exportAssets: boolean('export_assets').default(false).notNull(), - emailSlackEnabled: boolean('email_slack_enabled').default(false).notNull(), - createdAt: timestamp('created_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - updatedAt: timestamp('updated_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - deletedAt: timestamp('deleted_at', { withTimezone: true, mode: 'string' }), - createdBy: uuid('created_by').notNull(), - updatedBy: uuid('updated_by').notNull(), - deletedBy: uuid('deleted_by'), - status: userOrganizationStatusEnum().default('active').notNull(), - }, - (table) => [ - foreignKey({ - columns: [table.organizationId], - foreignColumns: [organizations.id], - name: 'users_to_organizations_organization_id_fkey', - }).onDelete('cascade'), - foreignKey({ - columns: [table.userId], - foreignColumns: [users.id], - name: 'users_to_organizations_user_id_fkey', - }).onUpdate('cascade'), - foreignKey({ - columns: [table.createdBy], - foreignColumns: [users.id], - name: 'users_to_organizations_created_by_fkey', - }).onUpdate('cascade'), - foreignKey({ - columns: [table.updatedBy], - foreignColumns: [users.id], - name: 'users_to_organizations_updated_by_fkey', - }).onUpdate('cascade'), - foreignKey({ - columns: [table.deletedBy], - foreignColumns: [users.id], - name: 'users_to_organizations_deleted_by_fkey', - }).onUpdate('cascade'), - primaryKey({ - columns: [table.userId, table.organizationId], - name: 'users_to_organizations_pkey', - }), - ] + "users_to_organizations", + { + userId: uuid("user_id").notNull(), + organizationId: uuid("organization_id").notNull(), + role: userOrganizationRoleEnum().default("querier").notNull(), + sharingSetting: sharingSettingEnum("sharing_setting") + .default("none") + .notNull(), + editSql: boolean("edit_sql").default(false).notNull(), + uploadCsv: boolean("upload_csv").default(false).notNull(), + exportAssets: boolean("export_assets").default(false).notNull(), + emailSlackEnabled: boolean("email_slack_enabled").default(false).notNull(), + createdAt: timestamp("created_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + updatedAt: timestamp("updated_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + deletedAt: timestamp("deleted_at", { withTimezone: true, mode: "string" }), + createdBy: uuid("created_by").notNull(), + updatedBy: uuid("updated_by").notNull(), + deletedBy: uuid("deleted_by"), + status: userOrganizationStatusEnum().default("active").notNull(), + }, + (table) => [ + foreignKey({ + columns: [table.organizationId], + foreignColumns: [organizations.id], + name: "users_to_organizations_organization_id_fkey", + }).onDelete("cascade"), + foreignKey({ + columns: [table.userId], + foreignColumns: [users.id], + name: "users_to_organizations_user_id_fkey", + }).onUpdate("cascade"), + foreignKey({ + columns: [table.createdBy], + foreignColumns: [users.id], + name: "users_to_organizations_created_by_fkey", + }).onUpdate("cascade"), + foreignKey({ + columns: [table.updatedBy], + foreignColumns: [users.id], + name: "users_to_organizations_updated_by_fkey", + }).onUpdate("cascade"), + foreignKey({ + columns: [table.deletedBy], + foreignColumns: [users.id], + name: "users_to_organizations_deleted_by_fkey", + }).onUpdate("cascade"), + primaryKey({ + columns: [table.userId, table.organizationId], + name: "users_to_organizations_pkey", + }), + ], ); export const databaseMetadata = pgTable( - 'database_metadata', - { - id: uuid().defaultRandom().primaryKey().notNull(), - dataSourceId: uuid('data_source_id').notNull(), - name: text().notNull(), - owner: text(), - comment: text(), - created: timestamp({ withTimezone: true, mode: 'string' }), - lastModified: timestamp('last_modified', { - withTimezone: true, - mode: 'string', - }), - metadata: jsonb().default({}).notNull(), - createdAt: timestamp('created_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - updatedAt: timestamp('updated_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - deletedAt: timestamp('deleted_at', { withTimezone: true, mode: 'string' }), - }, - (table) => [ - foreignKey({ - columns: [table.dataSourceId], - foreignColumns: [dataSources.id], - name: 'database_metadata_data_source_id_fkey', - }).onDelete('cascade'), - unique('database_metadata_data_source_id_name_key').on(table.dataSourceId, table.name), - index('database_metadata_data_source_id_idx').using( - 'btree', - table.dataSourceId.asc().nullsLast().op('uuid_ops') - ), - ] + "database_metadata", + { + id: uuid().defaultRandom().primaryKey().notNull(), + dataSourceId: uuid("data_source_id").notNull(), + name: text().notNull(), + owner: text(), + comment: text(), + created: timestamp({ withTimezone: true, mode: "string" }), + lastModified: timestamp("last_modified", { + withTimezone: true, + mode: "string", + }), + metadata: jsonb().default({}).notNull(), + createdAt: timestamp("created_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + updatedAt: timestamp("updated_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + deletedAt: timestamp("deleted_at", { withTimezone: true, mode: "string" }), + }, + (table) => [ + foreignKey({ + columns: [table.dataSourceId], + foreignColumns: [dataSources.id], + name: "database_metadata_data_source_id_fkey", + }).onDelete("cascade"), + unique("database_metadata_data_source_id_name_key").on( + table.dataSourceId, + table.name, + ), + index("database_metadata_data_source_id_idx").using( + "btree", + table.dataSourceId.asc().nullsLast().op("uuid_ops"), + ), + ], ); export const schemaMetadata = pgTable( - 'schema_metadata', - { - id: uuid().defaultRandom().primaryKey().notNull(), - dataSourceId: uuid('data_source_id').notNull(), - databaseId: uuid('database_id'), // Optional for MySQL - name: text().notNull(), - databaseName: text('database_name').notNull(), - owner: text(), - comment: text(), - created: timestamp({ withTimezone: true, mode: 'string' }), - lastModified: timestamp('last_modified', { - withTimezone: true, - mode: 'string', - }), - metadata: jsonb().default({}).notNull(), - createdAt: timestamp('created_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - updatedAt: timestamp('updated_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - deletedAt: timestamp('deleted_at', { withTimezone: true, mode: 'string' }), - }, - (table) => [ - foreignKey({ - columns: [table.dataSourceId], - foreignColumns: [dataSources.id], - name: 'schema_metadata_data_source_id_fkey', - }).onDelete('cascade'), - foreignKey({ - columns: [table.databaseId], - foreignColumns: [databaseMetadata.id], - name: 'schema_metadata_database_id_fkey', - }).onDelete('cascade'), - unique('schema_metadata_data_source_id_database_id_name_key').on( - table.dataSourceId, - table.databaseId, - table.name - ), - index('schema_metadata_data_source_id_idx').using( - 'btree', - table.dataSourceId.asc().nullsLast().op('uuid_ops') - ), - index('schema_metadata_database_id_idx').using( - 'btree', - table.databaseId.asc().nullsLast().op('uuid_ops') - ), - ] + "schema_metadata", + { + id: uuid().defaultRandom().primaryKey().notNull(), + dataSourceId: uuid("data_source_id").notNull(), + databaseId: uuid("database_id"), // Optional for MySQL + name: text().notNull(), + databaseName: text("database_name").notNull(), + owner: text(), + comment: text(), + created: timestamp({ withTimezone: true, mode: "string" }), + lastModified: timestamp("last_modified", { + withTimezone: true, + mode: "string", + }), + metadata: jsonb().default({}).notNull(), + createdAt: timestamp("created_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + updatedAt: timestamp("updated_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + deletedAt: timestamp("deleted_at", { withTimezone: true, mode: "string" }), + }, + (table) => [ + foreignKey({ + columns: [table.dataSourceId], + foreignColumns: [dataSources.id], + name: "schema_metadata_data_source_id_fkey", + }).onDelete("cascade"), + foreignKey({ + columns: [table.databaseId], + foreignColumns: [databaseMetadata.id], + name: "schema_metadata_database_id_fkey", + }).onDelete("cascade"), + unique("schema_metadata_data_source_id_database_id_name_key").on( + table.dataSourceId, + table.databaseId, + table.name, + ), + index("schema_metadata_data_source_id_idx").using( + "btree", + table.dataSourceId.asc().nullsLast().op("uuid_ops"), + ), + index("schema_metadata_database_id_idx").using( + "btree", + table.databaseId.asc().nullsLast().op("uuid_ops"), + ), + ], ); export const tableMetadata = pgTable( - 'table_metadata', - { - id: uuid().defaultRandom().primaryKey().notNull(), - dataSourceId: uuid('data_source_id').notNull(), - databaseId: uuid('database_id'), // Optional for some databases - schemaId: uuid('schema_id').notNull(), - name: text().notNull(), - schemaName: text('schema_name').notNull(), - databaseName: text('database_name').notNull(), - type: tableTypeEnum().notNull(), - rowCount: bigint('row_count', { mode: 'number' }), - sizeBytes: bigint('size_bytes', { mode: 'number' }), - comment: text(), - created: timestamp({ withTimezone: true, mode: 'string' }), - lastModified: timestamp('last_modified', { - withTimezone: true, - mode: 'string', - }), - clusteringKeys: jsonb('clustering_keys').default([]).notNull(), - columns: jsonb().default([]).notNull(), // Array of Column objects - metadata: jsonb().default({}).notNull(), - createdAt: timestamp('created_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - updatedAt: timestamp('updated_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - deletedAt: timestamp('deleted_at', { withTimezone: true, mode: 'string' }), - }, - (table) => [ - foreignKey({ - columns: [table.dataSourceId], - foreignColumns: [dataSources.id], - name: 'table_metadata_data_source_id_fkey', - }).onDelete('cascade'), - foreignKey({ - columns: [table.databaseId], - foreignColumns: [databaseMetadata.id], - name: 'table_metadata_database_id_fkey', - }).onDelete('cascade'), - foreignKey({ - columns: [table.schemaId], - foreignColumns: [schemaMetadata.id], - name: 'table_metadata_schema_id_fkey', - }).onDelete('cascade'), - unique('table_metadata_data_source_id_schema_id_name_key').on( - table.dataSourceId, - table.schemaId, - table.name - ), - index('table_metadata_data_source_id_idx').using( - 'btree', - table.dataSourceId.asc().nullsLast().op('uuid_ops') - ), - index('table_metadata_database_id_idx').using( - 'btree', - table.databaseId.asc().nullsLast().op('uuid_ops') - ), - index('table_metadata_schema_id_idx').using( - 'btree', - table.schemaId.asc().nullsLast().op('uuid_ops') - ), - ] + "table_metadata", + { + id: uuid().defaultRandom().primaryKey().notNull(), + dataSourceId: uuid("data_source_id").notNull(), + databaseId: uuid("database_id"), // Optional for some databases + schemaId: uuid("schema_id").notNull(), + name: text().notNull(), + schemaName: text("schema_name").notNull(), + databaseName: text("database_name").notNull(), + type: tableTypeEnum().notNull(), + rowCount: bigint("row_count", { mode: "number" }), + sizeBytes: bigint("size_bytes", { mode: "number" }), + comment: text(), + created: timestamp({ withTimezone: true, mode: "string" }), + lastModified: timestamp("last_modified", { + withTimezone: true, + mode: "string", + }), + clusteringKeys: jsonb("clustering_keys").default([]).notNull(), + columns: jsonb().default([]).notNull(), // Array of Column objects + metadata: jsonb().default({}).notNull(), + createdAt: timestamp("created_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + updatedAt: timestamp("updated_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + deletedAt: timestamp("deleted_at", { withTimezone: true, mode: "string" }), + }, + (table) => [ + foreignKey({ + columns: [table.dataSourceId], + foreignColumns: [dataSources.id], + name: "table_metadata_data_source_id_fkey", + }).onDelete("cascade"), + foreignKey({ + columns: [table.databaseId], + foreignColumns: [databaseMetadata.id], + name: "table_metadata_database_id_fkey", + }).onDelete("cascade"), + foreignKey({ + columns: [table.schemaId], + foreignColumns: [schemaMetadata.id], + name: "table_metadata_schema_id_fkey", + }).onDelete("cascade"), + unique("table_metadata_data_source_id_schema_id_name_key").on( + table.dataSourceId, + table.schemaId, + table.name, + ), + index("table_metadata_data_source_id_idx").using( + "btree", + table.dataSourceId.asc().nullsLast().op("uuid_ops"), + ), + index("table_metadata_database_id_idx").using( + "btree", + table.databaseId.asc().nullsLast().op("uuid_ops"), + ), + index("table_metadata_schema_id_idx").using( + "btree", + table.schemaId.asc().nullsLast().op("uuid_ops"), + ), + ], ); // Slack integrations table export const slackIntegrations = pgTable( - 'slack_integrations', - { - id: uuid().defaultRandom().primaryKey().notNull(), - organizationId: uuid('organization_id').notNull(), - userId: uuid('user_id').notNull(), + "slack_integrations", + { + id: uuid().defaultRandom().primaryKey().notNull(), + organizationId: uuid("organization_id").notNull(), + userId: uuid("user_id").notNull(), - // OAuth state fields (for pending integrations) - oauthState: varchar('oauth_state', { length: 255 }).unique(), - oauthExpiresAt: timestamp('oauth_expires_at', { withTimezone: true, mode: 'string' }), - oauthMetadata: jsonb('oauth_metadata').default({}), + // OAuth state fields (for pending integrations) + oauthState: varchar("oauth_state", { length: 255 }).unique(), + oauthExpiresAt: timestamp("oauth_expires_at", { + withTimezone: true, + mode: "string", + }), + oauthMetadata: jsonb("oauth_metadata").default({}), - // Slack workspace info (populated after successful OAuth) - teamId: varchar('team_id', { length: 255 }), - teamName: varchar('team_name', { length: 255 }), - teamDomain: varchar('team_domain', { length: 255 }), - enterpriseId: varchar('enterprise_id', { length: 255 }), + // Slack workspace info (populated after successful OAuth) + teamId: varchar("team_id", { length: 255 }), + teamName: varchar("team_name", { length: 255 }), + teamDomain: varchar("team_domain", { length: 255 }), + enterpriseId: varchar("enterprise_id", { length: 255 }), - // Bot info - botUserId: varchar('bot_user_id', { length: 255 }), - scope: text(), + // Bot info + botUserId: varchar("bot_user_id", { length: 255 }), + scope: text(), - // Token reference (actual token in Supabase Vault) - tokenVaultKey: varchar('token_vault_key', { length: 255 }).unique(), + // Token reference (actual token in Supabase Vault) + tokenVaultKey: varchar("token_vault_key", { length: 255 }).unique(), - // Metadata - installedBySlackUserId: varchar('installed_by_slack_user_id', { length: 255 }), - installedAt: timestamp('installed_at', { withTimezone: true, mode: 'string' }), - lastUsedAt: timestamp('last_used_at', { withTimezone: true, mode: 'string' }), - status: slackIntegrationStatusEnum().default('pending').notNull(), + // Metadata + installedBySlackUserId: varchar("installed_by_slack_user_id", { + length: 255, + }), + installedAt: timestamp("installed_at", { + withTimezone: true, + mode: "string", + }), + lastUsedAt: timestamp("last_used_at", { + withTimezone: true, + mode: "string", + }), + status: slackIntegrationStatusEnum().default("pending").notNull(), - // Default channel configuration - defaultChannel: jsonb('default_channel') - .$type<{ id: string; name: string } | Record>() - .default({}), + // Default channel configuration + defaultChannel: jsonb("default_channel") + .$type<{ id: string; name: string } | Record>() + .default({}), - // Timestamps - createdAt: timestamp('created_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - updatedAt: timestamp('updated_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - deletedAt: timestamp('deleted_at', { withTimezone: true, mode: 'string' }), + // Timestamps + createdAt: timestamp("created_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + updatedAt: timestamp("updated_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + deletedAt: timestamp("deleted_at", { withTimezone: true, mode: "string" }), - // Default Sharing Permissions in Slack - defaultSharingPermissions: slackSharingPermissionEnum('default_sharing_permissions') - .default('shareWithChannel') - .notNull(), - }, - (table) => [ - foreignKey({ - columns: [table.organizationId], - foreignColumns: [organizations.id], - name: 'slack_integrations_organization_id_fkey', - }).onDelete('cascade'), - foreignKey({ - columns: [table.userId], - foreignColumns: [users.id], - name: 'slack_integrations_user_id_fkey', - }), - unique('slack_integrations_org_team_key').on(table.organizationId, table.teamId), - index('idx_slack_integrations_org_id').using( - 'btree', - table.organizationId.asc().nullsLast().op('uuid_ops') - ), - index('idx_slack_integrations_team_id').using( - 'btree', - table.teamId.asc().nullsLast().op('text_ops') - ), - index('idx_slack_integrations_oauth_state').using( - 'btree', - table.oauthState.asc().nullsLast().op('text_ops') - ), - index('idx_slack_integrations_oauth_expires').using( - 'btree', - table.oauthExpiresAt.asc().nullsLast().op('timestamptz_ops') - ), - check( - 'slack_integrations_status_check', - sql`(status = 'pending' AND oauth_state IS NOT NULL) OR (status != 'pending' AND team_id IS NOT NULL)` - ), - ] + // Default Sharing Permissions in Slack + defaultSharingPermissions: slackSharingPermissionEnum( + "default_sharing_permissions", + ) + .default("shareWithChannel") + .notNull(), + }, + (table) => [ + foreignKey({ + columns: [table.organizationId], + foreignColumns: [organizations.id], + name: "slack_integrations_organization_id_fkey", + }).onDelete("cascade"), + foreignKey({ + columns: [table.userId], + foreignColumns: [users.id], + name: "slack_integrations_user_id_fkey", + }), + unique("slack_integrations_org_team_key").on( + table.organizationId, + table.teamId, + ), + index("idx_slack_integrations_org_id").using( + "btree", + table.organizationId.asc().nullsLast().op("uuid_ops"), + ), + index("idx_slack_integrations_team_id").using( + "btree", + table.teamId.asc().nullsLast().op("text_ops"), + ), + index("idx_slack_integrations_oauth_state").using( + "btree", + table.oauthState.asc().nullsLast().op("text_ops"), + ), + index("idx_slack_integrations_oauth_expires").using( + "btree", + table.oauthExpiresAt.asc().nullsLast().op("timestamptz_ops"), + ), + check( + "slack_integrations_status_check", + sql`(status = 'pending' AND oauth_state IS NOT NULL) OR (status != 'pending' AND team_id IS NOT NULL)`, + ), + ], ); // GitHub integrations table export const githubIntegrations = pgTable( - 'github_integrations', - { - id: uuid().defaultRandom().primaryKey().notNull(), - organizationId: uuid('organization_id').notNull(), - userId: uuid('user_id').notNull(), + "github_integrations", + { + id: uuid().defaultRandom().primaryKey().notNull(), + organizationId: uuid("organization_id").notNull(), + userId: uuid("user_id").notNull(), - installationId: varchar('installation_id', { length: 255 }).notNull(), - appId: varchar('app_id', { length: 255 }), + installationId: varchar("installation_id", { length: 255 }).notNull(), + appId: varchar("app_id", { length: 255 }), - githubOrgId: varchar('github_org_id', { length: 255 }).notNull(), - githubOrgName: varchar('github_org_name', { length: 255 }), + githubOrgId: varchar("github_org_id", { length: 255 }).notNull(), + githubOrgName: varchar("github_org_name", { length: 255 }), - tokenVaultKey: varchar('token_vault_key', { length: 255 }).unique(), - webhookSecretVaultKey: varchar('webhook_secret_vault_key', { length: 255 }), + tokenVaultKey: varchar("token_vault_key", { length: 255 }).unique(), + webhookSecretVaultKey: varchar("webhook_secret_vault_key", { length: 255 }), - repositoryPermissions: jsonb('repository_permissions').default({}), + repositoryPermissions: jsonb("repository_permissions").default({}), - status: githubIntegrationStatusEnum().default('pending').notNull(), - installedAt: timestamp('installed_at', { withTimezone: true, mode: 'string' }), - lastUsedAt: timestamp('last_used_at', { withTimezone: true, mode: 'string' }), + status: githubIntegrationStatusEnum().default("pending").notNull(), + installedAt: timestamp("installed_at", { + withTimezone: true, + mode: "string", + }), + lastUsedAt: timestamp("last_used_at", { + withTimezone: true, + mode: "string", + }), - // Timestamps - createdAt: timestamp('created_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - updatedAt: timestamp('updated_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - deletedAt: timestamp('deleted_at', { withTimezone: true, mode: 'string' }), - }, - (table) => [ - foreignKey({ - columns: [table.organizationId], - foreignColumns: [organizations.id], - name: 'github_integrations_organization_id_fkey', - }).onDelete('cascade'), - foreignKey({ - columns: [table.userId], - foreignColumns: [users.id], - name: 'github_integrations_user_id_fkey', - }).onDelete('set null'), - unique('github_integrations_org_installation_key').on( - table.organizationId, - table.installationId - ), - index('idx_github_integrations_org_id').using( - 'btree', - table.organizationId.asc().nullsLast().op('uuid_ops') - ), - index('idx_github_integrations_installation_id').using( - 'btree', - table.installationId.asc().nullsLast().op('text_ops') - ), - index('idx_github_integrations_github_org_id').using( - 'btree', - table.githubOrgId.asc().nullsLast().op('text_ops') - ), - ] + // Timestamps + createdAt: timestamp("created_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + updatedAt: timestamp("updated_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + deletedAt: timestamp("deleted_at", { withTimezone: true, mode: "string" }), + }, + (table) => [ + foreignKey({ + columns: [table.organizationId], + foreignColumns: [organizations.id], + name: "github_integrations_organization_id_fkey", + }).onDelete("cascade"), + foreignKey({ + columns: [table.userId], + foreignColumns: [users.id], + name: "github_integrations_user_id_fkey", + }).onDelete("set null"), + unique("github_integrations_org_installation_key").on( + table.organizationId, + table.installationId, + ), + index("idx_github_integrations_org_id").using( + "btree", + table.organizationId.asc().nullsLast().op("uuid_ops"), + ), + index("idx_github_integrations_installation_id").using( + "btree", + table.installationId.asc().nullsLast().op("text_ops"), + ), + index("idx_github_integrations_github_org_id").using( + "btree", + table.githubOrgId.asc().nullsLast().op("text_ops"), + ), + ], ); // Slack message tracking table (optional) export const slackMessageTracking = pgTable( - 'slack_message_tracking', - { - id: uuid().defaultRandom().primaryKey().notNull(), - integrationId: uuid('integration_id').notNull(), + "slack_message_tracking", + { + id: uuid().defaultRandom().primaryKey().notNull(), + integrationId: uuid("integration_id").notNull(), - // Internal reference - internalMessageId: uuid('internal_message_id').notNull().unique(), + // Internal reference + internalMessageId: uuid("internal_message_id").notNull().unique(), - // Slack references - slackChannelId: varchar('slack_channel_id', { length: 255 }).notNull(), - slackMessageTs: varchar('slack_message_ts', { length: 255 }).notNull(), - slackThreadTs: varchar('slack_thread_ts', { length: 255 }), + // Slack references + slackChannelId: varchar("slack_channel_id", { length: 255 }).notNull(), + slackMessageTs: varchar("slack_message_ts", { length: 255 }).notNull(), + slackThreadTs: varchar("slack_thread_ts", { length: 255 }), - // Metadata - messageType: varchar('message_type', { length: 50 }).notNull(), // Source of the message (e.g., 'analyst_message_post_processing') - content: text(), - senderInfo: jsonb('sender_info'), + // Metadata + messageType: varchar("message_type", { length: 50 }).notNull(), // Source of the message (e.g., 'analyst_message_post_processing') + content: text(), + senderInfo: jsonb("sender_info"), - // Timestamps - sentAt: timestamp('sent_at', { withTimezone: true, mode: 'string' }).notNull(), - createdAt: timestamp('created_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - }, - (table) => [ - foreignKey({ - columns: [table.integrationId], - foreignColumns: [slackIntegrations.id], - name: 'slack_message_tracking_integration_id_fkey', - }).onDelete('cascade'), - index('idx_message_tracking_integration').using( - 'btree', - table.integrationId.asc().nullsLast().op('uuid_ops') - ), - index('idx_message_tracking_channel').using( - 'btree', - table.slackChannelId.asc().nullsLast().op('text_ops') - ), - index('idx_message_tracking_thread').using( - 'btree', - table.slackThreadTs.asc().nullsLast().op('text_ops') - ), - ] + // Timestamps + sentAt: timestamp("sent_at", { + withTimezone: true, + mode: "string", + }).notNull(), + createdAt: timestamp("created_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + }, + (table) => [ + foreignKey({ + columns: [table.integrationId], + foreignColumns: [slackIntegrations.id], + name: "slack_message_tracking_integration_id_fkey", + }).onDelete("cascade"), + index("idx_message_tracking_integration").using( + "btree", + table.integrationId.asc().nullsLast().op("uuid_ops"), + ), + index("idx_message_tracking_channel").using( + "btree", + table.slackChannelId.asc().nullsLast().op("text_ops"), + ), + index("idx_message_tracking_thread").using( + "btree", + table.slackThreadTs.asc().nullsLast().op("text_ops"), + ), + ], ); // Join table between messages and slack messages export const messagesToSlackMessages = pgTable( - 'messages_to_slack_messages', - { - messageId: uuid('message_id').notNull(), - slackMessageId: uuid('slack_message_id').notNull(), - createdAt: timestamp('created_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - updatedAt: timestamp('updated_at', { withTimezone: true, mode: 'string' }) - .defaultNow() - .notNull(), - deletedAt: timestamp('deleted_at', { withTimezone: true, mode: 'string' }), - }, - (table) => [ - // Foreign keys - foreignKey({ - columns: [table.messageId], - foreignColumns: [messages.id], - name: 'messages_to_slack_messages_message_id_fkey', - }).onDelete('cascade'), - foreignKey({ - columns: [table.slackMessageId], - foreignColumns: [slackMessageTracking.id], - name: 'messages_to_slack_messages_slack_message_id_fkey', - }).onDelete('cascade'), - // Composite primary key - primaryKey({ - columns: [table.messageId, table.slackMessageId], - name: 'messages_to_slack_messages_pkey', - }), - // Indexes for query performance - index('messages_to_slack_messages_message_id_idx').using( - 'btree', - table.messageId.asc().nullsLast().op('uuid_ops') - ), - index('messages_to_slack_messages_slack_message_id_idx').using( - 'btree', - table.slackMessageId.asc().nullsLast().op('uuid_ops') - ), - ] + "messages_to_slack_messages", + { + messageId: uuid("message_id").notNull(), + slackMessageId: uuid("slack_message_id").notNull(), + createdAt: timestamp("created_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + updatedAt: timestamp("updated_at", { withTimezone: true, mode: "string" }) + .defaultNow() + .notNull(), + deletedAt: timestamp("deleted_at", { withTimezone: true, mode: "string" }), + }, + (table) => [ + // Foreign keys + foreignKey({ + columns: [table.messageId], + foreignColumns: [messages.id], + name: "messages_to_slack_messages_message_id_fkey", + }).onDelete("cascade"), + foreignKey({ + columns: [table.slackMessageId], + foreignColumns: [slackMessageTracking.id], + name: "messages_to_slack_messages_slack_message_id_fkey", + }).onDelete("cascade"), + // Composite primary key + primaryKey({ + columns: [table.messageId, table.slackMessageId], + name: "messages_to_slack_messages_pkey", + }), + // Indexes for query performance + index("messages_to_slack_messages_message_id_idx").using( + "btree", + table.messageId.asc().nullsLast().op("uuid_ops"), + ), + index("messages_to_slack_messages_slack_message_id_idx").using( + "btree", + table.slackMessageId.asc().nullsLast().op("uuid_ops"), + ), + ], );