From b1d15531e4fc2bcf10c02b58f6b8a7244bf8abef Mon Sep 17 00:00:00 2001 From: amhsirak Date: Wed, 22 Jan 2025 18:58:49 +0530 Subject: [PATCH 1/6] feat: set alter true while db sync --- server/src/storage/db.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/storage/db.ts b/server/src/storage/db.ts index 2f0fcde4..81c9c039 100644 --- a/server/src/storage/db.ts +++ b/server/src/storage/db.ts @@ -29,7 +29,7 @@ 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 + await sequelize.sync({ force: false, alter: true }); // force: true will drop and recreate tables on every run console.log('Database synced successfully!'); } catch (error) { console.error('Failed to sync database:', error); From 75d65578cd54a9ab4afd637bf8dc2e537e32ed30 Mon Sep 17 00:00:00 2001 From: amhsirak Date: Wed, 22 Jan 2025 19:00:15 +0530 Subject: [PATCH 2/6] feat: check node env --- server/src/storage/db.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/server/src/storage/db.ts b/server/src/storage/db.ts index 81c9c039..b6854c55 100644 --- a/server/src/storage/db.ts +++ b/server/src/storage/db.ts @@ -29,6 +29,7 @@ export const connectDB = async () => { export const syncDB = async () => { try { //setupAssociations(); + const isDevelopment = process.env.NODE_ENV === 'development'; await sequelize.sync({ force: false, alter: true }); // force: true will drop and recreate tables on every run console.log('Database synced successfully!'); } catch (error) { From 76ab46fc879e9486e053362e514b9e9a92d88a64 Mon Sep 17 00:00:00 2001 From: amhsirak Date: Wed, 22 Jan 2025 19:01:00 +0530 Subject: [PATCH 3/6] chore: re-arrange --- server/src/storage/db.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/src/storage/db.ts b/server/src/storage/db.ts index b6854c55..40968df8 100644 --- a/server/src/storage/db.ts +++ b/server/src/storage/db.ts @@ -30,7 +30,8 @@ export const syncDB = async () => { try { //setupAssociations(); const isDevelopment = process.env.NODE_ENV === 'development'; - await sequelize.sync({ force: false, alter: true }); // force: true will drop and recreate tables on every run + // force: true will drop and recreate tables on every run + await sequelize.sync({ force: false, alter: true }); console.log('Database synced successfully!'); } catch (error) { console.error('Failed to sync database:', error); From e58197b91b477163e3b3414a0c239e483596e88e Mon Sep 17 00:00:00 2001 From: amhsirak Date: Wed, 22 Jan 2025 19:01:16 +0530 Subject: [PATCH 4/6] chore: format --- server/src/storage/db.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/server/src/storage/db.ts b/server/src/storage/db.ts index 40968df8..bc31439c 100644 --- a/server/src/storage/db.ts +++ b/server/src/storage/db.ts @@ -31,7 +31,10 @@ export const syncDB = async () => { //setupAssociations(); const isDevelopment = process.env.NODE_ENV === 'development'; // force: true will drop and recreate tables on every run - await sequelize.sync({ force: false, alter: true }); + await sequelize.sync({ + force: false, + alter: true + }); console.log('Database synced successfully!'); } catch (error) { console.error('Failed to sync database:', error); From aaf13b47004529bfab5ba902e21d2392a0395950 Mon Sep 17 00:00:00 2001 From: amhsirak Date: Wed, 22 Jan 2025 19:01:53 +0530 Subject: [PATCH 5/6] feat: alter:true only in development mode --- server/src/storage/db.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/storage/db.ts b/server/src/storage/db.ts index bc31439c..0aa0dad5 100644 --- a/server/src/storage/db.ts +++ b/server/src/storage/db.ts @@ -33,7 +33,7 @@ export const syncDB = async () => { // force: true will drop and recreate tables on every run await sequelize.sync({ force: false, - alter: true + alter: isDevelopment }); console.log('Database synced successfully!'); } catch (error) { From a4c072b7d56b2f920ef32eebd5dd9799dd09aad9 Mon Sep 17 00:00:00 2001 From: amhsirak Date: Wed, 22 Jan 2025 19:02:22 +0530 Subject: [PATCH 6/6] chore: notes on db sync in dev mode --- server/src/storage/db.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/server/src/storage/db.ts b/server/src/storage/db.ts index 0aa0dad5..cdd84655 100644 --- a/server/src/storage/db.ts +++ b/server/src/storage/db.ts @@ -31,6 +31,7 @@ export const syncDB = async () => { //setupAssociations(); 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