44
55use DragonCode \Contracts \LaravelActions \Actionable as ActionableContract ;
66use DragonCode \LaravelActions \Concerns \Infoable ;
7+ use DragonCode \LaravelActions \Concerns \Versionable ;
78use Illuminate \Database \Migrations \Migrator as BaseMigrator ;
89use Illuminate \Support \Facades \DB ;
910use Throwable ;
1011
1112class Migrator extends BaseMigrator
1213{
1314 use Infoable;
14-
15- public function usingConnection ($ name , callable $ callback )
16- {
17- $ prev = $ this ->resolver ->getDefaultConnection ();
18-
19- $ this ->setConnection ($ name );
20-
21- return tap ($ callback (), function () use ($ prev ) {
22- $ this ->setConnection ($ prev );
23- });
24- }
15+ use Versionable;
2516
2617 /**
2718 * Run "up" a migration instance.
2819 *
2920 * @param string $file
3021 * @param int $batch
3122 * @param bool $pretend
23+ *
24+ * @throws \Throwable
3225 */
3326 protected function runUp ($ file , $ batch , $ pretend )
3427 {
3528 // First we will resolve a "real" instance of the migration class from this
3629 // migration file name. Once we have the instances we can run the actual
3730 // command such as "up" or "down", or we can just simulate the action.
38- $ migration = $ this ->resolve (
39- $ name = $ this ->getMigrationName ($ file )
40- );
31+ if ($ this ->isLatestApp ()) {
32+ $ migration = $ this ->resolvePath ($ file );
33+
34+ $ name = $ this ->getMigrationName ($ file );
35+ } else {
36+ $ migration = $ this ->resolve (
37+ $ name = $ this ->getMigrationName ($ file )
38+ );
39+ }
4140
4241 if (! $ this ->allowEnvironment ($ migration )) {
4342 $ this ->note ("<info>Migrate:</info> {$ name } was skipped on this environment " );
@@ -80,9 +79,15 @@ protected function runUp($file, $batch, $pretend)
8079 */
8180 protected function runDown ($ file , $ migration , $ pretend )
8281 {
83- $ instance = $ this ->resolve (
84- $ name = $ this ->getMigrationName ($ file )
85- );
82+ if ($ this ->isLatestApp ()) {
83+ $ instance = $ this ->resolvePath ($ file );
84+
85+ $ name = $ this ->getMigrationName ($ file );
86+ } else {
87+ $ instance = $ this ->resolve (
88+ $ name = $ this ->getMigrationName ($ file )
89+ );
90+ }
8691
8792 if (! $ this ->allowEnvironment ($ instance )) {
8893 $ this ->note ("<info>Rolling back:</info> {$ name } was skipped on this environment " );
@@ -119,23 +124,23 @@ protected function runMigration($migration, $method)
119124 /**
120125 * Whether it is necessary to record information about the execution in the database.
121126 *
122- * @param object $migration
127+ * @param \DragonCode\Contracts\LaravelActions\Actionable| object $migration
123128 *
124129 * @return bool
125130 */
126- protected function allowLogging ($ migration ): bool
131+ protected function allowLogging (ActionableContract $ migration ): bool
127132 {
128133 return $ migration ->isOnce ();
129134 }
130135
131136 /**
132137 * Whether the action needs to be executed in the current environment.
133138 *
134- * @param object $migration
139+ * @param \DragonCode\Contracts\LaravelActions\Actionable| object $migration
135140 *
136141 * @return bool
137142 */
138- protected function allowEnvironment ($ migration ): bool
143+ protected function allowEnvironment (ActionableContract $ migration ): bool
139144 {
140145 $ environment = config ('app.env ' , 'production ' );
141146
@@ -165,7 +170,7 @@ protected function allowEnvironment($migration): bool
165170 *
166171 * @return bool
167172 */
168- protected function enabledTransactions ($ migration ): bool
173+ protected function enabledTransactions (ActionableContract $ migration ): bool
169174 {
170175 return $ migration ->enabledTransactions ();
171176 }
@@ -177,7 +182,7 @@ protected function enabledTransactions($migration): bool
177182 *
178183 * @return int
179184 */
180- protected function transactionAttempts ($ migration ): int
185+ protected function transactionAttempts (ActionableContract $ migration ): int
181186 {
182187 $ value = $ migration ->transactionAttempts ();
183188
0 commit comments