add TypeORM postgres config and migration runner.

This commit is contained in:
2026-10-05 20:54:50 +02:00
parent ca8233eb5a
commit 64041aa9a8
9 changed files with 1251 additions and 31 deletions
+18 -3
View File
@@ -1,11 +1,28 @@
import { registerAs } from '@nestjs/config';
import { AppConfig } from '../types/AppConfig';
import { PostgresConfig } from '../types/Config';
import { NodeEnv } from '../types/NodeEnv';
const env = (key: string): string => process.env[key] || '';
const envInt = (key: string): number => parseInt(env(key), 10);
const isEnabled = (key: string): boolean => env(key) === 'true';
export const getPostgresConfig = (): PostgresConfig => {
return {
type: 'postgres',
url: `postgres://${env('POSTGRES_USER')}:${env('POSTGRES_PASSWORD')}@${env('POSTGRES_HOST')}:${env('POSTGRES_PORT')}/${env('POSTGRES_DB')}`,
host: env('POSTGRES_HOST'),
username: env('POSTGRES_USER'),
password: env('POSTGRES_PASSWORD'),
port: envInt('POSTGRES_PORT'),
database: env('POSTGRES_DB'),
entities: [__dirname + '/../modules/**/entities/*{.ts,.js}'],
migrations: [__dirname + '/../database/migrations/*{.ts,.js}'],
migrationsRun: isEnabled('POSTGRES_MIGRATIONS_RUN')
};
};
export const getAppConfig = (): AppConfig => {
const rawOrigins = env('CORS_ORIGINS');
@@ -18,5 +35,3 @@ export const getAppConfig = (): AppConfig => {
.filter(Boolean)
};
};
export default registerAs('app', getAppConfig);