loopback automigrate vs autoupdate
Asked Answered
C

1

5

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?

Chloromycetin answered 25/9, 2015 at 12:26 Comment(0)
S
8

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

Sharice answered 25/9, 2015 at 20:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.