-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(repository): migrateSchema APIs
Introduce a new Application-level method `app.migrateSchema()` provided by `RepositoryMixin`, this method executes schema migration as implemented by datasources registered with the application. Simplify the instructions shown in `Database-migrations.db` Add an example `migrate.ts` script to our Todo example to verify that the code snippet shown in the docs works as intended.
- Loading branch information
Showing
5 changed files
with
299 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright IBM Corp. 2017,2018. All Rights Reserved. | ||
// Node module: @loopback/example-todo | ||
// This file is licensed under the MIT License. | ||
// License text available at https://opensource.org/licenses/MIT | ||
|
||
import {TodoListApplication} from './application'; | ||
|
||
export async function migrate(args: string[]) { | ||
const existingSchema = args.includes('--rebuild') ? 'drop' : 'alter'; | ||
console.log('Migrating schemas (%s existing schema)', existingSchema); | ||
|
||
const app = new TodoListApplication(); | ||
await app.boot(); | ||
await app.migrateSchema({existingSchema}); | ||
|
||
// Connectors usually keep a pool of opened connections, | ||
// this keeps the process running even after all work is done. | ||
// We need to exit explicitly. | ||
process.exit(0); | ||
} | ||
|
||
migrate(process.argv).catch(err => { | ||
console.error('Cannot migrate database schema', err); | ||
process.exit(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.