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;
15+ use Versionable;
1416
1517 public function usingConnection ($ name , callable $ callback )
1618 {
@@ -29,15 +31,23 @@ public function usingConnection($name, callable $callback)
2931 * @param string $file
3032 * @param int $batch
3133 * @param bool $pretend
34+ *
35+ * @throws \Throwable
3236 */
3337 protected function runUp ($ file , $ batch , $ pretend )
3438 {
3539 // First we will resolve a "real" instance of the migration class from this
3640 // migration file name. Once we have the instances we can run the actual
3741 // command such as "up" or "down", or we can just simulate the action.
38- $ migration = $ this ->resolve (
39- $ name = $ this ->getMigrationName ($ file )
40- );
42+ if ($ this ->isLatestApp ()) {
43+ $ migration = $ this ->resolvePath ($ file );
44+
45+ $ name = $ this ->getMigrationName ($ file );
46+ } else {
47+ $ migration = $ this ->resolve (
48+ $ name = $ this ->getMigrationName ($ file )
49+ );
50+ }
4151
4252 if (! $ this ->allowEnvironment ($ migration )) {
4353 $ this ->note ("<info>Migrate:</info> {$ name } was skipped on this environment " );
@@ -80,9 +90,15 @@ protected function runUp($file, $batch, $pretend)
8090 */
8191 protected function runDown ($ file , $ migration , $ pretend )
8292 {
83- $ instance = $ this ->resolve (
84- $ name = $ this ->getMigrationName ($ file )
85- );
93+ if ($ this ->isLatestApp ()) {
94+ $ instance = $ this ->resolvePath ($ file );
95+
96+ $ name = $ this ->getMigrationName ($ file );
97+ } else {
98+ $ instance = $ this ->resolve (
99+ $ name = $ this ->getMigrationName ($ file )
100+ );
101+ }
86102
87103 if (! $ this ->allowEnvironment ($ instance )) {
88104 $ this ->note ("<info>Rolling back:</info> {$ name } was skipped on this environment " );
@@ -119,23 +135,23 @@ protected function runMigration($migration, $method)
119135 /**
120136 * Whether it is necessary to record information about the execution in the database.
121137 *
122- * @param object $migration
138+ * @param \DragonCode\Contracts\LaravelActions\Actionable| object $migration
123139 *
124140 * @return bool
125141 */
126- protected function allowLogging ($ migration ): bool
142+ protected function allowLogging (ActionableContract $ migration ): bool
127143 {
128144 return $ migration ->isOnce ();
129145 }
130146
131147 /**
132148 * Whether the action needs to be executed in the current environment.
133149 *
134- * @param object $migration
150+ * @param \DragonCode\Contracts\LaravelActions\Actionable| object $migration
135151 *
136152 * @return bool
137153 */
138- protected function allowEnvironment ($ migration ): bool
154+ protected function allowEnvironment (ActionableContract $ migration ): bool
139155 {
140156 $ environment = config ('app.env ' , 'production ' );
141157
@@ -165,7 +181,7 @@ protected function allowEnvironment($migration): bool
165181 *
166182 * @return bool
167183 */
168- protected function enabledTransactions ($ migration ): bool
184+ protected function enabledTransactions (ActionableContract $ migration ): bool
169185 {
170186 return $ migration ->enabledTransactions ();
171187 }
@@ -177,7 +193,7 @@ protected function enabledTransactions($migration): bool
177193 *
178194 * @return int
179195 */
180- protected function transactionAttempts ($ migration ): int
196+ protected function transactionAttempts (ActionableContract $ migration ): int
181197 {
182198 $ value = $ migration ->transactionAttempts ();
183199
0 commit comments