diff --git a/index.js b/index.js index a859533..4a46731 100644 --- a/index.js +++ b/index.js @@ -314,7 +314,7 @@ client.on("interactionCreate", async (interaction) => { log.info("Starting up...") -require("./migrations")().then(() => { +require("./migrations")(pool).then(() => { // Load all route modules from the 'routes' folder const routesPath = path.join(__dirname, 'routes'); fs.readdirSync(routesPath).forEach((file) => { diff --git a/migrations.js b/migrations.js index 3bb01f7..19ba8b0 100644 --- a/migrations.js +++ b/migrations.js @@ -2,22 +2,9 @@ const mariadb = require('mariadb'); const fs = require('fs'); const path = require('path'); const util = require("util") -require("dotenv").config() -const log = require("./log"); -// Create a MariaDB connection pool -const pool = mariadb.createPool({ - host: process.env.DB_HOST, // Replace with your database host - port: process.env.DB_PORT || 3306, - user: process.env.DB_USER, // Replace with your database username - password: process.env.DB_PASS, // Replace with your database password - database: process.env.DB_DATABASE, // Replace with your database name - connectionLimit: 5 // Adjust connection limit as needed -}); - - -function runMigrations() { +function runMigrations(pool) { return new Promise((resolve, reject) => { let connection; @@ -47,7 +34,7 @@ function runMigrations() { [migrationName] ).then(([rows]) => { if (Object.keys(rows || {}).length > 0) { - //log.info(`Skipping already applied migration: ${migrationName}`); + //console.log(`Skipping already applied migration: ${migrationName}`); return; // Skip this migration } @@ -60,7 +47,7 @@ function runMigrations() { 'INSERT INTO migrations (name) VALUES (?)', [migrationName] ).then(() => { - log.info(`Applied migration: ${migrationName}`); + console.log(`Applied migration: ${migrationName}`); }); }); }); @@ -68,11 +55,11 @@ function runMigrations() { }, Promise.resolve()); }) .then(() => { - log.info('All migrations applied successfully!'); + console.log('All migrations applied successfully!'); resolve(); }) .catch(err => { - log.error('Error running migrations:', err); + console.errorr('Error running migrations:', err); reject(err); }) .finally(() => {