Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent sequelize to drop database in node.js app

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

like image 428
Ivan Longin Avatar asked Jan 02 '14 11:01

Ivan Longin


1 Answers

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

like image 51
Jan Aagaard Meier Avatar answered Oct 21 '22 07:10

Jan Aagaard Meier