const fs = require('fs');
const path = require('path');
const Sequelize = require('sequelize');
const process = require('process');
const basename = path.basename(__filename);
const env = process.env.NODE_ENV || 'coba';
require('dotenv').config();

const config = {
    username: process.env.DB_USERNAME,
    password: process.env.DB_PASSWORD,
    database: process.env.DB_DATABASE,
    host: process.env.DB_HOST,
    dialect: process.env.DB_CONNECTION || 'mysql',
};

const db = {};

let sequelize;
if (config.use_env_variable) {
    sequelize = new Sequelize(process.env[config.use_env_variable], config);
} else {
    sequelize = new Sequelize(
        config.database,
        config.username,
        config.password,
        config
    );
}

// Import your model
const argv = require('yargs').argv;
const modelName = argv.modelName || 'defaultValue';

const Model = require(`../../models/${modelName}.model`)(sequelize);

// Synchronize the Model model to create its table
Model.sync({ alter: true }) // Set `force: true` to drop the table if it exists
    .then(() => {
        console.log(`Model ${modelName} created successfully.`);
        // Do any additional setup or actions here
    })
    .catch((error) => {
        console.error('Error creating Model table:', error);
    });
