防止sequelize在node.js应用中删除数据库 [英] Prevent sequelize to drop database in node.js app
问题描述
首先,我将node.js与sequelize ORM和Postgres SQL一起使用。
First of all, I am using node.js with sequelize ORM and Postgres SQL.
我有2个简单的问题:
-
每次我重新运行节点应用程序时,sequelize都会删除并在数据库中创建所有表。如何防止它发生(我不想删除数据库中的记录)?我尝试将NODE_ENV设置为进行测试,但无济于事。
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.
后继迁移如何知道它在哪里停止(哪些迁移已执行而哪些迁移未执行) )。
例如,当我在Grails框架中使用数据库迁移时,它会自动在数据库中创建一个表,该表保留所有在我重新运行应用程序之前和执行时所执行的迁移时间戳记,它会查看该表并知道哪些迁移是已经完成而尚未完成。
使用节点/序列化时没有看到任何表格,它如何工作? :)
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? :)
谢谢,
Ivan
Thanks, Ivan
推荐答案
您已经弄清楚了,由于正在执行操作,所以表被删除了
As you already figured out, the tables are being dropped because you are doing
sequelize.sync({ force: true })
真正的力量是元凶
第二个问题-迁移状态保存在数据库的一个表中-我相信它称为 sequelize_meta
To your second question - the state of migrations is saved in a table in your db - i believe it's called sequelize_meta
这篇关于防止sequelize在node.js应用中删除数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!