Skip to content

Commit f868bbb

Browse files
JesusJesus
Jesus
authored and
Jesus
committed
Adding migrations scrips directory as optional parameter
1 parent d5be41e commit f868bbb

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Down migrations are run in reverse run order.
1414
Options:
1515
--datasource specify database name (optional, default: db)
1616
--since specify date to run migrations from (options, default: run all migrations)
17+
--directory specify directory where migration scripts will live (options, default: '/server/migrations/'). A trailing slash is added at the end if not present
1718
```
1819

1920
<h2>Using the CLI directly</h2>
@@ -27,6 +28,11 @@ Run all new migrations since 01012014 that have not previously been run, using d
2728
NODE_ENV=qa ./node_modules/loopback-db-migrate/loopback-db-migrate.js up --datasource my_db_name --since 01012014
2829
```
2930

31+
Run all migrations living in the '/server/schema-migrations/' directory that have not previously been run, using datasource.json and database 'db'.
32+
```javascript
33+
./node_modules/loopback-db-migrate/loopback-db-migrate.js up --directory /server/schema-migrations/
34+
```
35+
3036
<h2>Using the CLI with npm by updating your package.json</h2>
3137
```javascript
3238
"scripts": {
@@ -62,4 +68,4 @@ module.exports = {
6268
dataSource.connector.query('DROP TABLE `my_table`;', next);
6369
}
6470
};
65-
```
71+
```

loopback-db-migrate.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ var fs = require('fs'),
77
dbName = (dbNameFlag > -1) ? process.argv[dbNameFlag + 1] : 'db',
88
dateSinceFlag = process.argv.indexOf('--since'),
99
dateSinceFilter = (dateSinceFlag > -1) ? process.argv[dateSinceFlag + 1] : '',
10-
migrationsFolder = process.cwd() + '/server/migrations/',
10+
migrationsFolderFlag = process.argv.indexOf('--directory'),
11+
migrationsFolder = process.cwd() + ( migrationsFolderFlag > -1 ? process.argv[migrationsFolderFlag + 1].replace(/\/?$/, '/') : '/server/migrations/'),
1112
dbMigrationsFolder = migrationsFolder+dbName,
1213
datasource = require(process.cwd() + '/server/server.js').dataSources[dbName];
1314

0 commit comments

Comments
 (0)