mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-13 15:14:49 -06:00
prisma orm: mysql
This commit is contained in:
parent
52c1394ce2
commit
da687041af
100
README.md
100
README.md
@ -21,6 +21,106 @@ The code allows the creation of multiservice chats, service bots, or any other s
|
||||
|
||||
The Evolution API has direct integration with [Typebot](https://github.com/baptisteArno/typebot.io) and [Chatwoot](https://github.com/chatwoot/chatwoot)
|
||||
|
||||
# Instalation
|
||||
|
||||
### Installing NVM (Node Version Manager)
|
||||
|
||||
NVM allows you to install and manage multiple versions of Node.js. This is particularly useful for maintaining compatibility across different projects.
|
||||
|
||||
```sh
|
||||
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
|
||||
|
||||
source ~/.bashrc
|
||||
|
||||
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
|
||||
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
|
||||
```
|
||||
|
||||
### Installing Node.js
|
||||
|
||||
```sh
|
||||
nvm install v20.10.0 && nvm use v20.10.0
|
||||
```
|
||||
|
||||
### Initializing the Application
|
||||
|
||||
Clone the repository:
|
||||
|
||||
```sh
|
||||
git clone https://github.com/EvolutionAPI/evolution-api.git
|
||||
```
|
||||
Configure the environment variables in the [.env](./.env.example) file.
|
||||
|
||||
### Installing Application Dependencies
|
||||
|
||||
```sh
|
||||
cd evolution-api
|
||||
|
||||
npm install
|
||||
|
||||
npm run build
|
||||
```
|
||||
|
||||
### Env
|
||||
> OBS: Rename the [.env.example](./.env.example) file to **.env**
|
||||
```sh
|
||||
cp .env.example .env
|
||||
```
|
||||
### Database Setup
|
||||
|
||||
The application supports PostgreSQL, MySQL, MariaDB.
|
||||
|
||||
Run one of the commands below for the non-existence of a database.
|
||||
|
||||
- **MySQL or MariaDB**:
|
||||
|
||||
```sh
|
||||
# Set the environment variable DATABASE_PROVIDER=mysql
|
||||
npx prisma migrate dev --name init --schema ./prisma/mysql-schema.prisma
|
||||
```
|
||||
|
||||
- **PostgreSQL**:
|
||||
```sh
|
||||
# Set the environment variable DATABASE_PROVIDER=postgressql
|
||||
npx prisma migrate dev --name init --schema ./prisma/postgresql-schema.prisma
|
||||
```
|
||||
|
||||
#### Deploying
|
||||
|
||||
> For production environments.
|
||||
|
||||
For existing relational databases such as PostgreSQL, MySQL, or MariaDB, the setup involves two essential steps:
|
||||
|
||||
1. **Setting the Environment Variable**: Initially, it's imperative to define the `DATABASE_PROVIDER` environment variable in alignment with your relational database type. Use `postgressql` for PostgreSQL, and `mysql` for MySQL or MariaDB. This configuration is crucial as it directs the Prisma ORM regarding the specific relational database in use.
|
||||
|
||||
2. **Deploying Schema Changes**: Following this, execute the `npx prisma migrate deploy --schema ./prisma/postgressql-schema.prisma` command. This command serves as a shortcut for the `prisma deploy` command, whose main role is to examine the current schema of the relational database and implement necessary modifications. A key feature of this command is its ability to update the database schema without affecting the existing data. This ensures that your current data remains intact while the database schema is updated to meet the latest requirements of the application.
|
||||
|
||||
#### Prisma Studio
|
||||
|
||||
- **View your data**
|
||||
```sh
|
||||
npx prisma studio --schema ./prisma/mysql-schema.prisma
|
||||
# or
|
||||
npx prisma studio --schema ./prisma/postgresql-schema.prisma
|
||||
```
|
||||
|
||||
This will sync your data models to your database, creating tables as needed.
|
||||
|
||||
### Running the Application
|
||||
|
||||
- **Development Mode**:
|
||||
|
||||
```sh
|
||||
npm run dev:server
|
||||
```
|
||||
|
||||
- **Production Mode**:
|
||||
|
||||
```sh
|
||||
npm run build
|
||||
npm run start:prod
|
||||
```
|
||||
|
||||
# Note
|
||||
|
||||
This code is in no way affiliated with WhatsApp. Use at your own discretion. Don't spam this.
|
||||
|
268
prisma/mysql-schema.prisma
Normal file
268
prisma/mysql-schema.prisma
Normal file
@ -0,0 +1,268 @@
|
||||
// This is your Prisma schema file,
|
||||
// learn more about it in the docs: https://pris.ly/d/prisma-schema
|
||||
|
||||
// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
|
||||
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init
|
||||
|
||||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
}
|
||||
|
||||
datasource db {
|
||||
provider = "mysql"
|
||||
url = env("DATABASE_CONNECTION_URI")
|
||||
}
|
||||
|
||||
enum InstanceConnectionStatus {
|
||||
open
|
||||
close
|
||||
connecting
|
||||
}
|
||||
|
||||
enum DeviceMessage {
|
||||
ios
|
||||
android
|
||||
web
|
||||
unknown
|
||||
desktop
|
||||
}
|
||||
|
||||
enum TypebotSessionStatus {
|
||||
open
|
||||
closed
|
||||
paused
|
||||
}
|
||||
|
||||
model Instance {
|
||||
id String @id @default(cuid())
|
||||
name String @unique @db.VarChar(255)
|
||||
connectionStatus InstanceConnectionStatus @default(open)
|
||||
ownerJid String? @db.VarChar(100)
|
||||
profilePicUrl String? @db.VarChar(500)
|
||||
integration String? @db.VarChar(100)
|
||||
number String? @db.VarChar(100)
|
||||
token String? @unique @db.VarChar(255)
|
||||
createdAt DateTime? @default(now()) @db.Date
|
||||
updatedAt DateTime? @updatedAt @db.Date
|
||||
Chat Chat[]
|
||||
Contact Contact[]
|
||||
Message Message[]
|
||||
Webhook Webhook?
|
||||
Chatwoot Chatwoot?
|
||||
Label Label[]
|
||||
Proxy Proxy?
|
||||
Setting Setting?
|
||||
Rabbitmq Rabbitmq?
|
||||
Sqs Sqs?
|
||||
Websocket Websocket?
|
||||
Typebot Typebot?
|
||||
Session Session?
|
||||
MessageUpdate MessageUpdate[]
|
||||
TypebotSession TypebotSession[]
|
||||
}
|
||||
|
||||
model Session {
|
||||
id Int @id @unique @default(autoincrement())
|
||||
sessionId String @unique
|
||||
creds String? @db.Text
|
||||
createdAt DateTime @default(now())
|
||||
Instance Instance @relation(fields: [sessionId], references: [id], onDelete: Cascade)
|
||||
}
|
||||
|
||||
model Chat {
|
||||
id Int @id @default(autoincrement())
|
||||
remoteJid String @db.VarChar(100)
|
||||
lastMsgTimestamp String? @db.VarChar(100)
|
||||
labels Json? @db.Json
|
||||
createdAt DateTime? @default(now()) @db.Date
|
||||
updatedAt DateTime? @updatedAt @db.Date
|
||||
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
|
||||
instanceId String
|
||||
}
|
||||
|
||||
model Contact {
|
||||
id Int @id @default(autoincrement())
|
||||
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
|
||||
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
|
||||
instanceId String
|
||||
}
|
||||
|
||||
model Message {
|
||||
id Int @id @default(autoincrement())
|
||||
key Json @db.Json
|
||||
pushName String? @db.VarChar(100)
|
||||
participant String? @db.VarChar(100)
|
||||
messageType String @db.VarChar(100)
|
||||
message Json @db.Json
|
||||
contextInfo Json? @db.Json
|
||||
source DeviceMessage
|
||||
messageTimestamp String @db.VarChar(100)
|
||||
chatwootMessageId Int? @db.Int
|
||||
chatwootInboxId Int? @db.Int
|
||||
chatwootConversationId Int? @db.Int
|
||||
chatwootContactInboxSourceId String? @db.VarChar(100)
|
||||
chatwootIsRead Boolean?
|
||||
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
|
||||
instanceId String
|
||||
typebotSessionId Int?
|
||||
MessageUpdate MessageUpdate[]
|
||||
TypebotSession TypebotSession? @relation(fields: [typebotSessionId], references: [id])
|
||||
}
|
||||
|
||||
model MessageUpdate {
|
||||
id Int @id @default(autoincrement())
|
||||
keyId String @db.VarChar(100)
|
||||
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)
|
||||
messageId Int
|
||||
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
|
||||
instanceId String
|
||||
}
|
||||
|
||||
model Webhook {
|
||||
id Int @id @default(autoincrement())
|
||||
url String @db.VarChar(500)
|
||||
enabled Boolean? @default(false)
|
||||
events Json? @db.Json
|
||||
webhookByEvents Boolean? @default(false)
|
||||
webhookBase64 Boolean? @default(false)
|
||||
createdAt DateTime? @default(now()) @db.Date
|
||||
updatedAt DateTime @updatedAt @db.Date
|
||||
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
|
||||
instanceId String @unique
|
||||
}
|
||||
|
||||
model Chatwoot {
|
||||
id Int @id @default(autoincrement())
|
||||
enabled Boolean? @default(true)
|
||||
accountId String? @db.VarChar(100)
|
||||
token String? @db.VarChar(100)
|
||||
url String? @db.VarChar(500)
|
||||
nameInbox String? @db.VarChar(100)
|
||||
signMsg Boolean? @default(false)
|
||||
signDelimiter String? @db.VarChar(100)
|
||||
number String? @db.VarChar(100)
|
||||
reopenConversation Boolean? @default(false)
|
||||
conversationPending Boolean? @default(false)
|
||||
mergeBrazilContacts Boolean? @default(false)
|
||||
importContacts Boolean? @default(false)
|
||||
importMessages Boolean? @default(false)
|
||||
daysLimitImportMessages Int? @db.Int
|
||||
createdAt DateTime? @default(now()) @db.Date
|
||||
updatedAt DateTime @updatedAt @db.Date
|
||||
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
|
||||
instanceId String @unique
|
||||
}
|
||||
|
||||
model Label {
|
||||
id Int @id @default(autoincrement())
|
||||
labelId String? @unique @db.VarChar(100)
|
||||
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
|
||||
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
|
||||
instanceId String
|
||||
}
|
||||
|
||||
model Proxy {
|
||||
id Int @id @default(autoincrement())
|
||||
enabled Boolean @default(false)
|
||||
host String @db.VarChar(100)
|
||||
port String @db.VarChar(100)
|
||||
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
|
||||
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
|
||||
instanceId String @unique
|
||||
}
|
||||
|
||||
model Setting {
|
||||
id Int @id @default(autoincrement())
|
||||
rejectCall Boolean @default(false)
|
||||
msgCall String? @db.VarChar(100)
|
||||
groupsIgnore Boolean @default(false)
|
||||
alwaysOnline Boolean @default(false)
|
||||
readMessages Boolean @default(false)
|
||||
readStatus Boolean @default(false)
|
||||
syncFullHistory Boolean @default(false)
|
||||
createdAt DateTime? @default(now()) @db.Date
|
||||
updatedAt DateTime @updatedAt @db.Date
|
||||
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
|
||||
instanceId String @unique
|
||||
}
|
||||
|
||||
model Rabbitmq {
|
||||
id Int @id @default(autoincrement())
|
||||
enabled Boolean @default(false)
|
||||
events Json @db.Json
|
||||
createdAt DateTime? @default(now()) @db.Date
|
||||
updatedAt DateTime @updatedAt @db.Date
|
||||
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
|
||||
instanceId String @unique
|
||||
}
|
||||
|
||||
model Sqs {
|
||||
id Int @id @default(autoincrement())
|
||||
enabled Boolean @default(false)
|
||||
events Json @db.Json
|
||||
createdAt DateTime? @default(now()) @db.Date
|
||||
updatedAt DateTime @updatedAt @db.Date
|
||||
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
|
||||
instanceId String @unique
|
||||
}
|
||||
|
||||
model Websocket {
|
||||
id Int @id @default(autoincrement())
|
||||
enabled Boolean @default(false)
|
||||
events Json @db.Json
|
||||
createdAt DateTime? @default(now()) @db.Date
|
||||
updatedAt DateTime @updatedAt @db.Date
|
||||
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
|
||||
instanceId String @unique
|
||||
}
|
||||
|
||||
model Typebot {
|
||||
id Int @id @default(autoincrement())
|
||||
enabled Boolean @default(true)
|
||||
url String @db.VarChar(500)
|
||||
typebot String @db.VarChar(100)
|
||||
expire Int @default(0) @db.Int
|
||||
keywordFinish String? @db.VarChar(100)
|
||||
delayMessage Int? @db.Int
|
||||
unknownMessage String? @db.VarChar(100)
|
||||
listeningFromMe Boolean @default(false)
|
||||
createdAt DateTime? @default(now()) @db.Date
|
||||
updatedAt DateTime? @updatedAt @db.Date
|
||||
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
|
||||
instanceId String @unique
|
||||
sessions TypebotSession[]
|
||||
}
|
||||
|
||||
model TypebotSession {
|
||||
id Int @id @default(autoincrement())
|
||||
remoteJid String @db.VarChar(100)
|
||||
pushName String? @db.VarChar(100)
|
||||
sessionId String @db.VarChar(100)
|
||||
status String @db.VarChar(100)
|
||||
prefilledVariables Json? @db.Json
|
||||
createdAt DateTime? @default(now()) @db.Date
|
||||
updatedAt DateTime @updatedAt @db.Date
|
||||
Typebot Typebot @relation(fields: [typebotId], references: [id], onDelete: Cascade)
|
||||
typebotId Int @db.Int
|
||||
Message Message[]
|
||||
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
|
||||
instanceId String
|
||||
}
|
Loading…
Reference in New Issue
Block a user