本文介绍了loopback automigrate vs autoupdate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们有模型并希望将其迁移到数据库时,我们只需在server / boot中创建脚本:

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){...})

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

每个服务器上的第一个重启,在db中重新创建模式并清除数据,第二个如果存在,可以创建模式或更改它,但不能清除数据。当我们使用automigrate创建模式时,我们应该删除它(或者每次我们的数据都会丢失),但是当我们使用autoupdate时它可以保留在代码中(我们可以修改模型和模式将更新)。

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).

看起来autoupdate更有用。当我们必须使用automigrate时呢? autoupdate是否有支持automigrate的缺点?

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

我喜欢工作流,我只使用自动启动,但只有当我决定时才设置env标志来更新模式。你怎么看?

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

推荐答案

它们都有其特定用途。如果您不关心数据,则自动迁移(即删除表并重新创建)。如果您不想意外删除现有数据,请自动更新。请参阅

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

这篇关于loopback automigrate vs autoupdate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 08:06