@@ -70,11 +70,13 @@ private function createMigrationsTable() : bool {
7070 * Other than that, an attempt to create the migrations table will be made.
7171 * If created, true is returned. Other than that, false is returned.
7272 */
73- private function checkMigrationsTable (?MigrationsRunner $ runner ) {
73+ private function checkMigrationsTable (?MigrationsRunner $ runner, $ conn = null ) {
7474 if (!$ this ->isArgProvided ('--ini ' )) {
7575 return 0 ;
7676 }
77- $ conn = $ this ->getDBConnection ($ runner );
77+ if ($ conn === null ) {
78+ $ conn = $ this ->getDBConnection ($ runner );
79+ }
7880 if ($ conn !== null ) {
7981 $ temp = $ runner !== null ? $ runner : new MigrationsRunner (APP_PATH , '\\' .APP_DIR , $ conn );
8082 try {
@@ -108,23 +110,26 @@ private function getNS(?MigrationsRunner $runner = null) {
108110 public function exec () : int {
109111
110112 $ runner = $ this ->getRunnerArg ();
113+
111114 if (!($ runner instanceof MigrationsRunner) && $ runner !== null ) {
112115 return -1 ;
113116 }
114117 $ ns = $ this ->getNS ($ runner );
115- if ($ this ->checkMigrationsTable ($ runner ) == -1 ) {
116- return -1 ;
117- }
118-
118+
119119 if (!$ this ->hasMigrations ($ ns )) {
120120 return 0 ;
121121 }
122122
123123 $ connection = $ this ->getDBConnection ($ runner );
124-
125124 if (!($ connection instanceof ConnectionInfo)) {
126125 return -1 ;
127126 }
127+
128+ if ($ this ->checkMigrationsTable ($ runner , $ connection ) == -1 ) {
129+ return -1 ;
130+ }
131+
132+
128133 try {
129134 $ runner = new MigrationsRunner (ROOT_PATH .DS . str_replace ('\\' , DS , $ ns ), $ ns , $ connection );
130135 } catch (Throwable $ ex ) {
@@ -191,7 +196,7 @@ private function getDBConnection(?MigrationsRunner $runner = null) {
191196 }
192197 private function applyNext (MigrationsRunner $ runner , &$ listOfApplied ) : bool {
193198 try {
194- $ this ->println ("Executing migration... " );
199+ // $this->println("Executing migration...");
195200 $ applied = $ runner ->applyOne ();
196201
197202 if ($ applied !== null ) {
@@ -203,7 +208,7 @@ private function applyNext(MigrationsRunner $runner, &$listOfApplied) : bool {
203208 }
204209 } catch (Throwable $ ex ) {
205210 $ this ->error ('Failed to execute migration due to following: ' );
206- $ this ->println ($ ex ->getMessage ().' at line ' .$ ex ->getLine ());
211+ $ this ->println ($ ex ->getMessage ().' (Line ' .$ ex ->getLine (). ' ) ' );
207212 $ this ->warning ('Execution stopped. ' );
208213 return false ;
209214 }
0 commit comments