@@ -13,6 +13,7 @@ import drop from './drop'
1313import dump from './dump'
1414import load from './load'
1515import truncate from './truncate'
16+ import checkStructure from './checkStructure'
1617
1718const argv = minimist ( process . argv . slice ( 2 ) )
1819
@@ -65,7 +66,7 @@ function initConfig(env) {
6566
6667 if ( environment ) {
6768 console . log ( 'Using environment:' , chalk . magenta ( environment ) )
68- config = config [ environment ] || config
69+ config = { ... config , ... config [ environment ] }
6970 }
7071
7172 if ( ! config ) {
@@ -80,7 +81,10 @@ function initConfig(env) {
8081 knexConfig : config ,
8182 env : environment ,
8283 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' ) ,
8488 docker :
8589 ( commander . docker !== undefined
8690 ? commander . docker
@@ -116,7 +120,7 @@ function invoke(env) {
116120 . action ( ( ) => {
117121 const config = initConfig ( env )
118122 return create ( config )
119- . then ( ( ) => console . log ( chalk . green ( ` Database created.` ) ) )
123+ . then ( ( ) => console . log ( chalk . green ( ' Database created.' ) ) )
120124 . catch ( exit )
121125 } )
122126
@@ -126,7 +130,7 @@ function invoke(env) {
126130 . action ( ( ) => {
127131 const config = initConfig ( env )
128132 return drop ( config )
129- . then ( ( ) => console . log ( chalk . green ( ` Database dropped.` ) ) )
133+ . then ( ( ) => console . log ( chalk . green ( ' Database dropped.' ) ) )
130134 . catch ( exit )
131135 } )
132136
@@ -136,7 +140,7 @@ function invoke(env) {
136140 . action ( ( ) => {
137141 const config = initConfig ( env )
138142 return dump ( config )
139- . then ( ( ) => console . log ( chalk . green ( ` Dump created.` ) ) )
143+ . then ( ( ) => console . log ( chalk . green ( ' Dump created.' ) ) )
140144 . catch ( exit )
141145 } )
142146
@@ -146,7 +150,24 @@ function invoke(env) {
146150 . action ( ( ) => {
147151 const config = initConfig ( env )
148152 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+ } )
150171 . catch ( exit )
151172 } )
152173
0 commit comments