1
1
'use strict' ;
2
2
3
- var _assert = require ( './helper/assert' ) ;
4
- var log = require ( 'db-migrate-shared' ) . log ;
5
- var mkdirp = require ( 'mkdirp' ) ;
6
- var fs = require ( 'fs' ) ;
7
- var optimist = require ( 'optimist' ) ;
8
- var util = require ( 'util' ) ;
3
+ const _assert = require ( './helper/assert' ) ;
4
+ const log = require ( 'db-migrate-shared' ) . log ;
5
+ const mkdirp = require ( 'mkdirp' ) ;
6
+ const fs = require ( 'fs' ) ;
7
+ const optimist = require ( 'optimist' ) ;
8
+ const util = require ( 'util' ) ;
9
9
10
10
function createMigrationDir ( dir , callback ) {
11
11
fs . stat ( dir , function ( err ) {
@@ -18,7 +18,8 @@ function createMigrationDir (dir, callback) {
18
18
}
19
19
20
20
function executeCreateMigration ( internals , config , callback ) {
21
- var migrationsDir = internals . argv [ 'migrations-dir' ] ;
21
+ let migrationsDir = internals . argv [ 'migrations-dir' ] ;
22
+ let folder , path ;
22
23
23
24
internals . runTimestamp = new Date ( ) ;
24
25
@@ -27,8 +28,6 @@ function executeCreateMigration (internals, config, callback) {
27
28
internals . argv [ 'migrations-dir' ] + '/' + internals . migrationMode ;
28
29
}
29
30
30
- var folder , path ;
31
-
32
31
if ( internals . argv . _ . length === 0 ) {
33
32
log . error ( "'migrationName' is required." ) ;
34
33
if ( ! internals . isModule ) {
@@ -43,8 +42,8 @@ function executeCreateMigration (internals, config, callback) {
43
42
}
44
43
45
44
createMigrationDir ( migrationsDir , function ( err ) {
46
- var index = require ( '../../connect' ) ;
47
- var Migration = require ( '../migration .js' ) ;
45
+ const index = require ( '../../connect' ) ;
46
+ const Migration = require ( '../template .js' ) ;
48
47
49
48
if ( err ) {
50
49
log . error ( 'Failed to create migration directory at ' , migrationsDir , err ) ;
@@ -64,12 +63,12 @@ function executeCreateMigration (internals, config, callback) {
64
63
if ( folder . length > 1 ) {
65
64
path += '/' ;
66
65
67
- for ( var i = 0 ; i < folder . length - 1 ; ++ i ) {
66
+ for ( let i = 0 ; i < folder . length - 1 ; ++ i ) {
68
67
path += folder [ i ] + '/' ;
69
68
}
70
69
}
71
70
72
- var templateType = Migration . TemplateType . DEFAULT_JS ;
71
+ let templateType = Migration . TemplateType . DEFAULT_JS ;
73
72
if (
74
73
shouldCreateSqlFiles ( internals , config ) &&
75
74
shouldCreateCoffeeFile ( internals , config )
@@ -85,7 +84,7 @@ function executeCreateMigration (internals, config, callback) {
85
84
} else if ( shouldCreateCoffeeFile ( internals , config ) ) {
86
85
templateType = Migration . TemplateType . DEFAULT_COFFEE ;
87
86
}
88
- var migration = new Migration (
87
+ const migration = new Migration (
89
88
internals . argv . title +
90
89
( shouldCreateCoffeeFile ( internals , config ) ? '.coffee' : '.js' ) ,
91
90
path ,
@@ -94,7 +93,7 @@ function executeCreateMigration (internals, config, callback) {
94
93
) ;
95
94
index . createMigration ( migration , function ( err , migration ) {
96
95
if ( _assert ( err , callback ) ) {
97
- log . info ( util . format ( 'Created migration at %s' , migration . path ) ) ;
96
+ log . info ( util . format ( 'Created migration at %s' , migration . file . path ) ) ;
98
97
if ( shouldCreateSqlFiles ( internals , config ) ) {
99
98
createSqlFiles ( internals , config , callback ) ;
100
99
} else {
@@ -120,17 +119,17 @@ function shouldCreateCoffeeFile (internals, config) {
120
119
}
121
120
122
121
function createSqlFiles ( internals , config , callback ) {
123
- var migrationsDir = internals . argv [ 'migrations-dir' ] ;
122
+ let migrationsDir = internals . argv [ 'migrations-dir' ] ;
124
123
125
124
if ( internals . migrationMode && internals . migrationMode !== 'all' ) {
126
125
migrationsDir =
127
126
internals . argv [ 'migrations-dir' ] + '/' + internals . migrationMode ;
128
127
}
129
128
130
- var sqlDir = migrationsDir + '/sqls' ;
129
+ const sqlDir = migrationsDir + '/sqls' ;
131
130
createMigrationDir ( sqlDir , function ( err ) {
132
- var index = require ( '../../connect' ) ;
133
- var Migration = require ( '../migration .js' ) ;
131
+ const index = require ( '../../connect' ) ;
132
+ const Migration = require ( '../template .js' ) ;
134
133
135
134
if ( err ) {
136
135
log . error ( 'Failed to create migration directory at ' , sqlDir , err ) ;
@@ -142,8 +141,8 @@ function createSqlFiles (internals, config, callback) {
142
141
}
143
142
}
144
143
145
- var templateTypeDefaultSQL = Migration . TemplateType . DEFAULT_SQL ;
146
- var migrationUpSQL = new Migration (
144
+ let templateTypeDefaultSQL = Migration . TemplateType . DEFAULT_SQL ;
145
+ const migrationUpSQL = new Migration (
147
146
internals . argv . title + '-up.sql' ,
148
147
sqlDir ,
149
148
internals . runTimestamp ,
@@ -152,10 +151,13 @@ function createSqlFiles (internals, config, callback) {
152
151
index . createMigration ( migrationUpSQL , function ( err , migration ) {
153
152
if ( _assert ( err , callback ) ) {
154
153
log . info (
155
- util . format ( 'Created migration up sql file at %s' , migration . path )
154
+ util . format (
155
+ 'Created migration up sql file at %s' ,
156
+ migration . file . path
157
+ )
156
158
) ;
157
159
158
- var migrationDownSQL = new Migration (
160
+ const migrationDownSQL = new Migration (
159
161
internals . argv . title + '-down.sql' ,
160
162
sqlDir ,
161
163
internals . runTimestamp ,
@@ -166,7 +168,7 @@ function createSqlFiles (internals, config, callback) {
166
168
log . info (
167
169
util . format (
168
170
'Created migration down sql file at %s' ,
169
- migration . path
171
+ migration . file . path
170
172
)
171
173
) ;
172
174
if ( typeof callback === 'function' ) callback ( ) ;
0 commit comments