const path = require('path');
const dotenv = require('dotenv');

const rootPath = process.env.ROOT_PATH || path.resolve(__dirname, '.');
dotenv.config({ path: path.resolve(rootPath, '.env') });
const dbPath = path.resolve(rootPath, './db');

/**
 * @type { Object.<string, import("knex").Knex.Config> }
 */
module.exports = {

  development: {
    client: 'mysql2',
    connection: {
      host: process.env.DB_HOST,
      user: process.env.DB_USER,
      password: process.env.DB_PASS,
      database: process.env.DB_NAME
    },
    pool: {
      min: 2,
      max: 10
    },
    migrations: {
      directory: path.join(dbPath, 'migrations')
    },
    seeds: {
      directory: path.join(dbPath, 'seeds')
    }
  },

  production: {
    client: 'mysql2',
    connection: {
      host: process.env.DB_HOST,
      user: process.env.DB_USER,
      password: process.env.DB_PASS,
      database: process.env.DB_NAME
    },
    pool: {
      min: 2,
      max: 10
    },
    migrations: {
      directory: path.join(dbPath, 'migrations')
    },
    seeds: {
      directory: path.join(dbPath, 'seeds')
    }
  }

};
