Question

First of all, I am using node.js with sequelize ORM and Postgres SQL.

I have 2 simple questions:

  1. Every time I rerun my node application sequelize is dropping and creating all tables in database. How to prevent it from doing that (I don't want my records in database to be deleted)? I have tried to set my NODE_ENV to test but it didn't help.

  2. How does sequelize migration knows where it stopped (which migration have executed and which not). When I was using database migration in Grails framework, for example, it automatically created a table in the database where it kept all migration timestamps that executed before and when I rerun my application it looks at that table and knows which migrations are already done and which are not. I don't see any table when using node/sequelize, so how it works? :)

Thanks, Ivan

Was it helpful?

Solution

As you already figured out, the tables are being dropped because you are doing

sequelize.sync({ force: true })

The force true part being the culprit

To your second question - the state of migrations is saved in a table in your db - i believe it's called sequelize_meta

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top