/**
 * The canonical Knex configuration, shared by:
 *   - the knex CLI, via the root knexfile.ts re-export (`npm run migrate*`)
 *   - the runtime instance in src/lib/db.ts
 *
 * Pool is sized down for shared cPanel hosting (PLANNING.md §3a / §12); the knex
 * default of 10 is often above the host's concurrent-connection cap.
 */
import type { Knex } from 'knex';
import { env } from '../env';

const config: Knex.Config = {
  client: 'mysql2',
  connection: {
    host: env.DB_HOST,
    port: env.DB_PORT,
    user: env.DB_USER,
    password: env.DB_PASSWORD,
    database: env.DB_NAME,
    charset: 'utf8mb4',
    timezone: 'Z',
    dateStrings: true,
  },
  pool: { min: 0, max: env.DB_POOL_MAX },
  migrations: {
    directory: './migrations',
    extension: 'ts',
    tableName: 'knex_migrations',
  },
  seeds: {
    directory: './seeds',
    extension: 'ts',
  },
};

export default config;
