Skip to content

Commit

Permalink
ability to send option directly to function instead of cli argument
Browse files Browse the repository at this point in the history
  • Loading branch information
s0msqs_jovanm authored and s0msqs_jovanm committed Sep 19, 2018
1 parent e1e214d commit 0654d26
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ require('anydb-sql-migrate')
.migrate({ silent: true }); // it will supress only console.logs, not errors
```

If you want to run the migrations from JavaScript code instead of cli, you can pass `{ execute: true }` to `run` function

```js
require('anydb-sql-migrate')
.create(myanydbsql, '/path/to/migrations/dir')
.run({ execute: true }); // will use this argument instead of reading from process.argv
```

# license

MIT
11 changes: 9 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ export interface MigrationTask {
up:MigFn; down:MigFn; name:string
}

export interface MigrationOptions {
check: boolean;
execute: boolean;
rollback: boolean;
drop: boolean;
}

export function create(db:AnydbSql, tasks:string | MigrationTask[]) {
var list:Array<MigrationTask> = [];
var migrations = <MigrationsTable>db.define<Migration>({
Expand Down Expand Up @@ -112,8 +119,8 @@ export function create(db:AnydbSql, tasks:string | MigrationTask[]) {
function check(f:(items: MigrationTask[]) => any) {
return runMigration(tx => getMigrationList(tx).then(f))
}
function run() {
const args = require('yargs').argv;
function run(migrationOptions?: MigrationOptions) {
const args = migrationOptions || require('yargs').argv;
if (args.check)
return check(migrations => {
if (migrations.length) {
Expand Down

0 comments on commit 0654d26

Please sign in to comment.