Skip to content

Commit 2fb6318

Browse files
committed
feat: updates api evolution for docker
1 parent 1665654 commit 2fb6318

File tree

6 files changed

+45
-20
lines changed

6 files changed

+45
-20
lines changed

.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
.git
22
*Dockerfile*
33
*docker-compose*
4+
package-lock.json
5+
.env
46
node_modules
57
dist

Docker/scripts/deploy_database.sh

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,44 @@
11
#!/bin/bash
22

3+
# Fonte das variáveis de ambiente
34
source ./Docker/scripts/env_functions.sh
45

6+
# Carregar variáveis de ambiente se não estiver no ambiente Docker
57
if [ "$DOCKER_ENV" != "true" ]; then
68
export_env_vars
79
fi
810

11+
# Verificar se o banco de dados é PostgreSQL ou MySQL
912
if [[ "$DATABASE_PROVIDER" == "postgresql" || "$DATABASE_PROVIDER" == "mysql" ]]; then
1013
export DATABASE_URL
1114
echo "Deploying migrations for $DATABASE_PROVIDER"
1215
echo "Database URL: $DATABASE_URL"
13-
# rm -rf ./prisma/migrations
14-
# cp -r ./prisma/$DATABASE_PROVIDER-migrations ./prisma/migrations
15-
npm run db:deploy
16-
if [ $? -ne 0 ]; then
17-
echo "Migration failed"
18-
exit 1
16+
17+
# Verificar se há migrações pendentes com Prisma
18+
MIGRATION_STATUS=$(npx prisma migrate status)
19+
20+
if echo "$MIGRATION_STATUS" | grep -q "Pending"; then
21+
echo "Migrações pendentes encontradas. Executando deploy..."
22+
npm run db:deploy # Aplica as migrações pendentes
23+
if [ $? -ne 0 ]; then
24+
echo "Migration failed"
25+
exit 1
26+
else
27+
echo "Migration succeeded"
28+
fi
1929
else
20-
echo "Migration succeeded"
30+
echo "Nenhuma migração pendente. Pulando deploy."
2131
fi
32+
33+
# Gerar o Prisma Client após o deploy
2234
npm run db:generate
2335
if [ $? -ne 0 ]; then
2436
echo "Prisma generate failed"
2537
exit 1
2638
else
2739
echo "Prisma generate succeeded"
2840
fi
41+
2942
else
3043
echo "Error: Database provider $DATABASE_PROVIDER invalid."
3144
exit 1

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
FROM node:20-alpine AS builder
22

33
RUN apk update && \
4-
apk add git ffmpeg wget curl bash
4+
apk add --no-cache git ffmpeg wget curl bash openssl
55

66
LABEL version="2.2.0" description="Api to control whatsapp features through http requests."
77
LABEL maintainer="Davidson Gomes" git="https://github.com/DavidsonGomes"

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
"db:generate": "node runWithProvider.js \"npx prisma generate --schema ./prisma/DATABASE_PROVIDER-schema.prisma\"",
1515
"db:deploy": "node runWithProvider.js \"rm -rf ./prisma/migrations && cp -r ./prisma/DATABASE_PROVIDER-migrations ./prisma/migrations && npx prisma migrate deploy --schema ./prisma/DATABASE_PROVIDER-schema.prisma\"",
1616
"db:studio": "node runWithProvider.js \"npx prisma studio --schema ./prisma/DATABASE_PROVIDER-schema.prisma\"",
17-
"db:migrate:dev": "node runWithProvider.js \"rm -rf ./prisma/migrations && cp -r ./prisma/DATABASE_PROVIDER-migrations ./prisma/migrations && npx prisma migrate dev --schema ./prisma/DATABASE_PROVIDER-schema.prisma && cp -r ./prisma/migrations/* ./prisma/DATABASE_PROVIDER-migrations\""
17+
"db:migrate:dev": "node runWithProvider.js \"rm -rf ./prisma/migrations && cp -r ./prisma/DATABASE_PROVIDER-migrations ./prisma/migrations && npx prisma migrate dev --schema ./prisma/DATABASE_PROVIDER-schema.prisma && cp -r ./prisma/migrations/* ./prisma/DATABASE_PROVIDER-migrations\"",
18+
"docker:build": "docker build -t joaovictorsouza/evolution-api:latest .",
19+
"docker:push": "docker push joaovictorsouza/evolution-api:latest"
1820
},
1921
"repository": {
2022
"type": "git",
@@ -51,7 +53,7 @@
5153
"@ffmpeg-installer/ffmpeg": "^1.1.0",
5254
"@figuro/chatwoot-sdk": "^1.1.16",
5355
"@hapi/boom": "^10.0.1",
54-
"@prisma/client": "^5.15.0",
56+
"@prisma/client": "^6.1.0",
5557
"@sentry/node": "^8.28.0",
5658
"amqplib": "^0.10.3",
5759
"axios": "^1.6.5",
@@ -82,7 +84,7 @@
8284
"openai": "^4.52.7",
8385
"pg": "^8.11.3",
8486
"pino": "^8.11.0",
85-
"prisma": "^5.15.0",
87+
"prisma": "^6.1.0",
8688
"pusher": "^5.2.0",
8789
"qrcode": "^1.5.1",
8890
"qrcode-terminal": "^0.12.0",

src/api/services/monitor.service.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,15 @@ export class WAMonitoringService {
7272

7373
const clientName = this.configService.get<Database>('DATABASE').CONNECTION.CLIENT_NAME;
7474

75-
const where = instanceNames && instanceNames.length > 0
76-
? {
77-
name: {
78-
in: instanceNames,
79-
},
80-
clientName,
81-
}
82-
: { clientName };
75+
const where =
76+
instanceNames && instanceNames.length > 0
77+
? {
78+
name: {
79+
in: instanceNames,
80+
},
81+
clientName,
82+
}
83+
: { clientName };
8384

8485
const instances = await this.prismaRepository.instance.findMany({
8586
where,

src/api/types/wa.types.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,14 @@ export declare namespace wa {
131131
export type StatusMessage = 'ERROR' | 'PENDING' | 'SERVER_ACK' | 'DELIVERY_ACK' | 'READ' | 'DELETED' | 'PLAYED';
132132
}
133133

134-
export const TypeMediaMessage = ['imageMessage', 'documentMessage', 'audioMessage', 'videoMessage', 'stickerMessage', 'ptvMessage'];
134+
export const TypeMediaMessage = [
135+
'imageMessage',
136+
'documentMessage',
137+
'audioMessage',
138+
'videoMessage',
139+
'stickerMessage',
140+
'ptvMessage',
141+
];
135142

136143
export const MessageSubtype = [
137144
'ephemeralMessage',

0 commit comments

Comments
 (0)