import { ConfigModule } from '@nestjs/config';
import dbConfiguration from './src/config/db.config';
import { DataSource } from 'typeorm';
import * as dotenv from 'dotenv';
dotenv.config();

ConfigModule.forRoot({
  isGlobal: true,
  load: [dbConfiguration],
});

const connectionSource = new DataSource({
  type: 'mysql',
  logging: true,
  host: process.env.DB_HOST,
  port: parseInt(process.env.DB_PORT),
  username: process.env.DB_USER,
  password: process.env.DB_PASSWORD,
  database: process.env.DB_DATABASE,
  // autoLoadEntities: true,
  entities: [
    'src/**/*.entity{.ts,.js}',
    'src/**/**/*.entity{.ts,.js}',
    'src/**/**/**/*.entity{.ts,.js}',
  ],
  synchronize: false,
  migrations: ['src/migrations/*.ts'],
  migrationsTableName: 'migrations_TypeORM',
  // default: true, //set up a default connection
});

module.exports = {
  connectionSource,
};
