loopback-component-migrate icon indicating copy to clipboard operation
loopback-component-migrate copied to clipboard

Question: How do you implement this via CLI?

Open sundeepgupta opened this issue 9 years ago • 5 comments

I thought I should be implementing this using the CLI so that it could be part of a deploy sequence, something like:

Note: I've aliased loopback-component-migrate binary command to lcm

  1. npm install
  2. lcm up
  3. node server.js

I created a migration via lcm create initial which created the migration file in ./migrations/20160810101725-initial.js. The migration file looks like:

module.exports = {
  up: function(dataSource, next) {
    console.log('running initial up');
    next();
  },
  down: function(dataSource, next) {
    console.log('running initial down');
    next();
  }
};

When I run lcm up, first thing output is "Migrating up to: "20160810101725-initial.js" [TODO]" and then I see output from starting the app up, just like I'd see if I ran node server.js. I don't see the logs I inserted into the migration or anything. The app continues to listen for web requests/socket messages...

I'm using MongoDB as my data store and when I look inside, I don't see a collection for Migrations or anything.

sundeepgupta avatar Aug 10 '16 15:08 sundeepgupta

when I use the CLI up command it just hangs for me on the Migrating up to: "name-of-migrationfile" [TODO]

jcolemorrison avatar Jan 14 '17 04:01 jcolemorrison

For anyone else having troubles with this, I just gave up. This doesn't seem to work at all with 3.x. There's actually a pretty reliable pattern you can achieve just using automigrate when you need to create new tables or seed data and then autoupdate to keep things in sync without having to worry about a convoluted solution:

Authorized Resources and Database Migrations with Strongloop's Loopback

jcolemorrison avatar Feb 01 '17 03:02 jcolemorrison

any plans to implement these features?

@sundeepgupta any idea?

curioustushar avatar Feb 08 '17 06:02 curioustushar

Thanks for implementing this @ivesdebruycker

mrfelton avatar Jan 10 '18 11:01 mrfelton

@jcolemorrison this package is less about keeping database schema changes in sync (which you can do with autoupdate as you mention), and more about running data migrations against your database in order to change your existing data if your application's data expectations change.

mrfelton avatar Jan 10 '18 11:01 mrfelton