#POSTGRES: Create Table if it does not exist

1 messages · Page 1 of 1 (latest)

sharp kraken
#

You can do those migrations when you start the app once.

Or even run them manually outside the app.

sharp kraken
#

Do a CREATE TABLE IF NOT EXISTS instead, and you should be good.

Maybe think about what you want to do when the query doesn't work too (maybe exit, so you don't run the app with the wrong model).

And this can work for small project, but at some point if you are on a bigger project, where you have to edit the database more often, another approach will be necessary to keep everything in sync.

slim plank
#

Okay use something like sequelize and there's something called sync, call it on the sequelize instance and when promise is resolved , start the server ,look it up, if you force then on every server re started db is dropped and created again. It looks something like this sequelize.sync