Skip to content

Instantly share code, notes, and snippets.

@viniciusstroher
Created September 3, 2020 01:46
Show Gist options
  • Save viniciusstroher/f56c72bcd4f8d92310cadf6ed19b8a00 to your computer and use it in GitHub Desktop.
Save viniciusstroher/f56c72bcd4f8d92310cadf6ed19b8a00 to your computer and use it in GitHub Desktop.
[LB4] Loopback 4 Automigrate Example (example/todo-list)
// Place in app root, build project (e.g: 'npm start'), execute (e.g. 'node automigrate.js')
const {DbDataSource} = require('./dist/src/datasources/db.datasource.js');
const {TodoRepository} = require('./dist/src/repositories/todo.repository.js');
const {TodoListRepository} = require('./dist/src/repositories/todo-list.repository.js');
const db = new DbDataSource();
const repoTodo = new TodoRepository(db);
const repoTodoList = new TodoListRepository(db);
db.automigrate(['Todo', 'TodoList']).then(
success => {
console.log('database was successfully updated');
process.exit(0);
},
error => {
console.error('cannot update the database', error);
process.exit(1);
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment