Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c1094c7

Browse files
committed
#145: Add logger arg to up, down
1 parent 6f8c2d8 commit c1094c7

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ migrator.config({
3232
// false disables logging
3333
log: true,
3434
// null or a function
35-
logger: (level, ..arg) => console.log(level, ..arg),
35+
logger: (level, ...args) => console.log(level, ...args),
3636
// enable/disable info log "already at latest."
3737
logIfLatest: true,
3838
// migrations collection name. Defaults to 'migrations'
@@ -64,7 +64,7 @@ var migrator = new Migration({
6464
// false disables logging
6565
log: true,
6666
// null or a function
67-
logger: (level, ..arg) => console.log(level, ..arg),
67+
logger: (level, ...args) => console.log(level, ...args),
6868
// enable/disable info log "already at latest."
6969
logIfLatest: true,
7070
// migrations collection name
@@ -90,7 +90,7 @@ To write a simple migration, somewhere in the server section of your project def
9090
``` javascript
9191
migrator.add({
9292
version: 1,
93-
up: function(db) {
93+
up: function(db, logger) {
9494
// use `db`(mongo driver Db instance) for migration setup to version 1
9595
// See http://mongodb.github.io/node-mongodb-native/2.2/api/Db.html for db api
9696
}
@@ -111,11 +111,11 @@ A more complete set of migrations might look like:
111111
migrator.add({
112112
version: 1,
113113
name: 'Name for this migration',
114-
up: function(db) {
114+
up: function(db, logger) {
115115
// use `db`(mongo driver Db instance) for migration setup to version 1.
116116
// See http://mongodb.github.io/node-mongodb-native/2.2/api/Db.html for db api
117117
},
118-
down: function(db) {
118+
down: function(db, logger) {
119119
// use `db`(mongo driver Db instance) for migration setup to version 0
120120
// See http://mongodb.github.io/node-mongodb-native/2.2/api/Db.html for db api
121121
}
@@ -124,11 +124,11 @@ migrator.add({
124124
migrator.add({
125125
version: 2,
126126
name: 'Name for this migration',
127-
up: function(db) {
127+
up: function(db, logger) {
128128
// use `db`(mongo driver Db instance) for migration setup to version 2
129129
// See http://mongodb.github.io/node-mongodb-native/2.2/api/Db.html for db api
130130
},
131-
down: function(db) {
131+
down: function(db, logger) {
132132
// use `db`(mongo driver Db instance) for migration setup to version 1
133133
// See http://mongodb.github.io/node-mongodb-native/2.2/api/Db.html for db api
134134
}
@@ -141,12 +141,12 @@ Control execution flow with async/await (promises):
141141
migrator.add({
142142
version: 2,
143143
name: 'Name for this migration',
144-
up: async function(db) {
144+
up: async function(db, logger) {
145145
// use `db`(mongo driver Db instance) for migration setup to version 2
146146
// See http://mongodb.github.io/node-mongodb-native/2.2/api/Db.html for db api
147147
await db.collections('someCollection')....
148148
},
149-
down: async function(db) {
149+
down: async function(db, logger) {
150150
// use `db`(mongo driver Db instance) for migration setup to version 1
151151
// See http://mongodb.github.io/node-mongodb-native/2.2/api/Db.html for db api
152152
await db.collections('someCollection')....

src/migration.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ export interface IMigrationOptions {
4646
export interface IMigration {
4747
version: number;
4848
name: string;
49-
up: (db: Db) => Promise<any> | any;
50-
down: (db: Db) => Promise<any> | any;
49+
up: (db: Db, logger?: (level: SyslogLevels, ...args: any[]) => void) => Promise<any> | any;
50+
down: (db: Db, logger?: (level: SyslogLevels, ...args: any[]) => void) => Promise<any> | any;
5151
}
5252

5353
export class Migration {
@@ -266,7 +266,7 @@ export class Migration {
266266
this.options.logger('info',
267267
'Running ' + direction + '() on version ' + migration.version + maybeName());
268268

269-
await migration[direction](self.db, migration);
269+
await migration[direction](self.db, this.options.logger);
270270

271271
};
272272

0 commit comments

Comments
 (0)