-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(loopback4-example-shopping): add migration script
Add migration.ts and package scripts Signed-off-by: dougal83 <[email protected]>
- Loading branch information
Showing
3 changed files
with
22 additions
and
0 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
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,20 @@ | ||
import {ShoppingApplication} 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 ShoppingApplication(); | ||
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); | ||
}); |