Skip to content

Commit

Permalink
feat(loopback4-example-shopping): add migration script
Browse files Browse the repository at this point in the history
Add migration.ts and package scripts

Signed-off-by: dougal83 <[email protected]>
  • Loading branch information
dougal83 authored and bajtos committed Jun 18, 2019
1 parent 6ec34f9 commit 491ba12
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"commitmsg": "commitlint -E GIT_PARAMS",
"docker:start": "./bin/start-dbs.sh",
"docker:stop": "./bin/stop-dbs.sh",
"migrate": "node ./packages/shopping/dist/migrate",
"lint": "npm run prettier:check && npm run eslint",
"lint:fix": "npm run prettier:fix && npm run eslint:fix",
"prettier:cli": "lb-prettier \"**/*.ts\" \"**/*.js\" \"**/*.md\"",
Expand Down
1 change: 1 addition & 0 deletions packages/shopping/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"clean": "lb-clean dist*",
"docker:start": "../../bin/start-dbs.sh",
"docker:stop": "../../bin/stop-dbs.sh",
"migrate": "node ./dist/migrate",
"pretest": "npm run clean && npm run build && npm run docker:start",
"pretest:ci": "npm run build",
"test": "lb-mocha --allow-console-logs \"dist/__tests__/**/*.js\"",
Expand Down
20 changes: 20 additions & 0 deletions packages/shopping/src/migrate.ts
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);
});

0 comments on commit 491ba12

Please sign in to comment.