import { DataSource } from 'typeorm';
import * as dotenv from 'dotenv';

// Load environment variables
dotenv.config({ path: '.env.local' });
dotenv.config({ path: '.env' });

/**
 * Production data source for running migrations
 * Uses compiled JS files instead of TypeScript
 */
export const AppDataSource = new DataSource({
  type: 'postgres',
  host: process.env.POSTGRES_HOST || 'localhost',
  port: parseInt(process.env.POSTGRES_PORT || '5432', 10),
  username: process.env.POSTGRES_USER || 'iconsulting',
  password: process.env.POSTGRES_PASSWORD,
  database: process.env.POSTGRES_DB || 'iconsulting',
  entities: [__dirname + '/**/*.orm.js'],
  migrations: [__dirname + '/migrations/*.js'],
  synchronize: false,
  logging: true,
});
