|
| 1 | +// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ |
| 2 | +// β @author jrCleber β |
| 3 | +// β @filename message.model.ts β |
| 4 | +// β Developed by: Cleber Wilson β |
| 5 | +// β Creation date: Dez 02, 2023 β |
| 6 | +// β Contact: contato@codechat.dev β |
| 7 | +// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€ |
| 8 | +// β @copyright Β© Cleber Wilson 2022. All rights reserved. β |
| 9 | +// β Licensed under the Apache License, Version 2.0 β |
| 10 | +// β β |
| 11 | +// β @license "https://github.com/code-chat-br/whatsapp-api/blob/main/LICENSE" β |
| 12 | +// β β |
| 13 | +// β You may not use this file except in compliance with the License. β |
| 14 | +// β You may obtain a copy of the License at β |
| 15 | +// β β |
| 16 | +// β http://www.apache.org/licenses/LICENSE-2.0 β |
| 17 | +// β β |
| 18 | +// β Unless required by applicable law or agreed to in writing, software β |
| 19 | +// β distributed under the License is distributed on an "AS IS" BASIS, β |
| 20 | +// β WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. β |
| 21 | +// β β |
| 22 | +// β See the License for the specific language governing permissions and β |
| 23 | +// β limitations under the License. β |
| 24 | +// β β β |
| 25 | +// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€ |
| 26 | +// β @important β |
| 27 | +// β For any future changes to the code in this file, it is recommended to β |
| 28 | +// β contain, together with the modification, the information of the developer β |
| 29 | +// β who changed it and the date of modification. β |
| 30 | +// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ |
| 31 | + |
| 32 | +// This is your Prisma schema file, |
| 33 | +// learn more about it in the docs: https://pris.ly/d/prisma-schema |
| 34 | + |
| 35 | +generator client { |
| 36 | + provider = "prisma-client-js" |
| 37 | +} |
| 38 | + |
| 39 | +datasource db { |
| 40 | + provider = "postgresql" |
| 41 | + url = env("DATABASE_URL") |
| 42 | +} |
| 43 | + |
| 44 | +enum InstanceConnectionStatus { |
| 45 | + ONLINE |
| 46 | + OFFLINE |
| 47 | +} |
| 48 | + |
| 49 | +model Instance { |
| 50 | + id Int @id @default(autoincrement()) |
| 51 | + name String @unique @db.VarChar(255) |
| 52 | + description String? @db.VarChar(255) |
| 53 | + connectionStatus InstanceConnectionStatus? @default(OFFLINE) |
| 54 | + ownerJid String? @unique @db.VarChar(100) |
| 55 | + profilePicUrl String? @db.VarChar(500) |
| 56 | + createdAt DateTime? @default(now()) @db.Date |
| 57 | + updatedAt DateTime? @updatedAt @db.Date |
| 58 | + Auth Auth? |
| 59 | + Chat Chat[] |
| 60 | + Contact Contact[] |
| 61 | + Webhook Webhook? |
| 62 | + Typebot Typebot? |
| 63 | + ActivityLogs ActivityLogs[] |
| 64 | + Message Message[] |
| 65 | +} |
| 66 | + |
| 67 | +model Auth { |
| 68 | + id Int @id @default(autoincrement()) |
| 69 | + token String @unique |
| 70 | + createdAt DateTime? @default(now()) @db.Date |
| 71 | + updatedAt DateTime? @updatedAt @db.Date |
| 72 | + Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) |
| 73 | + instanceId Int @unique @db.Integer |
| 74 | +} |
| 75 | + |
| 76 | +enum MessageSource { |
| 77 | + ios |
| 78 | + android |
| 79 | + web |
| 80 | +} |
| 81 | + |
| 82 | +enum DeviceMessage { |
| 83 | + ios |
| 84 | + android |
| 85 | + web |
| 86 | +} |
| 87 | + |
| 88 | +model Message { |
| 89 | + id Int @id @default(autoincrement()) |
| 90 | + keyId String @db.VarChar(100) |
| 91 | + keyRemoteJid String @db.VarChar(100) |
| 92 | + keyFromMe Boolean @db.Boolean |
| 93 | + keyParticipant String? @db.VarChar(100) |
| 94 | + pushName String? @db.VarChar(100) |
| 95 | + messageType String @db.VarChar(100) |
| 96 | + content Json @db.JsonB |
| 97 | + messageTimestamp Int @db.Integer |
| 98 | + device DeviceMessage |
| 99 | + isGroup Boolean? @db.Boolean |
| 100 | + Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) |
| 101 | + instanceId Int |
| 102 | + TypebotSession TypebotSession? @relation(fields: [typebotSessionId], references: [id], onDelete: Cascade) |
| 103 | + typebotSessionId Int? |
| 104 | + MessageUpdate MessageUpdate[] |
| 105 | + Media Media? |
| 106 | +
|
| 107 | + @@index([keyId], name: "keyId") |
| 108 | +} |
| 109 | + |
| 110 | +model Media { |
| 111 | + id Int @id @default(autoincrement()) |
| 112 | + fileName String @unique @db.VarChar(500) |
| 113 | + type String @db.VarChar(100) |
| 114 | + mimetype String @db.VarChar(100) |
| 115 | + createdAt DateTime? @default(now()) @db.Date |
| 116 | + Message Message @relation(fields: [messageId], references: [id], onDelete: Cascade) |
| 117 | + messageId Int @unique |
| 118 | +} |
| 119 | + |
| 120 | +model MessageUpdate { |
| 121 | + id Int @id @default(autoincrement()) |
| 122 | + dateTime DateTime @db.Date |
| 123 | + status String @db.VarChar(30) |
| 124 | + Message Message @relation(fields: [messageId], references: [id], onDelete: Cascade) |
| 125 | + messageId Int |
| 126 | +} |
| 127 | + |
| 128 | +model Chat { |
| 129 | + id Int @id @default(autoincrement()) |
| 130 | + remoteJid String @db.VarChar(100) |
| 131 | + createdAt DateTime? @default(now()) @db.Date |
| 132 | + updatedAt DateTime? @updatedAt @db.Date |
| 133 | + Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) |
| 134 | + instanceId Int |
| 135 | +} |
| 136 | + |
| 137 | +model Contact { |
| 138 | + id Int @id @default(autoincrement()) |
| 139 | + remoteJid String @db.VarChar(100) |
| 140 | + pushName String? @db.VarChar(100) |
| 141 | + profilePicUrl String? @db.VarChar(500) |
| 142 | + createdAt DateTime? @default(now()) @db.Date |
| 143 | + updatedAt DateTime? @updatedAt @db.Date |
| 144 | + Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) |
| 145 | + instanceId Int |
| 146 | +} |
| 147 | + |
| 148 | +model Webhook { |
| 149 | + id Int @id @default(autoincrement()) |
| 150 | + url String @db.VarChar(500) |
| 151 | + enabled Boolean? @default(true) @db.Boolean |
| 152 | + events Json? @db.JsonB |
| 153 | + createdAt DateTime? @default(now()) @db.Date |
| 154 | + updatedAt DateTime @updatedAt @db.Date |
| 155 | + Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) |
| 156 | + instanceId Int @unique |
| 157 | +} |
| 158 | + |
| 159 | +model Typebot { |
| 160 | + id Int @id @default(autoincrement()) |
| 161 | + publicId String @db.VarChar(200) |
| 162 | + typebotUrl String @db.VarChar(500) |
| 163 | + enabled Boolean? @default(true) @db.Boolean |
| 164 | + enableGroup Boolean? @default(false) @db.Boolean |
| 165 | + createdAt DateTime? @default(now()) @db.Date |
| 166 | + updatedAt DateTime? @updatedAt @db.Date |
| 167 | + Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) |
| 168 | + instanceId Int @unique |
| 169 | + TypebotSession TypebotSession[] |
| 170 | +} |
| 171 | + |
| 172 | +enum TypebotSessionStatus { |
| 173 | + open |
| 174 | + closed |
| 175 | + paused |
| 176 | +} |
| 177 | + |
| 178 | +model TypebotSession { |
| 179 | + id Int @id @default(autoincrement()) |
| 180 | + sessionId String @unique @db.VarChar(200) |
| 181 | + remoteJid String @db.VarChar(100) |
| 182 | + status TypebotSessionStatus @default(open) |
| 183 | + Typebot Typebot @relation(fields: [typebotId], references: [id], onDelete: Cascade) |
| 184 | + typebotId Int |
| 185 | + Message Message[] |
| 186 | +} |
| 187 | + |
| 188 | +enum StartConversationAs { |
| 189 | + open |
| 190 | + pending |
| 191 | +} |
| 192 | + |
| 193 | +model ActivityLogs { |
| 194 | + id Int @id @default(autoincrement()) |
| 195 | + dateTime DateTime? @default(now()) @db.Date |
| 196 | + context String? @db.VarChar(100) |
| 197 | + type String? @db.VarChar(100) |
| 198 | + content Json? @db.JsonB |
| 199 | + description String? @db.VarChar(500) |
| 200 | + Instance Instance? @relation(fields: [instanceId], references: [id], onDelete: Cascade) |
| 201 | + instanceId Int? @db.Integer |
| 202 | +} |
0 commit comments