-
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: scaffold DB migration script for new app projects
- Loading branch information
Showing
8 changed files
with
99 additions
and
24 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,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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import {<%= project.applicationName %>} 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 <%= project.applicationName %>(); | ||
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
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