Update environment configuration for PostgreSQL: Add new environment variables for NextAuth and PostgreSQL settings in .env file, update docker-compose.yml to utilize these variables, and enhance README documentation for environment setup. Ensure DATABASE_URL is constructed dynamically if not defined.
This commit is contained in:
@@ -7,8 +7,35 @@ import { PrismaPg } from "@prisma/adapter-pg";
|
||||
import { Pool } from "pg";
|
||||
import bcrypt from "bcryptjs";
|
||||
|
||||
// Construire DATABASE_URL si elle n'est pas définie (même logique que lib/prisma.ts)
|
||||
let databaseUrl = process.env.DATABASE_URL;
|
||||
|
||||
if (!databaseUrl) {
|
||||
const user = process.env.POSTGRES_USER || "gotgaming";
|
||||
const password = process.env.POSTGRES_PASSWORD || "change-this-in-production";
|
||||
// Si on est dans Docker, utiliser le nom du service, sinon localhost avec le port externe
|
||||
const host =
|
||||
process.env.POSTGRES_HOST ||
|
||||
(process.env.DOCKER_ENV ? "got-postgres" : "localhost");
|
||||
const port =
|
||||
process.env.POSTGRES_PORT || (process.env.DOCKER_ENV ? "5432" : "5433");
|
||||
const db = process.env.POSTGRES_DB || "gotgaming";
|
||||
|
||||
// Encoder le mot de passe pour l'URL
|
||||
const encodedPassword = encodeURIComponent(password);
|
||||
databaseUrl = `postgresql://${user}:${encodedPassword}@${host}:${port}/${db}?schema=public`;
|
||||
}
|
||||
|
||||
if (typeof databaseUrl !== "string") {
|
||||
throw new Error("DATABASE_URL must be a string");
|
||||
}
|
||||
|
||||
// Logger l'URL de connexion (masquer le mot de passe pour la sécurité)
|
||||
const logUrl = databaseUrl.replace(/:\/\/[^:]+:[^@]+@/, "://***:***@");
|
||||
console.log(`[Seed] Connecting to PostgreSQL: ${logUrl}`);
|
||||
|
||||
const pool = new Pool({
|
||||
connectionString: process.env.DATABASE_URL,
|
||||
connectionString: databaseUrl,
|
||||
});
|
||||
|
||||
const adapter = new PrismaPg(pool);
|
||||
|
||||
Reference in New Issue
Block a user