mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-13 15:14:49 -06:00

- Add new psql_bouncer database provider option - Update database scripts to handle psql_bouncer provider - Comment out pgbouncer service in docker-compose - Simplify postgresql schema by removing directUrl - Add new psql_bouncer-schema.prisma file - Update .env.example with psql_bouncer configuration - Modify runWithProvider.js to handle psql_bouncer migrations
52 lines
1.6 KiB
JavaScript
52 lines
1.6 KiB
JavaScript
const dotenv = require('dotenv');
|
|
const { execSync } = require('child_process');
|
|
const { existsSync } = require('fs');
|
|
|
|
dotenv.config();
|
|
|
|
const { DATABASE_PROVIDER } = process.env;
|
|
const databaseProviderDefault = DATABASE_PROVIDER ?? 'postgresql';
|
|
|
|
if (!DATABASE_PROVIDER) {
|
|
console.warn(`DATABASE_PROVIDER is not set in the .env file, using default: ${databaseProviderDefault}`);
|
|
}
|
|
|
|
// Função para determinar qual pasta de migrations usar
|
|
// Função para determinar qual pasta de migrations usar
|
|
function getMigrationsFolder(provider) {
|
|
switch (provider) {
|
|
case 'psql_bouncer':
|
|
return 'postgresql-migrations'; // psql_bouncer usa as migrations do postgresql
|
|
default:
|
|
return `${provider}-migrations`;
|
|
}
|
|
}
|
|
|
|
const migrationsFolder = getMigrationsFolder(databaseProviderDefault);
|
|
|
|
let command = process.argv
|
|
.slice(2)
|
|
.join(' ')
|
|
.replace(/DATABASE_PROVIDER/g, databaseProviderDefault);
|
|
|
|
// Substituir referências à pasta de migrations pela pasta correta
|
|
const migrationsPattern = new RegExp(`${databaseProviderDefault}-migrations`, 'g');
|
|
command = command.replace(migrationsPattern, migrationsFolder);
|
|
|
|
if (command.includes('rmdir') && existsSync('prisma\\migrations')) {
|
|
try {
|
|
execSync('rmdir /S /Q prisma\\migrations', { stdio: 'inherit' });
|
|
} catch (error) {
|
|
console.error(`Error removing directory: prisma\\migrations`);
|
|
process.exit(1);
|
|
}
|
|
} else if (command.includes('rmdir')) {
|
|
console.warn(`Directory 'prisma\\migrations' does not exist, skipping removal.`);
|
|
}
|
|
|
|
try {
|
|
execSync(command, { stdio: 'inherit' });
|
|
} catch (error) {
|
|
console.error(`Error executing command: ${command}`);
|
|
process.exit(1);
|
|
} |