1- <?php  namespace  Mitch \LaravelDoctrine \Console ;  
1+ <?php  namespace  Mitch \LaravelDoctrine \Console ;
22
33use  Illuminate \Console \Command ;
44use  Doctrine \ORM \Tools \SchemaTool ;
5- use  Doctrine \ORM \ Mapping \ ClassMetadataFactory ;
5+ use  Doctrine \Common \ Persistence \ ManagerRegistry ;
66use  Symfony \Component \Console \Input \InputOption ;
77
88class  SchemaUpdateCommand extends  Command
@@ -29,18 +29,18 @@ class SchemaUpdateCommand extends Command
2929    private  $ tool ;
3030
3131    /** 
32-      * The class metadata factory  
33-      * 
34-      * @var \Doctrine\ORM\Tools\SchemaTool  
35-      */ 
36-     private  $ metadata  ;
32+        * The ManagerRegistry  
33+        * 
34+        * @var \Doctrine\Common\Persistence\ManagerRegistry  
35+        */ 
36+     private  $ registry  ;
3737
38-     public  function  __construct (SchemaTool   $ tool , ClassMetadataFactory   $ metadata  )
38+     public  function  __construct (SchemaTool   $ tool , ManagerRegistry   $ registry  )
3939    {
4040        parent ::__construct ();
4141
4242        $ this  ->tool  = $ tool ;
43-         $ this  ->metadata  = $ metadata  ;
43+         $ this  ->registry  = $ registry  ;
4444    }
4545
4646    /** 
@@ -52,18 +52,21 @@ public function fire()
5252    {
5353        $ this  ->info ('Checking if database needs updating.... ' );
5454        $ clean  = $ this  ->option ('clean ' );
55-         $ sql  = $ this  ->tool ->getUpdateSchemaSql ($ this  ->metadata ->getAllMetadata (), $ clean );
56-         if  (empty ($ sql )) {
57-             $ this  ->info ('No updates found. ' );
58-             return ;
59-         }
60-         if  ($ this  ->option ('sql ' )) {
61-             $ this  ->info ('Outputting update query: ' );
62-             $ this  ->info (implode ('; '  . PHP_EOL , $ sql ));
63-         } else  {
64-             $ this  ->info ('Updating database schema.... ' );
65-             $ this  ->tool ->updateSchema ($ this  ->metadata ->getAllMetadata ());
66-             $ this  ->info ('Schema has been updated! ' );
55+         foreach  ($ this  ->registry ->getManagerNames () as  $ key  => $ value ) {
56+             $ manager  = $ this  ->registry ->getManager ($ key );
57+             $ sql  = $ this  ->tool ->getUpdateSchemaSql ($ manager ->getMetadataFactory ()->getAllMetadata (), $ clean );
58+             if  (empty ($ sql )) {
59+                 $ this  ->info ('No updates found. ' );
60+                 continue ;
61+             }
62+             if  ($ this  ->option ('sql ' )) {
63+                 $ this  ->info ('Outputting update query: ' );
64+                 $ this  ->info (implode ('; '  . PHP_EOL , $ sql ));
65+             } else  {
66+                 $ this  ->info ('Updating database schema.... ' );
67+                 $ this  ->tool ->updateSchema ($ this  ->metadata ->getAllMetadata ());
68+                 $ this  ->info ('Schema has been updated! ' );
69+             }
6770        }
6871    }
6972
@@ -75,4 +78,3 @@ protected function getOptions()
7578        ];
7679    }
7780}
78- 
0 commit comments