feat: add Next.js configuration and automated super admin initialization scripts
This commit is contained in:
@@ -3,7 +3,10 @@ const bcrypt = require('bcryptjs');
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
async function waitForDatabase(prismaClient, maxRetries = 30, delayMs = 2000) {
|
||||
const MAX_RETRIES = parseInt(process.env.DB_WAIT_MAX_RETRIES || '90', 10);
|
||||
const DELAY_MS = parseInt(process.env.DB_WAIT_DELAY_MS || '2000', 10);
|
||||
|
||||
async function waitForDatabase(prismaClient, maxRetries = MAX_RETRIES, delayMs = DELAY_MS) {
|
||||
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
||||
try {
|
||||
await prismaClient.$executeRawUnsafe('SELECT 1;');
|
||||
@@ -12,11 +15,19 @@ async function waitForDatabase(prismaClient, maxRetries = 30, delayMs = 2000) {
|
||||
} catch (err) {
|
||||
const msg = err.message || '';
|
||||
const isStartingUp = msg.includes('the database system is starting up') ||
|
||||
msg.includes('57P03') ||
|
||||
msg.includes('ConnectionRefused') ||
|
||||
msg.includes("Can't reach database server");
|
||||
msg.includes('57P03');
|
||||
const isUnreachable = msg.includes('ConnectionRefused') ||
|
||||
msg.includes("Can't reach database server") ||
|
||||
msg.includes('connection refused') ||
|
||||
msg.includes('P1001');
|
||||
|
||||
let info = msg.split('\n')[0].substring(0, 80);
|
||||
if (isStartingUp) {
|
||||
info = 'PostgreSQL est en cours de démarrage (recovery/init)...';
|
||||
} else if (isUnreachable) {
|
||||
info = 'PostgreSQL pas encore joignable (démarrage du conteneur en cours)...';
|
||||
}
|
||||
|
||||
const info = isStartingUp ? 'PostgreSQL est en cours de démarrage...' : msg.split('\n')[0].substring(0, 80);
|
||||
console.log(`⏳ En attente de la base de données (${attempt}/${maxRetries}) : ${info}`);
|
||||
|
||||
if (attempt === maxRetries) {
|
||||
|
||||
Reference in New Issue
Block a user