diff --git a/server/src/storage/db.ts b/server/src/storage/db.ts index 2f0fcde4..cdd84655 100644 --- a/server/src/storage/db.ts +++ b/server/src/storage/db.ts @@ -29,7 +29,13 @@ export const connectDB = async () => { export const syncDB = async () => { try { //setupAssociations(); - await sequelize.sync({ force: false }); // force: true will drop and recreate tables on every run + const isDevelopment = process.env.NODE_ENV === 'development'; + // force: true will drop and recreate tables on every run + // Use `alter: true` only in development mode + await sequelize.sync({ + force: false, + alter: isDevelopment + }); console.log('Database synced successfully!'); } catch (error) { console.error('Failed to sync database:', error);