8

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

3
  • Can you include some code? I'm using sequelize with postgresql and haven't had that problem. Commented Jan 2, 2014 at 14:08
  • I copied they express example on sequelize.js web page and only put postgre database instead of mysql (like they did in example) github.com/sequelize/sequelize-expressjs-example (link of their example) Commented Jan 2, 2014 at 15:22
  • 2
    I figured out. They put sync: { force: true } in some part of code in app.js and that override my sync (false) that I defined when connecting to database...now second question is all that bothers me :) Commented Jan 2, 2014 at 17:34

1 Answer 1

14

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.