From 678f2c2b5dd17acecd3b0174190201bbfddf0020 Mon Sep 17 00:00:00 2001 From: Davidson Gomes Date: Fri, 9 Aug 2024 07:58:33 -0300 Subject: [PATCH] prisma: adjusts for mysql and postgres --- .env.example | 2 +- Docker/scripts/deploy_database.sh | 2 +- package.json | 4 +- .../20240809105427_init/migration.sql | 588 ++++++++++++++++++ prisma/mysql-migrations/migration_lock.toml | 3 + prisma/mysql-schema.prisma | 291 +++++++-- .../20240609181238_init/migration.sql | 0 .../migration.sql | 0 .../migration.sql | 0 .../migration.sql | 0 .../migration.sql | 0 .../migration.sql | 0 .../migration.sql | 0 .../migration.sql | 0 .../migration.sql | 0 .../migration.sql | 0 .../migration.sql | 0 .../migration.sql | 0 .../migration.sql | 0 .../migration.sql | 0 .../migration.sql | 0 .../migration.sql | 0 .../migration.sql | 0 .../migration.sql | 0 .../migration.sql | 0 .../migration.sql | 0 .../migration.sql | 0 .../migration.sql | 0 .../migration.sql | 0 .../migration.sql | 0 .../migration.sql | 0 .../migration.sql | 0 .../migration_lock.toml | 0 33 files changed, 842 insertions(+), 48 deletions(-) create mode 100644 prisma/mysql-migrations/20240809105427_init/migration.sql create mode 100644 prisma/mysql-migrations/migration_lock.toml rename prisma/{migrations => postgresql-migrations}/20240609181238_init/migration.sql (100%) rename prisma/{migrations => postgresql-migrations}/20240610144159_create_column_profile_name_instance/migration.sql (100%) rename prisma/{migrations => postgresql-migrations}/20240611125754_create_columns_whitelabel_chatwoot/migration.sql (100%) rename prisma/{migrations => postgresql-migrations}/20240611202817_create_columns_debounce_time_typebot/migration.sql (100%) rename prisma/{migrations => postgresql-migrations}/20240712144948_add_business_id_column_to_instances/migration.sql (100%) rename prisma/{migrations => postgresql-migrations}/20240712150256_create_templates_table/migration.sql (100%) rename prisma/{migrations => postgresql-migrations}/20240712155950_adjusts_in_templates_table/migration.sql (100%) rename prisma/{migrations => postgresql-migrations}/20240712162206_remove_templates_table/migration.sql (100%) rename prisma/{migrations => postgresql-migrations}/20240712223655_column_fallback_typebot/migration.sql (100%) rename prisma/{migrations => postgresql-migrations}/20240712230631_column_ignore_jids_typebot/migration.sql (100%) rename prisma/{migrations => postgresql-migrations}/20240713184337_add_media_table/migration.sql (100%) rename prisma/{migrations => postgresql-migrations}/20240718121437_add_openai_tables/migration.sql (100%) rename prisma/{migrations => postgresql-migrations}/20240718123923_adjusts_openai_tables/migration.sql (100%) rename prisma/{migrations => postgresql-migrations}/20240722173259_add_name_column_to_openai_creds/migration.sql (100%) rename prisma/{migrations => postgresql-migrations}/20240722173518_add_name_column_to_openai_creds/migration.sql (100%) rename prisma/{migrations => postgresql-migrations}/20240723152648_adjusts_in_column_openai_creds/migration.sql (100%) rename prisma/{migrations => postgresql-migrations}/20240723200254_add_webhookurl_on_message/migration.sql (100%) rename prisma/{migrations => postgresql-migrations}/20240725184147_create_template_table/migration.sql (100%) rename prisma/{migrations => postgresql-migrations}/20240725202651_add_webhook_url_template_table/migration.sql (100%) rename prisma/{migrations => postgresql-migrations}/20240725221646_modify_token_instance_table/migration.sql (100%) rename prisma/{migrations => postgresql-migrations}/20240729115127_modify_trigger_type_openai_typebot_table/migration.sql (100%) rename prisma/{migrations => postgresql-migrations}/20240729180347_modify_typebot_session_status_openai_typebot_table/migration.sql (100%) rename prisma/{migrations => postgresql-migrations}/20240730152156_create_dify_tables/migration.sql (100%) rename prisma/{migrations => postgresql-migrations}/20240801193907_add_column_speech_to_text_openai_setting_table/migration.sql (100%) rename prisma/{migrations => postgresql-migrations}/20240803163908_add_column_description_on_integrations_table/migration.sql (100%) rename prisma/{migrations => postgresql-migrations}/20240808210239_add_column_function_url_openaibot_table/migration.sql (100%) rename prisma/{migrations => postgresql-migrations}/migration_lock.toml (100%) diff --git a/.env.example b/.env.example index 76169cd0..30a55879 100644 --- a/.env.example +++ b/.env.example @@ -21,7 +21,7 @@ DEL_INSTANCE=false # Permanent data storage DATABASE_ENABLED=true -# Provider: postgresql +# Provider: postgresql | mysql DATABASE_PROVIDER=postgresql DATABASE_CONNECTION_URI='postgresql://user:pass@localhost:5432/evolution?schema=public' # Client name for the database connection diff --git a/Docker/scripts/deploy_database.sh b/Docker/scripts/deploy_database.sh index c9a6813a..33b0a1cd 100755 --- a/Docker/scripts/deploy_database.sh +++ b/Docker/scripts/deploy_database.sh @@ -10,7 +10,7 @@ if [[ "$DATABASE_PROVIDER" == "postgresql" || "$DATABASE_PROVIDER" == "mysql" ]] export DATABASE_URL echo "Deploying migrations for $DATABASE_PROVIDER" echo "Database URL: $DATABASE_URL" - npx prisma migrate deploy --schema ./prisma/$DATABASE_PROVIDER-schema.prisma + npx prisma migrate deploy --schema ./prisma/$DATABASE_PROVIDER-schema.prisma --migrations ./prisma/migrations/$DATABASE_PROVIDER if [ $? -ne 0 ]; then echo "Migration failed" exit 1 diff --git a/package.json b/package.json index dcc84b57..fa9168f8 100644 --- a/package.json +++ b/package.json @@ -10,8 +10,8 @@ "dev:server": "clear && tsnd --files --transpile-only --respawn --ignore-watch node_modules ./src/main.ts", "test": "clear && tsnd --files --transpile-only --respawn --ignore-watch node_modules ./test/all.test.ts", "lint": "eslint --fix --ext .ts src", - "db:migrate:postgres": "npx prisma migrate dev --name init --schema ./prisma/postgresql-schema.prisma", - "db:migrate:mysql": "npx prisma migrate dev --name init --schema ./prisma/mysql-schema.prisma", + "db:migrate:postgres": "rm -rf ./prisma/migrations && cp -r ./prisma/postgresql-migrations ./prisma/migrations && npx prisma migrate dev --name init --schema ./prisma/postgresql-schema.prisma", + "db:migrate:mysql": "rm -rf ./prisma/migrations && cp -r ./prisma/mysql-migrations ./prisma/migrations && npx prisma migrate dev --name init --schema ./prisma/mysql-schema.prisma", "db:studio:postgres": "npx prisma studio --schema ./prisma/postgresql-schema.prisma", "db:studio:mysql": "npx prisma studio --schema ./prisma/mysql-schema.prisma" }, diff --git a/prisma/mysql-migrations/20240809105427_init/migration.sql b/prisma/mysql-migrations/20240809105427_init/migration.sql new file mode 100644 index 00000000..096aebb0 --- /dev/null +++ b/prisma/mysql-migrations/20240809105427_init/migration.sql @@ -0,0 +1,588 @@ +-- CreateTable +CREATE TABLE `Instance` ( + `id` VARCHAR(191) NOT NULL, + `name` VARCHAR(255) NOT NULL, + `connectionStatus` ENUM('open', 'close', 'connecting') NOT NULL DEFAULT 'open', + `ownerJid` VARCHAR(100) NULL, + `profileName` VARCHAR(100) NULL, + `profilePicUrl` VARCHAR(500) NULL, + `integration` VARCHAR(100) NULL, + `number` VARCHAR(100) NULL, + `businessId` VARCHAR(100) NULL, + `token` VARCHAR(255) NULL, + `clientName` VARCHAR(100) NULL, + `disconnectionReasonCode` INTEGER NULL, + `disconnectionObject` JSON NULL, + `disconnectionAt` TIMESTAMP NULL, + `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, + `updatedAt` TIMESTAMP NULL, + + UNIQUE INDEX `Instance_name_key`(`name`), + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `Session` ( + `id` VARCHAR(191) NOT NULL, + `sessionId` VARCHAR(191) NOT NULL, + `creds` TEXT NULL, + `createdAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + + UNIQUE INDEX `Session_sessionId_key`(`sessionId`), + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `Chat` ( + `id` VARCHAR(191) NOT NULL, + `remoteJid` VARCHAR(100) NOT NULL, + `labels` JSON NULL, + `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, + `updatedAt` TIMESTAMP NULL, + `instanceId` VARCHAR(191) NOT NULL, + + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `Contact` ( + `id` VARCHAR(191) NOT NULL, + `remoteJid` VARCHAR(100) NOT NULL, + `pushName` VARCHAR(100) NULL, + `profilePicUrl` VARCHAR(500) NULL, + `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, + `updatedAt` TIMESTAMP NULL, + `instanceId` VARCHAR(191) NOT NULL, + + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `Message` ( + `id` VARCHAR(191) NOT NULL, + `key` JSON NOT NULL, + `pushName` VARCHAR(100) NULL, + `participant` VARCHAR(100) NULL, + `messageType` VARCHAR(100) NOT NULL, + `message` JSON NOT NULL, + `contextInfo` JSON NULL, + `source` ENUM('ios', 'android', 'web', 'unknown', 'desktop') NOT NULL, + `messageTimestamp` INTEGER NOT NULL, + `chatwootMessageId` INTEGER NULL, + `chatwootInboxId` INTEGER NULL, + `chatwootConversationId` INTEGER NULL, + `chatwootContactInboxSourceId` VARCHAR(100) NULL, + `chatwootIsRead` BOOLEAN NULL DEFAULT false, + `instanceId` VARCHAR(191) NOT NULL, + `typebotSessionId` VARCHAR(191) NULL, + `openaiSessionId` VARCHAR(191) NULL, + `webhookUrl` VARCHAR(500) NULL, + `difySessionId` VARCHAR(191) NULL, + + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `MessageUpdate` ( + `id` VARCHAR(191) NOT NULL, + `keyId` VARCHAR(100) NOT NULL, + `remoteJid` VARCHAR(100) NOT NULL, + `fromMe` BOOLEAN NOT NULL, + `participant` VARCHAR(100) NULL, + `pollUpdates` JSON NULL, + `status` VARCHAR(30) NOT NULL, + `messageId` VARCHAR(191) NOT NULL, + `instanceId` VARCHAR(191) NOT NULL, + + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `Webhook` ( + `id` VARCHAR(191) NOT NULL, + `url` VARCHAR(500) NOT NULL, + `enabled` BOOLEAN NULL DEFAULT true, + `events` JSON NULL, + `webhookByEvents` BOOLEAN NULL DEFAULT false, + `webhookBase64` BOOLEAN NULL DEFAULT false, + `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, + `updatedAt` TIMESTAMP NOT NULL, + `instanceId` VARCHAR(191) NOT NULL, + + UNIQUE INDEX `Webhook_instanceId_key`(`instanceId`), + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `Chatwoot` ( + `id` VARCHAR(191) NOT NULL, + `enabled` BOOLEAN NULL DEFAULT true, + `accountId` VARCHAR(100) NULL, + `token` VARCHAR(100) NULL, + `url` VARCHAR(500) NULL, + `nameInbox` VARCHAR(100) NULL, + `signMsg` BOOLEAN NULL DEFAULT false, + `signDelimiter` VARCHAR(100) NULL, + `number` VARCHAR(100) NULL, + `reopenConversation` BOOLEAN NULL DEFAULT false, + `conversationPending` BOOLEAN NULL DEFAULT false, + `mergeBrazilContacts` BOOLEAN NULL DEFAULT false, + `importContacts` BOOLEAN NULL DEFAULT false, + `importMessages` BOOLEAN NULL DEFAULT false, + `daysLimitImportMessages` INTEGER NULL, + `organization` VARCHAR(100) NULL, + `logo` VARCHAR(500) NULL, + `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, + `updatedAt` TIMESTAMP NOT NULL, + `instanceId` VARCHAR(191) NOT NULL, + + UNIQUE INDEX `Chatwoot_instanceId_key`(`instanceId`), + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `Label` ( + `id` VARCHAR(191) NOT NULL, + `labelId` VARCHAR(100) NULL, + `name` VARCHAR(100) NOT NULL, + `color` VARCHAR(100) NOT NULL, + `predefinedId` VARCHAR(100) NULL, + `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, + `updatedAt` TIMESTAMP NOT NULL, + `instanceId` VARCHAR(191) NOT NULL, + + UNIQUE INDEX `Label_labelId_key`(`labelId`), + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `Proxy` ( + `id` VARCHAR(191) NOT NULL, + `enabled` BOOLEAN NOT NULL DEFAULT false, + `host` VARCHAR(100) NOT NULL, + `port` VARCHAR(100) NOT NULL, + `protocol` VARCHAR(100) NOT NULL, + `username` VARCHAR(100) NOT NULL, + `password` VARCHAR(100) NOT NULL, + `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, + `updatedAt` TIMESTAMP NOT NULL, + `instanceId` VARCHAR(191) NOT NULL, + + UNIQUE INDEX `Proxy_instanceId_key`(`instanceId`), + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `Setting` ( + `id` VARCHAR(191) NOT NULL, + `rejectCall` BOOLEAN NOT NULL DEFAULT false, + `msgCall` VARCHAR(100) NULL, + `groupsIgnore` BOOLEAN NOT NULL DEFAULT false, + `alwaysOnline` BOOLEAN NOT NULL DEFAULT false, + `readMessages` BOOLEAN NOT NULL DEFAULT false, + `readStatus` BOOLEAN NOT NULL DEFAULT false, + `syncFullHistory` BOOLEAN NOT NULL DEFAULT false, + `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, + `updatedAt` TIMESTAMP NOT NULL, + `instanceId` VARCHAR(191) NOT NULL, + + UNIQUE INDEX `Setting_instanceId_key`(`instanceId`), + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `Rabbitmq` ( + `id` VARCHAR(191) NOT NULL, + `enabled` BOOLEAN NOT NULL DEFAULT false, + `events` JSON NOT NULL, + `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, + `updatedAt` TIMESTAMP NOT NULL, + `instanceId` VARCHAR(191) NOT NULL, + + UNIQUE INDEX `Rabbitmq_instanceId_key`(`instanceId`), + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `Sqs` ( + `id` VARCHAR(191) NOT NULL, + `enabled` BOOLEAN NOT NULL DEFAULT false, + `events` JSON NOT NULL, + `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, + `updatedAt` TIMESTAMP NOT NULL, + `instanceId` VARCHAR(191) NOT NULL, + + UNIQUE INDEX `Sqs_instanceId_key`(`instanceId`), + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `Websocket` ( + `id` VARCHAR(191) NOT NULL, + `enabled` BOOLEAN NOT NULL DEFAULT false, + `events` JSON NOT NULL, + `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, + `updatedAt` TIMESTAMP NOT NULL, + `instanceId` VARCHAR(191) NOT NULL, + + UNIQUE INDEX `Websocket_instanceId_key`(`instanceId`), + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `Typebot` ( + `id` VARCHAR(191) NOT NULL, + `enabled` BOOLEAN NOT NULL DEFAULT true, + `description` VARCHAR(255) NULL, + `url` VARCHAR(500) NOT NULL, + `typebot` VARCHAR(100) NOT NULL, + `expire` INTEGER NULL DEFAULT 0, + `keywordFinish` VARCHAR(100) NULL, + `delayMessage` INTEGER NULL, + `unknownMessage` VARCHAR(100) NULL, + `listeningFromMe` BOOLEAN NULL DEFAULT false, + `stopBotFromMe` BOOLEAN NULL DEFAULT false, + `keepOpen` BOOLEAN NULL DEFAULT false, + `debounceTime` INTEGER NULL, + `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, + `updatedAt` TIMESTAMP NULL, + `ignoreJids` JSON NULL, + `triggerType` ENUM('all', 'keyword', 'none') NULL, + `triggerOperator` ENUM('contains', 'equals', 'startsWith', 'endsWith', 'regex') NULL, + `triggerValue` VARCHAR(191) NULL, + `instanceId` VARCHAR(191) NOT NULL, + + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `TypebotSession` ( + `id` VARCHAR(191) NOT NULL, + `remoteJid` VARCHAR(100) NOT NULL, + `pushName` VARCHAR(100) NULL, + `sessionId` VARCHAR(100) NOT NULL, + `status` ENUM('opened', 'closed', 'paused') NOT NULL, + `prefilledVariables` JSON NULL, + `awaitUser` BOOLEAN NOT NULL DEFAULT false, + `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, + `updatedAt` TIMESTAMP NOT NULL, + `typebotId` VARCHAR(191) NOT NULL, + `instanceId` VARCHAR(191) NOT NULL, + + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `TypebotSetting` ( + `id` VARCHAR(191) NOT NULL, + `expire` INTEGER NULL DEFAULT 0, + `keywordFinish` VARCHAR(100) NULL, + `delayMessage` INTEGER NULL, + `unknownMessage` VARCHAR(100) NULL, + `listeningFromMe` BOOLEAN NULL DEFAULT false, + `stopBotFromMe` BOOLEAN NULL DEFAULT false, + `keepOpen` BOOLEAN NULL DEFAULT false, + `debounceTime` INTEGER NULL, + `typebotIdFallback` VARCHAR(100) NULL, + `ignoreJids` JSON NULL, + `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, + `updatedAt` TIMESTAMP NOT NULL, + `instanceId` VARCHAR(191) NOT NULL, + + UNIQUE INDEX `TypebotSetting_instanceId_key`(`instanceId`), + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `Media` ( + `id` VARCHAR(191) NOT NULL, + `fileName` VARCHAR(500) NOT NULL, + `type` VARCHAR(100) NOT NULL, + `mimetype` VARCHAR(100) NOT NULL, + `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, + `messageId` VARCHAR(191) NOT NULL, + `instanceId` VARCHAR(191) NOT NULL, + + UNIQUE INDEX `Media_fileName_key`(`fileName`), + UNIQUE INDEX `Media_messageId_key`(`messageId`), + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `OpenaiCreds` ( + `id` VARCHAR(191) NOT NULL, + `name` VARCHAR(255) NULL, + `apiKey` VARCHAR(255) NULL, + `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, + `updatedAt` TIMESTAMP NOT NULL, + `instanceId` VARCHAR(191) NOT NULL, + + UNIQUE INDEX `OpenaiCreds_name_key`(`name`), + UNIQUE INDEX `OpenaiCreds_apiKey_key`(`apiKey`), + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `OpenaiBot` ( + `id` VARCHAR(191) NOT NULL, + `enabled` BOOLEAN NOT NULL DEFAULT true, + `description` VARCHAR(255) NULL, + `botType` ENUM('assistant', 'chatCompletion') NOT NULL, + `assistantId` VARCHAR(255) NULL, + `functionUrl` VARCHAR(500) NULL, + `model` VARCHAR(100) NULL, + `systemMessages` JSON NULL, + `assistantMessages` JSON NULL, + `userMessages` JSON NULL, + `maxTokens` INTEGER NULL, + `expire` INTEGER NULL DEFAULT 0, + `keywordFinish` VARCHAR(100) NULL, + `delayMessage` INTEGER NULL, + `unknownMessage` VARCHAR(100) NULL, + `listeningFromMe` BOOLEAN NULL DEFAULT false, + `stopBotFromMe` BOOLEAN NULL DEFAULT false, + `keepOpen` BOOLEAN NULL DEFAULT false, + `debounceTime` INTEGER NULL, + `ignoreJids` JSON NULL, + `triggerType` ENUM('all', 'keyword', 'none') NULL, + `triggerOperator` ENUM('contains', 'equals', 'startsWith', 'endsWith', 'regex') NULL, + `triggerValue` VARCHAR(191) NULL, + `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, + `updatedAt` TIMESTAMP NOT NULL, + `openaiCredsId` VARCHAR(191) NOT NULL, + `instanceId` VARCHAR(191) NOT NULL, + + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `OpenaiSession` ( + `id` VARCHAR(191) NOT NULL, + `sessionId` VARCHAR(255) NOT NULL, + `remoteJid` VARCHAR(100) NOT NULL, + `status` ENUM('opened', 'closed', 'paused') NOT NULL, + `awaitUser` BOOLEAN NOT NULL DEFAULT false, + `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, + `updatedAt` TIMESTAMP NOT NULL, + `openaiBotId` VARCHAR(191) NOT NULL, + `instanceId` VARCHAR(191) NOT NULL, + + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `OpenaiSetting` ( + `id` VARCHAR(191) NOT NULL, + `expire` INTEGER NULL DEFAULT 0, + `keywordFinish` VARCHAR(100) NULL, + `delayMessage` INTEGER NULL, + `unknownMessage` VARCHAR(100) NULL, + `listeningFromMe` BOOLEAN NULL DEFAULT false, + `stopBotFromMe` BOOLEAN NULL DEFAULT false, + `keepOpen` BOOLEAN NULL DEFAULT false, + `debounceTime` INTEGER NULL, + `ignoreJids` JSON NULL, + `speechToText` BOOLEAN NULL DEFAULT false, + `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, + `updatedAt` TIMESTAMP NOT NULL, + `openaiCredsId` VARCHAR(191) NOT NULL, + `openaiIdFallback` VARCHAR(100) NULL, + `instanceId` VARCHAR(191) NOT NULL, + + UNIQUE INDEX `OpenaiSetting_openaiCredsId_key`(`openaiCredsId`), + UNIQUE INDEX `OpenaiSetting_instanceId_key`(`instanceId`), + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `Template` ( + `id` VARCHAR(191) NOT NULL, + `templateId` VARCHAR(255) NOT NULL, + `name` VARCHAR(255) NOT NULL, + `template` JSON NOT NULL, + `webhookUrl` VARCHAR(500) NULL, + `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, + `updatedAt` TIMESTAMP NOT NULL, + `instanceId` VARCHAR(191) NOT NULL, + + UNIQUE INDEX `Template_templateId_key`(`templateId`), + UNIQUE INDEX `Template_name_key`(`name`), + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `Dify` ( + `id` VARCHAR(191) NOT NULL, + `enabled` BOOLEAN NOT NULL DEFAULT true, + `description` VARCHAR(255) NULL, + `botType` ENUM('chatBot', 'textGenerator', 'agent', 'workflow') NOT NULL, + `apiUrl` VARCHAR(255) NULL, + `apiKey` VARCHAR(255) NULL, + `expire` INTEGER NULL DEFAULT 0, + `keywordFinish` VARCHAR(100) NULL, + `delayMessage` INTEGER NULL, + `unknownMessage` VARCHAR(100) NULL, + `listeningFromMe` BOOLEAN NULL DEFAULT false, + `stopBotFromMe` BOOLEAN NULL DEFAULT false, + `keepOpen` BOOLEAN NULL DEFAULT false, + `debounceTime` INTEGER NULL, + `ignoreJids` JSON NULL, + `triggerType` ENUM('all', 'keyword', 'none') NULL, + `triggerOperator` ENUM('contains', 'equals', 'startsWith', 'endsWith', 'regex') NULL, + `triggerValue` VARCHAR(191) NULL, + `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, + `updatedAt` TIMESTAMP NOT NULL, + `instanceId` VARCHAR(191) NOT NULL, + + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `DifySession` ( + `id` VARCHAR(191) NOT NULL, + `sessionId` VARCHAR(255) NOT NULL, + `remoteJid` VARCHAR(100) NOT NULL, + `status` ENUM('opened', 'closed', 'paused') NOT NULL, + `awaitUser` BOOLEAN NOT NULL DEFAULT false, + `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, + `updatedAt` TIMESTAMP NOT NULL, + `difyId` VARCHAR(191) NOT NULL, + `instanceId` VARCHAR(191) NOT NULL, + + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `DifySetting` ( + `id` VARCHAR(191) NOT NULL, + `expire` INTEGER NULL DEFAULT 0, + `keywordFinish` VARCHAR(100) NULL, + `delayMessage` INTEGER NULL, + `unknownMessage` VARCHAR(100) NULL, + `listeningFromMe` BOOLEAN NULL DEFAULT false, + `stopBotFromMe` BOOLEAN NULL DEFAULT false, + `keepOpen` BOOLEAN NULL DEFAULT false, + `debounceTime` INTEGER NULL, + `ignoreJids` JSON NULL, + `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, + `updatedAt` TIMESTAMP NOT NULL, + `difyIdFallback` VARCHAR(100) NULL, + `instanceId` VARCHAR(191) NOT NULL, + + UNIQUE INDEX `DifySetting_instanceId_key`(`instanceId`), + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- AddForeignKey +ALTER TABLE `Session` ADD CONSTRAINT `Session_sessionId_fkey` FOREIGN KEY (`sessionId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `Chat` ADD CONSTRAINT `Chat_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `Contact` ADD CONSTRAINT `Contact_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `Message` ADD CONSTRAINT `Message_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `Message` ADD CONSTRAINT `Message_typebotSessionId_fkey` FOREIGN KEY (`typebotSessionId`) REFERENCES `TypebotSession`(`id`) ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `Message` ADD CONSTRAINT `Message_openaiSessionId_fkey` FOREIGN KEY (`openaiSessionId`) REFERENCES `OpenaiSession`(`id`) ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `Message` ADD CONSTRAINT `Message_difySessionId_fkey` FOREIGN KEY (`difySessionId`) REFERENCES `DifySession`(`id`) ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `MessageUpdate` ADD CONSTRAINT `MessageUpdate_messageId_fkey` FOREIGN KEY (`messageId`) REFERENCES `Message`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `MessageUpdate` ADD CONSTRAINT `MessageUpdate_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `Webhook` ADD CONSTRAINT `Webhook_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `Chatwoot` ADD CONSTRAINT `Chatwoot_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `Label` ADD CONSTRAINT `Label_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `Proxy` ADD CONSTRAINT `Proxy_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `Setting` ADD CONSTRAINT `Setting_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `Rabbitmq` ADD CONSTRAINT `Rabbitmq_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `Sqs` ADD CONSTRAINT `Sqs_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `Websocket` ADD CONSTRAINT `Websocket_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `Typebot` ADD CONSTRAINT `Typebot_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `TypebotSession` ADD CONSTRAINT `TypebotSession_typebotId_fkey` FOREIGN KEY (`typebotId`) REFERENCES `Typebot`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `TypebotSession` ADD CONSTRAINT `TypebotSession_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `TypebotSetting` ADD CONSTRAINT `TypebotSetting_typebotIdFallback_fkey` FOREIGN KEY (`typebotIdFallback`) REFERENCES `Typebot`(`id`) ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `TypebotSetting` ADD CONSTRAINT `TypebotSetting_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `Media` ADD CONSTRAINT `Media_messageId_fkey` FOREIGN KEY (`messageId`) REFERENCES `Message`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `Media` ADD CONSTRAINT `Media_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `OpenaiCreds` ADD CONSTRAINT `OpenaiCreds_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `OpenaiBot` ADD CONSTRAINT `OpenaiBot_openaiCredsId_fkey` FOREIGN KEY (`openaiCredsId`) REFERENCES `OpenaiCreds`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `OpenaiBot` ADD CONSTRAINT `OpenaiBot_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `OpenaiSession` ADD CONSTRAINT `OpenaiSession_openaiBotId_fkey` FOREIGN KEY (`openaiBotId`) REFERENCES `OpenaiBot`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `OpenaiSession` ADD CONSTRAINT `OpenaiSession_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `OpenaiSetting` ADD CONSTRAINT `OpenaiSetting_openaiCredsId_fkey` FOREIGN KEY (`openaiCredsId`) REFERENCES `OpenaiCreds`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `OpenaiSetting` ADD CONSTRAINT `OpenaiSetting_openaiIdFallback_fkey` FOREIGN KEY (`openaiIdFallback`) REFERENCES `OpenaiBot`(`id`) ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `OpenaiSetting` ADD CONSTRAINT `OpenaiSetting_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `Template` ADD CONSTRAINT `Template_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `Dify` ADD CONSTRAINT `Dify_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `DifySession` ADD CONSTRAINT `DifySession_difyId_fkey` FOREIGN KEY (`difyId`) REFERENCES `Dify`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `DifySession` ADD CONSTRAINT `DifySession_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `DifySetting` ADD CONSTRAINT `DifySetting_difyIdFallback_fkey` FOREIGN KEY (`difyIdFallback`) REFERENCES `Dify`(`id`) ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `DifySetting` ADD CONSTRAINT `DifySetting_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/prisma/mysql-migrations/migration_lock.toml b/prisma/mysql-migrations/migration_lock.toml new file mode 100644 index 00000000..e5a788a7 --- /dev/null +++ b/prisma/mysql-migrations/migration_lock.toml @@ -0,0 +1,3 @@ +# Please do not edit this file manually +# It should be added in your version-control system (i.e. Git) +provider = "mysql" \ No newline at end of file diff --git a/prisma/mysql-schema.prisma b/prisma/mysql-schema.prisma index 8a4748fc..ed82c7e7 100644 --- a/prisma/mysql-schema.prisma +++ b/prisma/mysql-schema.prisma @@ -28,7 +28,7 @@ enum DeviceMessage { } enum TypebotSessionStatus { - open + opened closed paused } @@ -44,6 +44,19 @@ enum TriggerOperator { equals startsWith endsWith + regex +} + +enum OpenaiBotType { + assistant + chatCompletion +} + +enum DifyBotType { + chatBot + textGenerator + agent + workflow } model Instance { @@ -55,12 +68,13 @@ model Instance { profilePicUrl String? @db.VarChar(500) integration String? @db.VarChar(100) number String? @db.VarChar(100) - token String? @unique @db.VarChar(255) + businessId String? @db.VarChar(100) + token String? @db.VarChar(255) clientName String? @db.VarChar(100) disconnectionReasonCode Int? @db.Int disconnectionObject Json? @db.Json disconnectionAt DateTime? @db.Timestamp - createdAt DateTime? @default(now()) @db.Timestamp + createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp updatedAt DateTime? @updatedAt @db.Timestamp Chat Chat[] Contact Contact[] @@ -78,13 +92,22 @@ model Instance { MessageUpdate MessageUpdate[] TypebotSession TypebotSession[] TypebotSetting TypebotSetting? + Media Media[] + OpenaiCreds OpenaiCreds[] + OpenaiBot OpenaiBot[] + OpenaiSession OpenaiSession[] + OpenaiSetting OpenaiSetting? + Template Template[] + Dify Dify[] + DifySession DifySession[] + DifySetting DifySetting? } model Session { id String @id @default(cuid()) sessionId String @unique creds String? @db.Text - createdAt DateTime @default(now()) + createdAt DateTime @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp Instance Instance @relation(fields: [sessionId], references: [id], onDelete: Cascade) } @@ -92,8 +115,8 @@ model Chat { id String @id @default(cuid()) remoteJid String @db.VarChar(100) labels Json? @db.Json - createdAt DateTime? @default(now()) @db.Date - updatedAt DateTime? @updatedAt @db.Date + createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp + updatedAt DateTime? @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String } @@ -103,8 +126,8 @@ model Contact { remoteJid String @db.VarChar(100) pushName String? @db.VarChar(100) profilePicUrl String? @db.VarChar(500) - createdAt DateTime? @default(now()) @db.Date - updatedAt DateTime? @updatedAt @db.Date + createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp + updatedAt DateTime? @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String } @@ -118,17 +141,23 @@ model Message { message Json @db.Json contextInfo Json? @db.Json source DeviceMessage - messageTimestamp String @db.VarChar(100) + messageTimestamp Int @db.Int chatwootMessageId Int? @db.Int chatwootInboxId Int? @db.Int chatwootConversationId Int? @db.Int chatwootContactInboxSourceId String? @db.VarChar(100) - chatwootIsRead Boolean? + chatwootIsRead Boolean? @default(false) Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String typebotSessionId String? MessageUpdate MessageUpdate[] TypebotSession TypebotSession? @relation(fields: [typebotSessionId], references: [id]) + Media Media? + OpenaiSession OpenaiSession? @relation(fields: [openaiSessionId], references: [id]) + openaiSessionId String? + webhookUrl String? @db.VarChar(500) + DifySession DifySession? @relation(fields: [difySessionId], references: [id]) + difySessionId String? } model MessageUpdate { @@ -137,7 +166,6 @@ model MessageUpdate { remoteJid String @db.VarChar(100) fromMe Boolean participant String? @db.VarChar(100) - dateTime DateTime @db.Date pollUpdates Json? @db.Json status String @db.VarChar(30) Message Message @relation(fields: [messageId], references: [id], onDelete: Cascade) @@ -149,12 +177,12 @@ model MessageUpdate { model Webhook { id String @id @default(cuid()) url String @db.VarChar(500) - enabled Boolean? @default(false) + enabled Boolean? @default(true) events Json? @db.Json webhookByEvents Boolean? @default(false) webhookBase64 Boolean? @default(false) - createdAt DateTime? @default(now()) @db.Date - updatedAt DateTime @updatedAt @db.Date + createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp + updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique } @@ -176,9 +204,9 @@ model Chatwoot { importMessages Boolean? @default(false) daysLimitImportMessages Int? @db.Int organization String? @db.VarChar(100) - logoUrl String? @db.VarChar(500) - createdAt DateTime? @default(now()) @db.Date - updatedAt DateTime @updatedAt @db.Date + logo String? @db.VarChar(500) + createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp + updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique } @@ -189,8 +217,8 @@ model Label { name String @db.VarChar(100) color String @db.VarChar(100) predefinedId String? @db.VarChar(100) - createdAt DateTime? @default(now()) @db.Date - updatedAt DateTime @updatedAt @db.Date + createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp + updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String } @@ -203,8 +231,8 @@ model Proxy { protocol String @db.VarChar(100) username String @db.VarChar(100) password String @db.VarChar(100) - createdAt DateTime? @default(now()) @db.Date - updatedAt DateTime @updatedAt @db.Date + createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp + updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique } @@ -218,8 +246,8 @@ model Setting { readMessages Boolean @default(false) readStatus Boolean @default(false) syncFullHistory Boolean @default(false) - createdAt DateTime? @default(now()) @db.Date - updatedAt DateTime @updatedAt @db.Date + createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp + updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique } @@ -228,8 +256,8 @@ model Rabbitmq { id String @id @default(cuid()) enabled Boolean @default(false) events Json @db.Json - createdAt DateTime? @default(now()) @db.Date - updatedAt DateTime @updatedAt @db.Date + createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp + updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique } @@ -238,8 +266,8 @@ model Sqs { id String @id @default(cuid()) enabled Boolean @default(false) events Json @db.Json - createdAt DateTime? @default(now()) @db.Date - updatedAt DateTime @updatedAt @db.Date + createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp + updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique } @@ -248,8 +276,8 @@ model Websocket { id String @id @default(cuid()) enabled Boolean @default(false) events Json @db.Json - createdAt DateTime? @default(now()) @db.Date - updatedAt DateTime @updatedAt @db.Date + createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp + updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique } @@ -257,6 +285,7 @@ model Websocket { model Typebot { id String @id @default(cuid()) enabled Boolean @default(true) + description String? @db.VarChar(255) url String @db.VarChar(500) typebot String @db.VarChar(100) expire Int? @default(0) @db.Int @@ -267,34 +296,204 @@ model Typebot { stopBotFromMe Boolean? @default(false) keepOpen Boolean? @default(false) debounceTime Int? @db.Int - createdAt DateTime? @default(now()) @db.Date - updatedAt DateTime? @updatedAt @db.Date + createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp + updatedAt DateTime? @updatedAt @db.Timestamp + ignoreJids Json? triggerType TriggerType? triggerOperator TriggerOperator? triggerValue String? Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String sessions TypebotSession[] + TypebotSetting TypebotSetting[] } model TypebotSession { - id String @id @default(cuid()) - remoteJid String @db.VarChar(100) - pushName String? @db.VarChar(100) - sessionId String @db.VarChar(100) - status String @db.VarChar(100) - prefilledVariables Json? @db.Json - debounceTime Int? @db.Int - createdAt DateTime? @default(now()) @db.Date - updatedAt DateTime @updatedAt @db.Date - Typebot Typebot @relation(fields: [typebotId], references: [id], onDelete: Cascade) + id String @id @default(cuid()) + remoteJid String @db.VarChar(100) + pushName String? @db.VarChar(100) + sessionId String @db.VarChar(100) + status TypebotSessionStatus + prefilledVariables Json? @db.Json + awaitUser Boolean @default(false) + createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp + updatedAt DateTime @updatedAt @db.Timestamp + Typebot Typebot @relation(fields: [typebotId], references: [id], onDelete: Cascade) typebotId String Message Message[] - Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) + Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String } model TypebotSetting { + id String @id @default(cuid()) + expire Int? @default(0) @db.Int + keywordFinish String? @db.VarChar(100) + delayMessage Int? @db.Int + unknownMessage String? @db.VarChar(100) + listeningFromMe Boolean? @default(false) + stopBotFromMe Boolean? @default(false) + keepOpen Boolean? @default(false) + debounceTime Int? @db.Int + typebotIdFallback String? @db.VarChar(100) + ignoreJids Json? + createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp + updatedAt DateTime @updatedAt @db.Timestamp + Fallback Typebot? @relation(fields: [typebotIdFallback], references: [id]) + Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) + instanceId String @unique +} + +model Media { + id String @id @default(cuid()) + fileName String @unique @db.VarChar(500) + type String @db.VarChar(100) + mimetype String @db.VarChar(100) + createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp + Message Message @relation(fields: [messageId], references: [id], onDelete: Cascade) + messageId String @unique + Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) + instanceId String +} + +model OpenaiCreds { + id String @id @default(cuid()) + name String? @unique @db.VarChar(255) + apiKey String? @unique @db.VarChar(255) + createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp + updatedAt DateTime @updatedAt @db.Timestamp + Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) + instanceId String + OpenaiAssistant OpenaiBot[] + OpenaiSetting OpenaiSetting? +} + +model OpenaiBot { + id String @id @default(cuid()) + enabled Boolean @default(true) + description String? @db.VarChar(255) + botType OpenaiBotType + assistantId String? @db.VarChar(255) + functionUrl String? @db.VarChar(500) + model String? @db.VarChar(100) + systemMessages Json? @db.Json + assistantMessages Json? @db.Json + userMessages Json? @db.Json + maxTokens Int? @db.Int + expire Int? @default(0) @db.Int + keywordFinish String? @db.VarChar(100) + delayMessage Int? @db.Int + unknownMessage String? @db.VarChar(100) + listeningFromMe Boolean? @default(false) + stopBotFromMe Boolean? @default(false) + keepOpen Boolean? @default(false) + debounceTime Int? @db.Int + ignoreJids Json? + triggerType TriggerType? + triggerOperator TriggerOperator? + triggerValue String? + createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp + updatedAt DateTime @updatedAt @db.Timestamp + OpenaiCreds OpenaiCreds @relation(fields: [openaiCredsId], references: [id], onDelete: Cascade) + openaiCredsId String + Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) + instanceId String + OpenaiSession OpenaiSession[] + OpenaiSetting OpenaiSetting[] +} + +model OpenaiSession { + id String @id @default(cuid()) + sessionId String @db.VarChar(255) + remoteJid String @db.VarChar(100) + status TypebotSessionStatus + awaitUser Boolean @default(false) + createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp + updatedAt DateTime @updatedAt @db.Timestamp + OpenaiBot OpenaiBot @relation(fields: [openaiBotId], references: [id], onDelete: Cascade) + openaiBotId String + Message Message[] + Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) + instanceId String +} + +model OpenaiSetting { + id String @id @default(cuid()) + expire Int? @default(0) @db.Int + keywordFinish String? @db.VarChar(100) + delayMessage Int? @db.Int + unknownMessage String? @db.VarChar(100) + listeningFromMe Boolean? @default(false) + stopBotFromMe Boolean? @default(false) + keepOpen Boolean? @default(false) + debounceTime Int? @db.Int + ignoreJids Json? + speechToText Boolean? @default(false) + createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp + updatedAt DateTime @updatedAt @db.Timestamp + OpenaiCreds OpenaiCreds? @relation(fields: [openaiCredsId], references: [id]) + openaiCredsId String @unique + Fallback OpenaiBot? @relation(fields: [openaiIdFallback], references: [id]) + openaiIdFallback String? @db.VarChar(100) + Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) + instanceId String @unique +} + +model Template { + id String @id @default(cuid()) + templateId String @unique @db.VarChar(255) + name String @unique @db.VarChar(255) + template Json @db.Json + webhookUrl String? @db.VarChar(500) + createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp + updatedAt DateTime @updatedAt @db.Timestamp + Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) + instanceId String +} + +model Dify { + id String @id @default(cuid()) + enabled Boolean @default(true) + description String? @db.VarChar(255) + botType DifyBotType + apiUrl String? @db.VarChar(255) + apiKey String? @db.VarChar(255) + expire Int? @default(0) @db.Int + keywordFinish String? @db.VarChar(100) + delayMessage Int? @db.Int + unknownMessage String? @db.VarChar(100) + listeningFromMe Boolean? @default(false) + stopBotFromMe Boolean? @default(false) + keepOpen Boolean? @default(false) + debounceTime Int? @db.Int + ignoreJids Json? + triggerType TriggerType? + triggerOperator TriggerOperator? + triggerValue String? + createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp + updatedAt DateTime @updatedAt @db.Timestamp + Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) + instanceId String + DifySession DifySession[] + DifySetting DifySetting[] +} + +model DifySession { + id String @id @default(cuid()) + sessionId String @db.VarChar(255) + remoteJid String @db.VarChar(100) + status TypebotSessionStatus + awaitUser Boolean @default(false) + createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp + updatedAt DateTime @updatedAt @db.Timestamp + Dify Dify @relation(fields: [difyId], references: [id], onDelete: Cascade) + difyId String + Message Message[] + Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) + instanceId String +} + +model DifySetting { id String @id @default(cuid()) expire Int? @default(0) @db.Int keywordFinish String? @db.VarChar(100) @@ -303,8 +502,12 @@ model TypebotSetting { listeningFromMe Boolean? @default(false) stopBotFromMe Boolean? @default(false) keepOpen Boolean? @default(false) - createdAt DateTime? @default(now()) @db.Date - updatedAt DateTime @updatedAt @db.Date + debounceTime Int? @db.Int + ignoreJids Json? + createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp + updatedAt DateTime @updatedAt @db.Timestamp + Fallback Dify? @relation(fields: [difyIdFallback], references: [id]) + difyIdFallback String? @db.VarChar(100) Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique } diff --git a/prisma/migrations/20240609181238_init/migration.sql b/prisma/postgresql-migrations/20240609181238_init/migration.sql similarity index 100% rename from prisma/migrations/20240609181238_init/migration.sql rename to prisma/postgresql-migrations/20240609181238_init/migration.sql diff --git a/prisma/migrations/20240610144159_create_column_profile_name_instance/migration.sql b/prisma/postgresql-migrations/20240610144159_create_column_profile_name_instance/migration.sql similarity index 100% rename from prisma/migrations/20240610144159_create_column_profile_name_instance/migration.sql rename to prisma/postgresql-migrations/20240610144159_create_column_profile_name_instance/migration.sql diff --git a/prisma/migrations/20240611125754_create_columns_whitelabel_chatwoot/migration.sql b/prisma/postgresql-migrations/20240611125754_create_columns_whitelabel_chatwoot/migration.sql similarity index 100% rename from prisma/migrations/20240611125754_create_columns_whitelabel_chatwoot/migration.sql rename to prisma/postgresql-migrations/20240611125754_create_columns_whitelabel_chatwoot/migration.sql diff --git a/prisma/migrations/20240611202817_create_columns_debounce_time_typebot/migration.sql b/prisma/postgresql-migrations/20240611202817_create_columns_debounce_time_typebot/migration.sql similarity index 100% rename from prisma/migrations/20240611202817_create_columns_debounce_time_typebot/migration.sql rename to prisma/postgresql-migrations/20240611202817_create_columns_debounce_time_typebot/migration.sql diff --git a/prisma/migrations/20240712144948_add_business_id_column_to_instances/migration.sql b/prisma/postgresql-migrations/20240712144948_add_business_id_column_to_instances/migration.sql similarity index 100% rename from prisma/migrations/20240712144948_add_business_id_column_to_instances/migration.sql rename to prisma/postgresql-migrations/20240712144948_add_business_id_column_to_instances/migration.sql diff --git a/prisma/migrations/20240712150256_create_templates_table/migration.sql b/prisma/postgresql-migrations/20240712150256_create_templates_table/migration.sql similarity index 100% rename from prisma/migrations/20240712150256_create_templates_table/migration.sql rename to prisma/postgresql-migrations/20240712150256_create_templates_table/migration.sql diff --git a/prisma/migrations/20240712155950_adjusts_in_templates_table/migration.sql b/prisma/postgresql-migrations/20240712155950_adjusts_in_templates_table/migration.sql similarity index 100% rename from prisma/migrations/20240712155950_adjusts_in_templates_table/migration.sql rename to prisma/postgresql-migrations/20240712155950_adjusts_in_templates_table/migration.sql diff --git a/prisma/migrations/20240712162206_remove_templates_table/migration.sql b/prisma/postgresql-migrations/20240712162206_remove_templates_table/migration.sql similarity index 100% rename from prisma/migrations/20240712162206_remove_templates_table/migration.sql rename to prisma/postgresql-migrations/20240712162206_remove_templates_table/migration.sql diff --git a/prisma/migrations/20240712223655_column_fallback_typebot/migration.sql b/prisma/postgresql-migrations/20240712223655_column_fallback_typebot/migration.sql similarity index 100% rename from prisma/migrations/20240712223655_column_fallback_typebot/migration.sql rename to prisma/postgresql-migrations/20240712223655_column_fallback_typebot/migration.sql diff --git a/prisma/migrations/20240712230631_column_ignore_jids_typebot/migration.sql b/prisma/postgresql-migrations/20240712230631_column_ignore_jids_typebot/migration.sql similarity index 100% rename from prisma/migrations/20240712230631_column_ignore_jids_typebot/migration.sql rename to prisma/postgresql-migrations/20240712230631_column_ignore_jids_typebot/migration.sql diff --git a/prisma/migrations/20240713184337_add_media_table/migration.sql b/prisma/postgresql-migrations/20240713184337_add_media_table/migration.sql similarity index 100% rename from prisma/migrations/20240713184337_add_media_table/migration.sql rename to prisma/postgresql-migrations/20240713184337_add_media_table/migration.sql diff --git a/prisma/migrations/20240718121437_add_openai_tables/migration.sql b/prisma/postgresql-migrations/20240718121437_add_openai_tables/migration.sql similarity index 100% rename from prisma/migrations/20240718121437_add_openai_tables/migration.sql rename to prisma/postgresql-migrations/20240718121437_add_openai_tables/migration.sql diff --git a/prisma/migrations/20240718123923_adjusts_openai_tables/migration.sql b/prisma/postgresql-migrations/20240718123923_adjusts_openai_tables/migration.sql similarity index 100% rename from prisma/migrations/20240718123923_adjusts_openai_tables/migration.sql rename to prisma/postgresql-migrations/20240718123923_adjusts_openai_tables/migration.sql diff --git a/prisma/migrations/20240722173259_add_name_column_to_openai_creds/migration.sql b/prisma/postgresql-migrations/20240722173259_add_name_column_to_openai_creds/migration.sql similarity index 100% rename from prisma/migrations/20240722173259_add_name_column_to_openai_creds/migration.sql rename to prisma/postgresql-migrations/20240722173259_add_name_column_to_openai_creds/migration.sql diff --git a/prisma/migrations/20240722173518_add_name_column_to_openai_creds/migration.sql b/prisma/postgresql-migrations/20240722173518_add_name_column_to_openai_creds/migration.sql similarity index 100% rename from prisma/migrations/20240722173518_add_name_column_to_openai_creds/migration.sql rename to prisma/postgresql-migrations/20240722173518_add_name_column_to_openai_creds/migration.sql diff --git a/prisma/migrations/20240723152648_adjusts_in_column_openai_creds/migration.sql b/prisma/postgresql-migrations/20240723152648_adjusts_in_column_openai_creds/migration.sql similarity index 100% rename from prisma/migrations/20240723152648_adjusts_in_column_openai_creds/migration.sql rename to prisma/postgresql-migrations/20240723152648_adjusts_in_column_openai_creds/migration.sql diff --git a/prisma/migrations/20240723200254_add_webhookurl_on_message/migration.sql b/prisma/postgresql-migrations/20240723200254_add_webhookurl_on_message/migration.sql similarity index 100% rename from prisma/migrations/20240723200254_add_webhookurl_on_message/migration.sql rename to prisma/postgresql-migrations/20240723200254_add_webhookurl_on_message/migration.sql diff --git a/prisma/migrations/20240725184147_create_template_table/migration.sql b/prisma/postgresql-migrations/20240725184147_create_template_table/migration.sql similarity index 100% rename from prisma/migrations/20240725184147_create_template_table/migration.sql rename to prisma/postgresql-migrations/20240725184147_create_template_table/migration.sql diff --git a/prisma/migrations/20240725202651_add_webhook_url_template_table/migration.sql b/prisma/postgresql-migrations/20240725202651_add_webhook_url_template_table/migration.sql similarity index 100% rename from prisma/migrations/20240725202651_add_webhook_url_template_table/migration.sql rename to prisma/postgresql-migrations/20240725202651_add_webhook_url_template_table/migration.sql diff --git a/prisma/migrations/20240725221646_modify_token_instance_table/migration.sql b/prisma/postgresql-migrations/20240725221646_modify_token_instance_table/migration.sql similarity index 100% rename from prisma/migrations/20240725221646_modify_token_instance_table/migration.sql rename to prisma/postgresql-migrations/20240725221646_modify_token_instance_table/migration.sql diff --git a/prisma/migrations/20240729115127_modify_trigger_type_openai_typebot_table/migration.sql b/prisma/postgresql-migrations/20240729115127_modify_trigger_type_openai_typebot_table/migration.sql similarity index 100% rename from prisma/migrations/20240729115127_modify_trigger_type_openai_typebot_table/migration.sql rename to prisma/postgresql-migrations/20240729115127_modify_trigger_type_openai_typebot_table/migration.sql diff --git a/prisma/migrations/20240729180347_modify_typebot_session_status_openai_typebot_table/migration.sql b/prisma/postgresql-migrations/20240729180347_modify_typebot_session_status_openai_typebot_table/migration.sql similarity index 100% rename from prisma/migrations/20240729180347_modify_typebot_session_status_openai_typebot_table/migration.sql rename to prisma/postgresql-migrations/20240729180347_modify_typebot_session_status_openai_typebot_table/migration.sql diff --git a/prisma/migrations/20240730152156_create_dify_tables/migration.sql b/prisma/postgresql-migrations/20240730152156_create_dify_tables/migration.sql similarity index 100% rename from prisma/migrations/20240730152156_create_dify_tables/migration.sql rename to prisma/postgresql-migrations/20240730152156_create_dify_tables/migration.sql diff --git a/prisma/migrations/20240801193907_add_column_speech_to_text_openai_setting_table/migration.sql b/prisma/postgresql-migrations/20240801193907_add_column_speech_to_text_openai_setting_table/migration.sql similarity index 100% rename from prisma/migrations/20240801193907_add_column_speech_to_text_openai_setting_table/migration.sql rename to prisma/postgresql-migrations/20240801193907_add_column_speech_to_text_openai_setting_table/migration.sql diff --git a/prisma/migrations/20240803163908_add_column_description_on_integrations_table/migration.sql b/prisma/postgresql-migrations/20240803163908_add_column_description_on_integrations_table/migration.sql similarity index 100% rename from prisma/migrations/20240803163908_add_column_description_on_integrations_table/migration.sql rename to prisma/postgresql-migrations/20240803163908_add_column_description_on_integrations_table/migration.sql diff --git a/prisma/migrations/20240808210239_add_column_function_url_openaibot_table/migration.sql b/prisma/postgresql-migrations/20240808210239_add_column_function_url_openaibot_table/migration.sql similarity index 100% rename from prisma/migrations/20240808210239_add_column_function_url_openaibot_table/migration.sql rename to prisma/postgresql-migrations/20240808210239_add_column_function_url_openaibot_table/migration.sql diff --git a/prisma/migrations/migration_lock.toml b/prisma/postgresql-migrations/migration_lock.toml similarity index 100% rename from prisma/migrations/migration_lock.toml rename to prisma/postgresql-migrations/migration_lock.toml