import { DataSource } from 'typeorm';
import { config } from 'dotenv';
import { join } from 'path';

// TypeORM CLI runs from apps/server/
const root = process.cwd();
config({ path: join(root, '.env') });

export default new DataSource({
  type: 'mysql',
  host: process.env.DB_HOST || 'localhost',
  port: Number(process.env.DB_PORT) || 3306,
  username: process.env.DB_USERNAME || 'root',
  password: process.env.DB_PASSWORD || '',
  database: process.env.DB_DATABASE || 'dorm_billing',
  charset: 'utf8mb4',
  entities: [join(root, 'src/**/*.entity.ts')],
  migrations: [join(root, 'src/migrations/*.ts')],
});
