@@ -13,6 +13,7 @@ import drop from './drop'
13
13
import dump from './dump'
14
14
import load from './load'
15
15
import truncate from './truncate'
16
+ import checkStructure from './checkStructure'
16
17
17
18
const argv = minimist ( process . argv . slice ( 2 ) )
18
19
@@ -65,7 +66,7 @@ function initConfig(env) {
65
66
66
67
if ( environment ) {
67
68
console . log ( 'Using environment:' , chalk . magenta ( environment ) )
68
- config = config [ environment ] || config
69
+ config = { ... config , ... config [ environment ] }
69
70
}
70
71
71
72
if ( ! config ) {
@@ -80,7 +81,10 @@ function initConfig(env) {
80
81
knexConfig : config ,
81
82
env : environment ,
82
83
structurePath : knexScriptsConfig . structurePath || 'db/structure.sql' ,
83
- migrationsPath : join ( process . cwd ( ) , 'migrations' ) ,
84
+ migrationsPath :
85
+ config . migrations && config . migrations . directory
86
+ ? config . migrations . directory
87
+ : join ( process . cwd ( ) , 'migrations' ) ,
84
88
docker :
85
89
( commander . docker !== undefined
86
90
? commander . docker
@@ -116,7 +120,7 @@ function invoke(env) {
116
120
. action ( ( ) => {
117
121
const config = initConfig ( env )
118
122
return create ( config )
119
- . then ( ( ) => console . log ( chalk . green ( ` Database created.` ) ) )
123
+ . then ( ( ) => console . log ( chalk . green ( ' Database created.' ) ) )
120
124
. catch ( exit )
121
125
} )
122
126
@@ -126,7 +130,7 @@ function invoke(env) {
126
130
. action ( ( ) => {
127
131
const config = initConfig ( env )
128
132
return drop ( config )
129
- . then ( ( ) => console . log ( chalk . green ( ` Database dropped.` ) ) )
133
+ . then ( ( ) => console . log ( chalk . green ( ' Database dropped.' ) ) )
130
134
. catch ( exit )
131
135
} )
132
136
@@ -136,7 +140,7 @@ function invoke(env) {
136
140
. action ( ( ) => {
137
141
const config = initConfig ( env )
138
142
return dump ( config )
139
- . then ( ( ) => console . log ( chalk . green ( ` Dump created.` ) ) )
143
+ . then ( ( ) => console . log ( chalk . green ( ' Dump created.' ) ) )
140
144
. catch ( exit )
141
145
} )
142
146
@@ -146,7 +150,24 @@ function invoke(env) {
146
150
. action ( ( ) => {
147
151
const config = initConfig ( env )
148
152
return load ( config )
149
- . then ( ( ) => console . log ( chalk . green ( `Database loaded.` ) ) )
153
+ . then ( ( ) => console . log ( chalk . green ( 'Database loaded.' ) ) )
154
+ . catch ( exit )
155
+ } )
156
+
157
+ commander
158
+ . command ( 'check-structure' )
159
+ . description ( 'Check structure.' )
160
+ . action ( ( ) => {
161
+ const config = initConfig ( env )
162
+ return checkStructure ( config )
163
+ . then ( upToDate => {
164
+ if ( upToDate ) {
165
+ console . log ( chalk . green ( 'Structure is up to date.' ) )
166
+ } else {
167
+ console . log ( chalk . red ( 'Structure is not up to date.' ) )
168
+ process . exit ( 1 )
169
+ }
170
+ } )
150
171
. catch ( exit )
151
172
} )
152
173
0 commit comments