const config = require("../config");
const Sequelize = require('sequelize');

const { host, port, user, password, database } = config.databaseConfigSAPPS;
const dbSAPPS = new Sequelize(database, user, password, {
    host: host,
    dialect: "mysql",
    port: port,
    define: {
        timestamps: false,
    },
});

const migration = require('../migrations/20241224090336-update-employee-relations'); // Sesuaikan dengan path ke file migrasi

(async () => {
    // Tunggu inisialisasi selesai
    console.log('Initializing...');
    await dbSAPPS.authenticate();
    await dbSAPPS.sync();

    // Jalankan migrasi
    console.log('Migrating...');
    await migration.up(dbSAPPS.getQueryInterface(), dbSAPPS);
    console.log('Migration applied successfully.');
})().catch(error => {
    console.error('Error applying migration:', error);
});

