Skip to content

Commit 3c51af0

Browse files
committed
Extend startup with logging and failure handling on 0.9.x versions
Before this patch users may ran into a local installation older than 0.9.x, this patch ensures that the version is compatible to be preffered over the global version. If the local version is to old (<0.10.0) the global version will be used instead. If this is the case a warn message gets displayed to the user. Additionally added informational logging within the verbose mode if a local version gets preferred. solves #317
1 parent f424e9e commit 3c51af0

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

bin/db-migrate

+23-10
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,36 @@
11
#!/usr/bin/env node
22

33
var resolve = require( 'resolve' );
4+
var log = require( '../lib/log.js' );
45

56
process.title = 'db-migrate';
67

8+
if ( process.argv.indexOf( '--verbose' ) !== -1 || process.argv.indexOf( '-v' ) !== -1 )
9+
global.verbose = true;
10+
711
resolve( 'db-migrate', {
812

9-
basedir: process.cwd()
13+
basedir: process.cwd()
1014
}, function ( error, localModule ) {
1115

12-
var DBMigrate, dbmigrate;
16+
var DBMigrate, dbmigrate;
17+
18+
if ( error ) {
19+
DBMigrate = require( '../' );
20+
}
21+
else {
22+
DBMigrate = require( localModule );
23+
log.verbose( 'Detected and using the projects local version of db-migrate. ' +
24+
'\'' + localModule + '\'');
25+
}
26+
27+
if ( typeof( DBMigrate.getInstance ) !== 'function' ) {
28+
DBMigrate = require( '../' );
1329

14-
if ( error ) {
15-
DBMigrate = require( '../' );
16-
}
17-
else {
18-
DBMigrate = require( localModule );
19-
}
30+
log.warn( 'Using global instead of local detected version as you have a ' +
31+
'version older than 0.10.0 in your projects package.json!' );
32+
}
2033

21-
dbmigrate = DBMigrate.getInstance();
22-
dbmigrate.run();
34+
dbmigrate = DBMigrate.getInstance();
35+
dbmigrate.run();
2336
} );

0 commit comments

Comments
 (0)