Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

loopback automigrate vs autoupdate

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?

like image 941
Krzysztof Sztompka Avatar asked Sep 25 '15 12:09

Krzysztof Sztompka


1 Answers

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

like image 195
superkhau Avatar answered Oct 02 '22 13:10

superkhau