/
home
/
infinitibizsol
/
.trash
/
File Upload :
llllll
Current File: /home/infinitibizsol/.trash/run-migrations.js.2
/* // run-migrations.js const { exec } = require("child_process"); function runMigrations() { const migrateCommand = "npx sequelize-cli db:migrate"; console.log("Starting migrations..."); exec(migrateCommand, (error, stdout, stderr) => { if (error) { console.error(`Migration error: ${error.message}`); return; } if (stderr) { console.error(`Migration stderr: ${stderr}`); return; } console.log(`Migration output:\n${stdout}`); }); } module.exports = { runMigrations }; */ const { exec } = require("child_process"); // Function to create a new migration function createNewMigration(migrationName) { if (!migrationName) { throw new Error("A migration name must be provided"); } // Replace any spaces with underscores (_) and remove special characters const cleanedName = migrationName .replace(/\s+/g, "_") .replace(/[^a-zA-Z0-9_]/g, ""); const command = `npx sequelize-cli migration:generate --name ${cleanedName}`; return executeCommand(command, "Create Migration"); } // Function to run migrations function runMigrations() { return executeCommand("npx sequelize-cli db:migrate", "Migration"); } // Function to undo the last migration function undoLastMigration() { return executeCommand("npx sequelize-cli db:migrate:undo", "Migration undo"); } // Function to undo all migrations function undoAllMigrations() { return executeCommand( "npx sequelize-cli db:migrate:undo:all", "Full migration undo" ); } // General function to execute any Sequelize CLI command function executeCommand(command, actionName) { console.log(`${actionName} started...`); return new Promise((resolve, reject) => { exec(command, (error, stdout, stderr) => { if (error) { console.error(`${actionName} error: ${error.message}`); reject(error); return; } if (stderr) { console.error(`${actionName} stderr: ${stderr}`); reject(new Error(stderr)); return; } console.log(`${actionName} output:\n${stdout}`); resolve(stdout); }); }); } module.exports = { runMigrations, undoLastMigration, undoAllMigrations, createNewMigration, };
Copyright ©2k19 -
Hexid
|
Tex7ure