2525class RunMigrationsCommand extends Command {
2626 /**
2727 *
28- * @var MigrationsRunner
28+ * @var SchemaRunner
2929 */
3030 private $ migrationsRunner ;
3131 /**
@@ -48,15 +48,15 @@ public function __construct() {
4848 * Checks if the argument '--ini' is provided or not and initialize
4949 * migrations table if provided.
5050 *
51- * @param MigrationsRunner |null $runner An optional instance which will be
51+ * @param SchemaRunner |null $runner An optional instance which will be
5252 * used to run the migrations. If provided, the table will be created based
5353 * on the connection of the runner.
5454 *
5555 * @return bool If the argument '--ini' is not provided, true is returned.
5656 * Other than that, an attempt to create the migrations table will be made.
5757 * If created, true is returned. Other than that, false is returned.
5858 */
59- private function checkMigrationsTable (?MigrationsRunner $ runner , $ conn = null ) {
59+ private function checkMigrationsTable (?SchemaRunner $ runner , $ conn = null ) {
6060 if (!$ this ->isArgProvided ('--ini ' )) {
6161 return 0 ;
6262 }
@@ -67,9 +67,9 @@ private function checkMigrationsTable(?MigrationsRunner $runner, $conn = null) {
6767
6868 try {
6969 $ this ->println ("Initializing migrations table... " );
70- $ temp = $ runner !== null ? $ runner : new MigrationsRunner ( APP_PATH , '\\' . APP_DIR , $ conn );
70+ $ temp = $ runner !== null ? $ runner : new SchemaRunner ( $ conn );
7171
72- $ temp ->createMigrationsTable ();
72+ $ temp ->createSchemaTable ();
7373 $ this ->success ("Migrations table succesfully created. " );
7474 } catch (\Throwable $ ex ) {
7575 $ this ->error ('Unable to create migrations table due to following: ' );
@@ -80,11 +80,11 @@ private function checkMigrationsTable(?MigrationsRunner $runner, $conn = null) {
8080 }
8181 return 0 ;
8282 }
83- private function getNS (?MigrationsRunner $ runner = null ) {
83+ private function getNS (?SchemaRunner $ runner = null ) {
8484 if ($ this ->isArgProvided ('--ns ' )) {
8585 return $ this ->getArgValue ('--ns ' );
8686 } else if ($ runner !== null ) {
87- return $ runner -> getMigrationsNamespace ();
87+ // Removed getMigrationsNamespace() call as it doesn't exist in SchemaRunner
8888 } else {
8989 $ this ->info ("Using default namespace for migrations. " );
9090 return '\\' .APP_DIR .'\\database \\migrations ' ;
@@ -100,7 +100,7 @@ public function exec() : int {
100100
101101 $ runner = $ this ->getRunnerArg ();
102102
103- if (!($ runner instanceof MigrationsRunner ) && $ runner !== null ) {
103+ if (!($ runner instanceof SchemaRunner ) && $ runner !== null ) {
104104 return -1 ;
105105 }
106106 $ ns = $ this ->getNS ($ runner );
@@ -120,7 +120,7 @@ public function exec() : int {
120120
121121
122122 try {
123- $ runner = new MigrationsRunner ( ROOT_PATH . DS . str_replace ( '\\' , DS , $ ns ), $ ns , $ connection );
123+ $ runner = new SchemaRunner ( $ connection );
124124 } catch (Throwable $ ex ) {
125125 $ this ->error ($ ex ->getMessage ());
126126 return -1 ;
@@ -131,7 +131,7 @@ public function exec() : int {
131131 return $ this ->executeMigrations ($ runner );
132132 }
133133 }
134- private function rollbackMigration (MigrationsRunner $ runner ) {
134+ private function rollbackMigration (SchemaRunner $ runner ) {
135135 $ isAll = $ this ->isArgProvided ('--all ' );
136136 $ rolledCount = 0 ;
137137 if ($ isAll ) {
@@ -158,9 +158,9 @@ private function rollbackMigration(MigrationsRunner $runner) {
158158
159159 return 0 ;
160160 }
161- private function doRollback (MigrationsRunner $ runner ) {
161+ private function doRollback (SchemaRunner $ runner ) {
162162 try {
163- return $ runner ->rollback ( );
163+ return $ runner ->rollbackUpTo ( null );
164164
165165 } catch (Throwable $ ex ) {
166166 $ this ->error ('Failed to execute migration due to following: ' );
@@ -175,7 +175,7 @@ private function printInfo(?AbstractMigration $migration, &$rolledCount = 0) {
175175 $ this ->success ("Migration ' " .$ migration ->getName ()."' was successfully rolled back. " );
176176 }
177177 }
178- private function executeMigrations (MigrationsRunner $ runner ) {
178+ private function executeMigrations (SchemaRunner $ runner ) {
179179 $ this ->println ("Starting to execute migrations... " );
180180 $ listOfApplied = [];
181181 while ($ this ->applyNext ($ runner , $ listOfApplied )){};
@@ -202,12 +202,12 @@ private function executeMigrations(MigrationsRunner $runner) {
202202 * ask the user to select a connection from the connections which
203203 * exist in application configuration.
204204 *
205- * @param MigrationsRunner |null $runner If given and the connection is set
205+ * @param SchemaRunner |null $runner If given and the connection is set
206206 * on the instance, it will be returned.
207207 *
208208 * @return ConnectionInfo|null
209209 */
210- private function getDBConnection (?MigrationsRunner $ runner = null ) {
210+ private function getDBConnection (?SchemaRunner $ runner = null ) {
211211
212212 if ($ runner !== null ) {
213213 if ($ runner ->getConnectionInfo () !== null ) {
@@ -232,8 +232,8 @@ private function getDBConnection(?MigrationsRunner $runner = null) {
232232 return CLIUtils::getConnectionName ($ this );
233233 }
234234 }
235- public function getNext (MigrationsRunner $ runner ) : ?AbstractMigration {
236- foreach ($ runner ->getMigrations () as $ m ) {
235+ public function getNext (SchemaRunner $ runner ) : ?AbstractMigration {
236+ foreach ($ runner ->getChanges () as $ m ) {
237237 if ($ runner ->isApplied ($ m ->getName ())) {
238238 continue ;
239239 } else {
@@ -242,7 +242,7 @@ public function getNext(MigrationsRunner $runner) : ?AbstractMigration {
242242 }
243243 return null ;
244244 }
245- private function applyNext (MigrationsRunner $ runner , &$ listOfApplied ) : bool {
245+ private function applyNext (SchemaRunner $ runner , &$ listOfApplied ) : bool {
246246 $ toBeApplied = $ this ->getNext ($ runner );
247247
248248 try {
@@ -274,7 +274,7 @@ private function applyNext(MigrationsRunner $runner, &$listOfApplied) : bool {
274274 }
275275 /**
276276 *
277- * @return MigrationsRunner |int|null
277+ * @return SchemaRunner |int|null
278278 */
279279 private function getRunnerArg () {
280280 $ runner = $ this ->getArgValue ('--runner ' );
@@ -291,8 +291,8 @@ private function getRunnerArg() {
291291 return -1 ;
292292 }
293293
294- if (!($ runnerInst instanceof MigrationsRunner )) {
295- $ this ->error ('The argument --runner has invalid value: " ' .$ runner .'" is not an instance of "MigrationsRunner ". ' );
294+ if (!($ runnerInst instanceof SchemaRunner )) {
295+ $ this ->error ('The argument --runner has invalid value: " ' .$ runner .'" is not an instance of "SchemaRunner ". ' );
296296 return -1 ;
297297 } else {
298298 return $ runnerInst ;
@@ -311,9 +311,9 @@ private function hasConnections() : bool {
311311 return true ;
312312 }
313313 private function hasMigrations (string $ namespace ) : bool {
314- $ tmpRunner = new MigrationsRunner ( ROOT_PATH . DS . str_replace ( '\\' , DS , $ namespace ), $ namespace , null );
314+ $ tmpRunner = new SchemaRunner ( null );
315315 $ this ->println ("Checking namespace ' $ namespace' for migrations... " );
316- $ count = count ($ tmpRunner ->getMigrations ());
316+ $ count = count ($ tmpRunner ->getChanges ());
317317 if ($ count == 0 ) {
318318 $ this ->info ("No migrations found in the namespace ' $ namespace'. " );
319319 return false ;
0 commit comments