-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(migration): implement migration service (#142)
* meta service * meta schema * migrations start * fix * http version use meta * semver * list migs in correct order * progress * fix * k * fix * fixes * dry run * logger.window * MIGRATE_TARGET * refact * down migration * fix * ShutDownSignal * refact * refact * refact * fix * yargs * yargs+ * migrate command * refact * fix * fix * fix * pr comments * remove user token migration * fix * tests
- Loading branch information
1 parent
e2a1216
commit a6fef7c
Showing
16 changed files
with
515 additions
and
54 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
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,5 @@ | ||
export class ShutDownSignal extends Error { | ||
constructor() { | ||
super() | ||
} | ||
} |
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 |
---|---|---|
@@ -1,16 +1,67 @@ | ||
import './rewire' | ||
import express from 'express' | ||
import yargs from 'yargs' | ||
import { Api } from './api' | ||
import { App } from './app' | ||
import { Launcher } from './launcher' | ||
|
||
// Set NODE_ENV to production when starting messaging using the binary version | ||
process.env.NODE_ENV = (<any>process).pkg ? 'production' : process.env.NODE_ENV | ||
|
||
const router = express() | ||
const launch = async () => { | ||
const router = express() | ||
|
||
const app = new App() | ||
const api = new Api(app, router) | ||
const app = new App() | ||
const api = new Api(app, router) | ||
|
||
const launcher = new Launcher(router, app, api) | ||
void launcher.launch() | ||
const launcher = new Launcher(router, app, api) | ||
await launcher.launch() | ||
} | ||
|
||
void yargs | ||
.scriptName('') | ||
.command( | ||
['$0', 'serve'], | ||
'Start server', | ||
(yargs) => { | ||
return yargs.options({ autoMigrate: { type: 'boolean', default: false } }) | ||
}, | ||
async (argv) => { | ||
if (argv.autoMigrate) { | ||
process.env.AUTO_MIGRATE = 'true' | ||
} | ||
|
||
await launch() | ||
} | ||
) | ||
.command('migrate', 'Migrate database', (yargs) => { | ||
const start = async (cmd: string, target: string, dry: boolean) => { | ||
process.env.AUTO_MIGRATE = 'true' | ||
if (cmd) { | ||
process.env.MIGRATE_CMD = cmd | ||
} | ||
if (target) { | ||
process.env.MIGRATE_TARGET = target | ||
} | ||
if (dry) { | ||
process.env.MIGRATE_DRYRUN = 'true' | ||
} | ||
await launch() | ||
} | ||
|
||
return yargs | ||
.command('up', 'Migrate to the latest version (unless --target is specified)', {}, async (argv) => { | ||
await start('up', argv.target as string, argv.dry as boolean) | ||
}) | ||
.command('down', 'Downgrade to a previous version (--target must be specified)', {}, async (argv) => { | ||
await start('down', argv.target as string, argv.dry as boolean) | ||
}) | ||
.option('target', { | ||
alias: 't', | ||
describe: 'Target a specific version' | ||
}) | ||
.option('dryrun', { | ||
alias: 'dry', | ||
describe: 'Displays the list of migrations that will be executed, without applying the changes' | ||
}) | ||
}).argv |
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.