Compare commits
No commits in common. "ca9413e665cc1bd78214ee822592c887e5f058e5" and "f2ffdb64a861a83e63e565f483d366258c58235c" have entirely different histories.
ca9413e665
...
f2ffdb64a8
|
|
@ -9,5 +9,5 @@ DATABASE_URL="postgresql://kord:password@localhost:5432/kord_db?schema=public"
|
|||
# Logging (log4js — file only under LOG_DIR, no console appender)
|
||||
# Levels: trace, debug, info, warn, error, fatal
|
||||
LOG_LEVEL=info
|
||||
# Daily log files; keep 7 rotated days (see logger.ts). Directory is created at startup if missing.
|
||||
# Daily log files; keep 7 rotated days (see logger.ts)
|
||||
LOG_DIR=logs
|
||||
|
|
@ -1,36 +1,11 @@
|
|||
import type { PoolConfig } from 'pg';
|
||||
import { Pool } from 'pg';
|
||||
import { PrismaPg } from '@prisma/adapter-pg';
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import { env } from '../config/env';
|
||||
import { logger } from '../utils/logger';
|
||||
|
||||
/**
|
||||
* `?schema=` in DATABASE_URL is a Prisma URL extension. node-postgres does not apply it,
|
||||
* so connections default to `search_path=public`. PrismaPg also needs an explicit schema
|
||||
* option in some setups (see prisma/prisma#28611).
|
||||
*/
|
||||
function createPgPoolConfig(connectionString: string): { poolConfig: PoolConfig; prismaSchema?: string } {
|
||||
if (!connectionString) {
|
||||
return { poolConfig: { connectionString: '' } };
|
||||
}
|
||||
try {
|
||||
const url = new URL(connectionString);
|
||||
const schema = url.searchParams.get('schema')?.trim();
|
||||
const poolConfig: PoolConfig = { connectionString };
|
||||
if (schema) {
|
||||
const escaped = schema.replace(/"/g, '""');
|
||||
poolConfig.options = `-c search_path="${escaped}"`;
|
||||
}
|
||||
return { poolConfig, prismaSchema: schema || undefined };
|
||||
} catch {
|
||||
return { poolConfig: { connectionString } };
|
||||
}
|
||||
}
|
||||
|
||||
const { poolConfig, prismaSchema } = createPgPoolConfig(env.DATABASE_URL);
|
||||
const pool = new Pool(poolConfig);
|
||||
const adapter = prismaSchema ? new PrismaPg(pool, { schema: prismaSchema }) : new PrismaPg(pool);
|
||||
// Prisma 7 requires a driver adapter for direct database connections.
|
||||
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
|
||||
const adapter = new PrismaPg(pool);
|
||||
|
||||
export const prisma = new PrismaClient({
|
||||
adapter,
|
||||
|
|
|
|||
|
|
@ -14,20 +14,10 @@ function resolveLogLevel(): LogLevel {
|
|||
return (LOG_LEVELS as readonly string[]).includes(raw) ? (raw as LogLevel) : 'info';
|
||||
}
|
||||
|
||||
function ensureLogDir(dir: string): void {
|
||||
try {
|
||||
mkdirSync(dir, { recursive: true });
|
||||
} catch (err) {
|
||||
const msg = err instanceof Error ? err.message : String(err);
|
||||
process.stderr.write(`[kord] Failed to create LOG_DIR "${dir}": ${msg}\n`);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
const logDir = resolve((process.env.LOG_DIR || 'logs').trim());
|
||||
const logDir = resolve(process.env.LOG_DIR || 'logs');
|
||||
const level = resolveLogLevel();
|
||||
|
||||
ensureLogDir(logDir);
|
||||
mkdirSync(logDir, { recursive: true });
|
||||
|
||||
log4js.configure({
|
||||
appenders: {
|
||||
|
|
|
|||
Loading…
Reference in New Issue