@@ -27,12 +27,10 @@ public function runPending(array $migrations, array $options = []): void
27
27
28
28
$ batch = $ this ->repository ->getNextBatchNumber ();
29
29
30
- $ pretend = $ options ['pretend ' ] ?? false ;
31
-
32
30
$ step = $ options ['step ' ] ?? false ;
33
31
34
32
foreach ($ migrations as $ file ) {
35
- $ this ->patch ($ file , $ batch, $ pretend );
33
+ $ this ->patch ($ file , $ batch );
36
34
37
35
if ($ step ) {
38
36
$ batch ++;
@@ -45,40 +43,60 @@ public function runPending(array $migrations, array $options = []): void
45
43
*
46
44
* @param string $file
47
45
* @param int $batch
48
- * @param bool $pretend
49
- *
50
46
* @return void
51
47
* @throws \Throwable
52
48
*/
53
- protected function patch (string $ file , int $ batch, bool $ pretend ): void
49
+ protected function patch (string $ file , int $ batch ): void
54
50
{
55
- $ migration = $ this ->resolvePath ($ file );
51
+ $ patch = $ this ->resolvePath ($ file );
56
52
57
53
$ name = $ this ->getMigrationName ($ file );
58
54
59
- $ migration ->setContainer (app ())->setCommand (app ('command.patcher ' ));
60
-
61
- $ this ->note ("<comment>Patching:</comment> {$ name }" );
55
+ $ this ->note ("<comment>Patching:</comment> $ name " );
62
56
63
57
$ startTime = microtime (true );
64
58
65
- $ this ->runPatch ($ migration );
59
+ if ($ patch instanceof Patch && $ this ->isEligible ($ patch )) {
60
+ $ patch
61
+ ->setContainer (app ())
62
+ ->setCommand (app ('command.patcher ' ))
63
+ ->setLogger (app ('log ' )->driver (PatcherServiceProvider::$ LOG_CHANNEL ));
64
+
65
+ $ this ->runPatch ($ patch );
66
66
67
- $ runTime = round (microtime (true ) - $ startTime , 2 );
67
+ $ runTime = round (microtime (true ) - $ startTime , 2 );
68
+
69
+ $ this ->repository ->log ($ name , $ batch );
70
+
71
+ $ this ->note ("<info>Patched:</info> $ name ( $ runTime seconds). " );
72
+ } else {
73
+ $ this ->note ("<comment>Skipped:</comment> $ name is not eligible to run in current condition. " );
74
+ }
75
+ }
68
76
69
- $ this ->repository ->log ($ name , $ batch );
77
+ /**
78
+ * Determine if patcher should run.
79
+ *
80
+ * @param \Dentro\Patcher\Patch $patch
81
+ * @return bool
82
+ */
83
+ public function isEligible (Patch $ patch ): bool
84
+ {
85
+ if (method_exists ($ patch , 'eligible ' )) {
86
+ return $ patch ->eligible ();
87
+ }
70
88
71
- $ this -> note ( " <info>Patched:</info> { $ name } ( { $ runTime } seconds) " ) ;
89
+ return true ;
72
90
}
73
91
74
92
/**
75
93
* Run a migration inside a transaction if the database supports it.
76
94
*
77
- * @param object $patch
95
+ * @param \Dentro\Patcher\Patch $patch
78
96
* @return void
79
97
* @throws \Throwable
80
98
*/
81
- protected function runPatch (object $ patch ): void
99
+ protected function runPatch (Patch $ patch ): void
82
100
{
83
101
$ connection = $ this ->resolveConnection (
84
102
$ patch ->getConnection ()
@@ -102,9 +120,11 @@ protected function runPatch(object $patch): void
102
120
}
103
121
};
104
122
105
- $ this ->getSchemaGrammar ($ connection )->supportsSchemaTransactions ()
106
- && $ patch ->withinTransaction
107
- ? $ connection ->transaction ($ callback )
108
- : $ callback ();
123
+ if ($ patch ->withinTransaction && $ this ->getSchemaGrammar ($ connection )->supportsSchemaTransactions ()) {
124
+ $ connection ->transaction ($ callback );
125
+ return ;
126
+ }
127
+
128
+ $ callback ();
109
129
}
110
130
}
0 commit comments