Update environment configuration and enhance logging: Add support for loading a local .env file and improve logging behavior based on QUIET_ENV_LOGS settings. Introduce new diagnostic scripts in package.json for town worth and money flow analysis. Adjust production cost calculations in FalukantService to align with updated pricing logic and enhance product initialization parameters.
This commit is contained in:
@@ -1,7 +1,18 @@
|
||||
import { Sequelize, DataTypes } from 'sequelize';
|
||||
import dotenv from 'dotenv';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
|
||||
dotenv.config();
|
||||
const _dotenvQuiet = process.env.QUIET_ENV_LOGS === '1' || process.env.DOTENV_CONFIG_QUIET === '1';
|
||||
dotenv.config({ quiet: _dotenvQuiet });
|
||||
|
||||
// backend/.env.local — Tunnel/Entwicklung (override), auch wenn loadEnv.js nicht importiert wurde
|
||||
const _sequelizeDir = path.dirname(fileURLToPath(import.meta.url));
|
||||
const _envLocalPath = path.join(_sequelizeDir, '../.env.local');
|
||||
if (fs.existsSync(_envLocalPath)) {
|
||||
dotenv.config({ path: _envLocalPath, override: true, quiet: _dotenvQuiet });
|
||||
}
|
||||
|
||||
// Optionales Performance-Logging (aktivierbar per ENV)
|
||||
// - SQL_BENCHMARK=1: Sequelize liefert Query-Timing (ms) an logger
|
||||
@@ -27,12 +38,20 @@ const dbName = process.env.DB_NAME;
|
||||
const dbUser = process.env.DB_USER;
|
||||
const dbPass = process.env.DB_PASS || ''; // Fallback auf leeren String
|
||||
const dbHost = process.env.DB_HOST;
|
||||
const dbPort = Number.parseInt(process.env.DB_PORT || '5432', 10);
|
||||
|
||||
console.log('Database configuration:');
|
||||
console.log('DB_NAME:', dbName);
|
||||
console.log('DB_USER:', dbUser);
|
||||
console.log('DB_PASS:', dbPass ? '[SET]' : '[NOT SET]');
|
||||
console.log('DB_HOST:', dbHost);
|
||||
const useSsl = process.env.DB_SSL === '1' || process.env.PGSSLMODE === 'require';
|
||||
const connectTimeoutMs = Number.parseInt(process.env.DB_CONNECT_TIMEOUT_MS || '30000', 10);
|
||||
|
||||
if (process.env.QUIET_ENV_LOGS !== '1') {
|
||||
console.log('Database configuration:');
|
||||
console.log('DB_NAME:', dbName);
|
||||
console.log('DB_USER:', dbUser);
|
||||
console.log('DB_PASS:', dbPass ? '[SET]' : '[NOT SET]');
|
||||
console.log('DB_HOST:', dbHost);
|
||||
console.log('DB_PORT:', dbPort);
|
||||
console.log('DB_SSL:', useSsl ? 'on' : 'off');
|
||||
}
|
||||
|
||||
if (!dbName || !dbUser || !dbHost) {
|
||||
throw new Error('Missing required database environment variables: DB_NAME, DB_USER, or DB_HOST');
|
||||
@@ -44,8 +63,22 @@ const poolAcquire = Number.parseInt(process.env.DB_POOL_ACQUIRE || '30000', 10);
|
||||
const poolIdle = Number.parseInt(process.env.DB_POOL_IDLE || '10000', 10);
|
||||
const poolEvict = Number.parseInt(process.env.DB_POOL_EVICT || '1000', 10);
|
||||
|
||||
const dialectOptions = {
|
||||
connectTimeout: connectTimeoutMs,
|
||||
...(useSsl
|
||||
? {
|
||||
// node-pg: true oder { rejectUnauthorized: false } bei selbstsigniertem Zertifikat
|
||||
ssl:
|
||||
process.env.DB_SSL_REJECT_UNAUTHORIZED === '0'
|
||||
? { rejectUnauthorized: false }
|
||||
: true
|
||||
}
|
||||
: {})
|
||||
};
|
||||
|
||||
const sequelize = new Sequelize(dbName, dbUser, dbPass, {
|
||||
host: dbHost,
|
||||
port: dbPort,
|
||||
dialect: 'postgres',
|
||||
define: {
|
||||
timestamps: false,
|
||||
@@ -61,9 +94,7 @@ const sequelize = new Sequelize(dbName, dbUser, dbPass, {
|
||||
evict: poolEvict, // Intervall (ms) zum Prüfen auf idle Verbindungen
|
||||
handleDisconnects: true // Automatisches Reconnect bei Verbindungsverlust
|
||||
},
|
||||
dialectOptions: {
|
||||
connectTimeout: 30000 // Timeout für Verbindungsaufbau (30 Sekunden)
|
||||
},
|
||||
dialectOptions,
|
||||
retry: {
|
||||
max: 3, // Maximale Anzahl von Wiederholungsversuchen
|
||||
match: [
|
||||
|
||||
Reference in New Issue
Block a user