Skip to content

Commit 8874fa6

Browse files
committed
add command line option for v2 template
Signed-off-by: Tobias Gurtzick <[email protected]>
1 parent 8124786 commit 8874fa6

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

lib/commands/create-migration.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,9 @@ async function executeCreateMigration (internals, config) {
8282
templateType = Migration.TemplateType.SQL_FILE_LOADER;
8383
} else if (shouldCreateCoffeeFile(internals, config)) {
8484
templateType = Migration.TemplateType.DEFAULT_COFFEE;
85+
} else if (shouldCreateV2File(internals, config)) {
86+
templateType = Migration.TemplateType.V2_DEFAULT;
8587
}
86-
8788
if (plugins) {
8889
hooks = plugins.hook('create:template') || [];
8990
}
@@ -173,6 +174,10 @@ function shouldCreateCoffeeFile (internals, config) {
173174
return internals.argv['coffee-file'] || config['coffee-file'];
174175
}
175176

177+
function shouldCreateV2File (internals, config) {
178+
return internals.argv['v2-file'] || config['v2-file'];
179+
}
180+
176181
async function createSqlFiles (internals, config) {
177182
let migrationsDir = internals.argv['migrations-dir'];
178183

lib/commands/set-default-argv.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ module.exports = function (internals, isModule) {
6464
.boolean('version')
6565
.describe('config', 'Location of the database.json file.')
6666
.string('config')
67+
.describe('v2-file', 'Create v2 schema migration')
68+
.boolean('v2-file')
6769
.describe(
6870
'sql-file',
6971
'Automatically create two sql files for up and down statements in ' +

lib/template.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,8 @@ Template.TemplateType = {
258258
SQL_FILE_LOADER: 2,
259259
DEFAULT_COFFEE: 3,
260260
COFFEE_SQL_FILE_LOADER: 4,
261-
SQL_FILE_LOADER_IGNORE_ON_INIT: 5
261+
SQL_FILE_LOADER_IGNORE_ON_INIT: 5,
262+
V2_DEFAULT: 6
262263
};
263264

264265
Template.prototype.getTemplate = function () {
@@ -277,6 +278,8 @@ Template.prototype.getTemplate = function () {
277278
return this.sqlFileLoaderIgnoreOnInitTemplate();
278279
case Template.TemplateType.DEFAULT_JS:
279280
return this.defaultJsTemplate();
281+
case Template.TemplateType.V2_DEFAULT:
282+
return require('./templates/v2.js')();
280283
default:
281284
if (this.plugins) {
282285
plugin = this.plugins.overwrite(

lib/templates/v2.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use strict';
2+
3+
module.exports = () => `'use strict';
4+
5+
exports.migrate = async (db, opt) => {
6+
const type = opt.dbm.dataType;
7+
return null;
8+
};
9+
10+
exports._meta = {
11+
version: 2
12+
};`;

0 commit comments

Comments
 (0)