@@ -40,6 +40,12 @@ protected function configure()
4040 InputOption::VALUE_NONE ,
4141 'Skip execution of the schema files '
4242 )
43+ ->addOption (
44+ 'versions-path ' ,
45+ 'p ' ,
46+ InputOption::VALUE_REQUIRED ,
47+ 'Optional custom path to database versions directory '
48+ )
4349 ;
4450 }
4551
@@ -98,6 +104,21 @@ protected function execute(InputInterface $input, OutputInterface $output)
98104
99105 // 2. Check for current version and available version
100106
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+
101122 // what is the current version?
102123 $ query = $ runConf ->query ("SELECT `value` FROM `db_config` WHERE `key`='version' " );
103124 if ($ query ->rowCount ()) {
@@ -106,15 +127,16 @@ protected function execute(InputInterface $input, OutputInterface $output)
106127 } else {
107128 $ currentVersion = 0 ;
108129 }
130+ $ output ->writeln ('Current version: ' .$ currentVersion );
109131
110132 // what is the available version?
111133 $ availableVersion = 0 ;
112- $ versionsPath = realpath (dirname (__FILE__ ).'/../../../../../../db/versions ' );
113134 foreach (scandir ($ versionsPath ) as $ path ) {
114135 if (preg_match ("/^( \\d)+$/ " , $ path ) && (int ) $ path > $ availableVersion ) {
115136 $ availableVersion = (int ) $ path ;
116137 }
117138 }
139+ $ output ->writeln ('Available version: ' .$ availableVersion );
118140
119141 if ($ currentVersion >= $ availableVersion ) {
120142 $ output ->writeln ('<info>Database version is already up to date.</info> ' );
0 commit comments