// apps/server/src/database/database.module.ts
import { Module, Global } from '@nestjs/common';
import { Pool } from 'pg';

@Global()
@Module({
  providers: [
    {
      provide: 'PG_POOL',
      useFactory: () => {
        // 直接从 process.env 读取，因为启动脚本已通过 --env-file 注入
        return new Pool({
          host: process.env.DB_HOST,
          port: parseInt(process.env.DB_PORT || '5432'),
          user: process.env.DB_USER,
          password: process.env.DB_PASSWORD,
          database: process.env.DB_NAME,
        });
      },
    },
  ],
  exports: ['PG_POOL'],
})
export class DatabaseModule {}

