Fix mariadb?

This commit is contained in:
Christopher Cookman 2024-12-19 18:35:41 -07:00
parent 389c3d43f9
commit 5b559a0ec0
2 changed files with 6 additions and 19 deletions

View file

@ -314,7 +314,7 @@ client.on("interactionCreate", async (interaction) => {
log.info("Starting up...") log.info("Starting up...")
require("./migrations")().then(() => { require("./migrations")(pool).then(() => {
// Load all route modules from the 'routes' folder // Load all route modules from the 'routes' folder
const routesPath = path.join(__dirname, 'routes'); const routesPath = path.join(__dirname, 'routes');
fs.readdirSync(routesPath).forEach((file) => { fs.readdirSync(routesPath).forEach((file) => {

View file

@ -2,22 +2,9 @@ const mariadb = require('mariadb');
const fs = require('fs'); const fs = require('fs');
const path = require('path'); const path = require('path');
const util = require("util") const util = require("util")
require("dotenv").config()
const log = require("./log");
// Create a MariaDB connection pool function runMigrations(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() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let connection; let connection;
@ -47,7 +34,7 @@ function runMigrations() {
[migrationName] [migrationName]
).then(([rows]) => { ).then(([rows]) => {
if (Object.keys(rows || {}).length > 0) { if (Object.keys(rows || {}).length > 0) {
//log.info(`Skipping already applied migration: ${migrationName}`); //console.log(`Skipping already applied migration: ${migrationName}`);
return; // Skip this migration return; // Skip this migration
} }
@ -60,7 +47,7 @@ function runMigrations() {
'INSERT INTO migrations (name) VALUES (?)', 'INSERT INTO migrations (name) VALUES (?)',
[migrationName] [migrationName]
).then(() => { ).then(() => {
log.info(`Applied migration: ${migrationName}`); console.log(`Applied migration: ${migrationName}`);
}); });
}); });
}); });
@ -68,11 +55,11 @@ function runMigrations() {
}, Promise.resolve()); }, Promise.resolve());
}) })
.then(() => { .then(() => {
log.info('All migrations applied successfully!'); console.log('All migrations applied successfully!');
resolve(); resolve();
}) })
.catch(err => { .catch(err => {
log.error('Error running migrations:', err); console.errorr('Error running migrations:', err);
reject(err); reject(err);
}) })
.finally(() => { .finally(() => {