remove sync alter true, add pending migration check
This commit is contained in:
@@ -165,10 +165,23 @@ app.use(sanitizeError);
|
||||
|
||||
const PORT = process.env.PORT || 5000;
|
||||
|
||||
const { checkPendingMigrations } = require("./utils/checkMigrations");
|
||||
|
||||
sequelize
|
||||
.sync({ alter: true })
|
||||
.authenticate()
|
||||
.then(async () => {
|
||||
logger.info("Database synced successfully");
|
||||
logger.info("Database connection established successfully");
|
||||
|
||||
// Check for pending migrations
|
||||
const pendingMigrations = await checkPendingMigrations(sequelize);
|
||||
if (pendingMigrations.length > 0) {
|
||||
logger.error(
|
||||
`Found ${pendingMigrations.length} pending migration(s). Please run 'npm run db:migrate'`,
|
||||
{ pendingMigrations }
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
logger.info("All migrations are up to date");
|
||||
|
||||
// Initialize email services and load templates
|
||||
try {
|
||||
@@ -209,8 +222,9 @@ sequelize
|
||||
});
|
||||
})
|
||||
.catch((err) => {
|
||||
logger.error("Unable to sync database", {
|
||||
logger.error("Unable to connect to database", {
|
||||
error: err.message,
|
||||
stack: err.stack,
|
||||
});
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user