loopback automigrate vs autoupdate

纵然是瞬间 提交于 2019-12-10 16:21:06

问题


When we have model and we want to migrate it to database, we simply create script in server/boot with:

server.dataSource['myDbSource'].automigrate('MyMode', function(err){...})

or

server.dataSource['myDbSource'].autoupdate('MyMode', function(err){...})

First one on each server restart, recreate schema in db and clear data, second one can create schema or change it if exist, but not clear data. When we used automigrate to create schema we should remove it (or each time our data will be lost), but when we use autoupdate it can stay in code (we can modify models and schema will be updated).

It looks like autoupdate is more useful. When we have to use automigrate then? Is autoupdate has drawbacks in favor of automigrate?

I like workflow where i use automigrations only but set env flag to update schema only when i decided. What do you think?


回答1:


They both have their specific uses. Auto-migrate if you don't care about your data (ie. drop the table and recreate it). Auto-update if you don't want to accidentally delete existing data. See auto-migrate documentation



来源:https://stackoverflow.com/questions/32782192/loopback-automigrate-vs-autoupdate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!