1
+ <?php
2
+ namespace ChrisHalbert \LaravelNomadic ;
3
+
4
+ use Illuminate \Database \Migrations \Migrator ;
5
+ use ChrisHalbert \LaravelNomadic \NomadicRepositoryInterface ;
6
+
7
+
8
+ use Illuminate \Filesystem \Filesystem ;
9
+ use Illuminate \Database \ConnectionResolverInterface as Resolver ;
10
+
11
+ class NomadicMigrator extends Migrator
12
+ {
13
+ /**
14
+ * The migration repository implementation.
15
+ *
16
+ * @var \Illuminate\Database\Migrations\MigrationRepositoryInterface
17
+ */
18
+ protected $ repository ;
19
+
20
+ /**
21
+ * Create a new migrator instance.
22
+ *
23
+ * @param NomadicRepositoryInterface $repository
24
+ * @param \Illuminate\Database\ConnectionResolverInterface $resolver
25
+ * @param \Illuminate\Filesystem\Filesystem $files
26
+ * @return void
27
+ */
28
+ public function __construct (NomadicRepositoryInterface $ repository ,
29
+ Resolver $ resolver ,
30
+ Filesystem $ files )
31
+ {
32
+ $ this ->files = $ files ;
33
+ $ this ->resolver = $ resolver ;
34
+ $ this ->repository = $ repository ;
35
+ }
36
+
37
+ /**
38
+ * Run "up" a migration instance.
39
+ *
40
+ * @param string $file
41
+ * @param int $batch
42
+ * @param bool $pretend
43
+ * @return void
44
+ */
45
+ protected function runUp ($ file , $ batch , $ pretend )
46
+ {
47
+ // First we will resolve a "real" instance of the migration class from this
48
+ // migration file name. Once we have the instances we can run the actual
49
+ // command such as "up" or "down", or we can just simulate the action.
50
+ $ migration = $ this ->resolve (
51
+ $ name = $ this ->getMigrationName ($ file )
52
+ );
53
+
54
+ if ($ pretend ) {
55
+ return $ this ->pretendToRun ($ migration , 'up ' );
56
+ }
57
+
58
+ $ this ->note ("<comment>Migrating:</comment> {$ name }" );
59
+
60
+ $ this ->runMigration ($ migration , 'up ' );
61
+
62
+ // Once we have run a migrations class, we will log that it was run in this
63
+ // repository so that we don't try to run it next time we do a migration
64
+ // in the application. A migration repository keeps the migrate order.
65
+ $ this ->repository ->log ($ name , $ batch , $ migration ->getProperties ());
66
+
67
+ $ this ->note ("<info>Migrated:</info> {$ name }" );
68
+ }
69
+ }
0 commit comments