Skip to content

Instantly share code, notes, and snippets.

@kopipejst
Created August 24, 2014 01:07
Show Gist options
  • Save kopipejst/3e525bdb4e856c98bfb1 to your computer and use it in GitHub Desktop.
Save kopipejst/3e525bdb4e856c98bfb1 to your computer and use it in GitHub Desktop.
loopback create build-in models tables
/**
* loopback: create build-in models tables
*
* put migrate.js file in server folder
* run `node migrate.js`
* @type {[type]}
*/
var app = require('./server');
var dataSource = app.dataSources.db;
dataSource.automigrate('User', function(err) {
if (!err) {
console.log('User table created');
} else {
console.log('-- User table not created');
}
dataSource.automigrate('AccessToken', function(err) {
if (!err) {
console.log('AccessToken table created');
} else {
console.log('-- AccessToken table not created');
}
dataSource.automigrate('ACL', function(err) {
if (!err) {
console.log('ACL table created');
} else {
console.log('-- ACL table not created');
}
dataSource.automigrate('RoleMapping', function(err) {
if (!err) {
console.log('RoleMapping table created');
} else {
console.log('-- RoleMapping table not created');
}
dataSource.automigrate('Role', function(err) {
if (!err) {
console.log('Role table created');
} else {
console.log('-- Role table not created');
}
dataSource.disconnect(); // close connection
});
});
});
});
});
@wesleymilan
Copy link

Ivan, thank you very much for this example. Migration should be a build-in function in slc command.

Best regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment