import 'dotenv/config';
import * as path from 'path';
import { DataSource } from 'typeorm';

const migrationDataSource = new DataSource({
  type: 'mysql',
  ...(process.env.DATABASE_URL
    ? { url: process.env.DATABASE_URL }
    : {
        host: process.env.DB_HOST || 'localhost',
        port: parseInt(process.env.DB_PORT || '') || 3306,
        username: process.env.DB_USERNAME || 'root',
        password: process.env.DB_PASSWORD || '',
        database: process.env.DB_DATABASE || 'tracker',
      }),
  entities: [path.join(__dirname, 'entities.ts')],
  migrations: [path.join(__dirname, '..', '..', 'migrations', '*.{ts,js}')],
  synchronize: false,
  logging: true,
});

export default migrationDataSource;
