@@ -34,6 +34,18 @@ protected function configure()
3434 InputArgument::OPTIONAL ,
3535 'Where is the MySQL binary located? '
3636 )
37+ ->addOption (
38+ 'no-schema ' ,
39+ null ,
40+ InputOption::VALUE_NONE ,
41+ 'Skip execution of the schema files '
42+ )
43+ ->addOption (
44+ 'versions-path ' ,
45+ 'p ' ,
46+ InputOption::VALUE_REQUIRED ,
47+ 'Optional custom path to database versions directory '
48+ )
3749 ;
3850 }
3951
@@ -59,7 +71,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
5971
6072 if (!$ buildConf instanceof \PDO ) {
6173 $ output ->writeln ('<error>Failed: unable to obtain a database connection.</error> ' );
62- return false ;
74+ return 1 ;
6375 }
6476
6577 if ($ buildConf ->query ("SHOW TABLES LIKE 'db_config' " )->rowCount ()) {
@@ -84,14 +96,29 @@ protected function execute(InputInterface $input, OutputInterface $output)
8496
8597 if (!$ result ) {
8698 $ output ->writeln ('<error>Installing version control failed.</error> ' );
87- return false ;
99+ return 1 ;
88100 }
89101
90102 $ output ->writeln ('<info>Installed version control successfully.</info> ' );
91103 }
92104
93105 // 2. Check for current version and available version
94106
107+ // what is the versions path?
108+ if ($ input ->getOption ('versions-path ' )) {
109+ $ versionsPath = $ input ->getOption ('versions-path ' );
110+ } else {
111+ $ versionsPath = realpath (dirname (__FILE__ ).'/../../../../../../db/versions ' );
112+ }
113+ if (!is_readable ($ versionsPath )) {
114+ $ output ->writeln ('<error>Versions path is not readable: ' .$ versionsPath .'</error> ' );
115+ return 1 ;
116+ }
117+ if (!is_dir ($ versionsPath )) {
118+ $ output ->writeln ('<error>Versions path is not a directory: ' .$ versionsPath .'</error> ' );
119+ return 1 ;
120+ }
121+
95122 // what is the current version?
96123 $ query = $ runConf ->query ("SELECT `value` FROM `db_config` WHERE `key`='version' " );
97124 if ($ query ->rowCount ()) {
@@ -100,19 +127,20 @@ protected function execute(InputInterface $input, OutputInterface $output)
100127 } else {
101128 $ currentVersion = 0 ;
102129 }
130+ $ output ->writeln ('Current version: ' .$ currentVersion );
103131
104132 // what is the available version?
105133 $ availableVersion = 0 ;
106- $ versionsPath = realpath (dirname (__FILE__ ).'/../../../../../../db/versions ' );
107134 foreach (scandir ($ versionsPath ) as $ path ) {
108135 if (preg_match ("/^( \\d)+$/ " , $ path ) && (int ) $ path > $ availableVersion ) {
109136 $ availableVersion = (int ) $ path ;
110137 }
111138 }
139+ $ output ->writeln ('Available version: ' .$ availableVersion );
112140
113141 if ($ currentVersion >= $ availableVersion ) {
114142 $ output ->writeln ('<info>Database version is already up to date.</info> ' );
115- return true ;
143+ return 0 ;
116144 }
117145
118146 $ noun = ($ availableVersion - $ currentVersion > 1 ) ? 'updates ' : 'update ' ;
@@ -122,7 +150,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
122150
123151 // go from current to latest version, building stack of SQL files
124152 $ filesToLookFor = [];
125- $ filesToLookFor [] = 'schema.sql ' ; // structural changes, alters, creates, drops
153+ if (!$ input ->getOption ('no-schema ' )) {
154+ $ filesToLookFor [] = 'schema.sql ' ; // structural changes, alters, creates, drops
155+ }
126156 $ filesToLookFor [] = 'data.sql ' ; // core data, inserts, replaces, updates, deletes
127157 if (in_array ($ this ->env , DbConfig::getTestingEnvironments ())) {
128158 $ filesToLookFor [] = 'testing.sql ' ; // extra data on top of data.sql for the testing environment(s)
@@ -225,11 +255,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
225255
226256 if ($ result ) {
227257 $ output ->writeln ('<info>Database updates installed successfully.</info> ' );
228- return true ;
258+ return 0 ;
229259
230260 } else {
231261 $ output ->writeln ('<error>Installing database updates failed.</error> ' );
232- return false ;
262+ return 1 ;
233263 }
234264 }
235265}
0 commit comments