@@ -23,7 +23,7 @@ class SyncMigrateCommand extends BaseCommand
2323 *
2424 * @var string
2525 */
26- protected $ signature = 'migrate:sync ' ;
26+ protected $ signature = 'migrate:sync {file?} ' ;
2727 /**
2828 * The console command description.
2929 *
@@ -53,17 +53,44 @@ public function __construct(Migrator $migrator)
5353 */
5454 public function handle ()
5555 {
56- $ files = $ this ->migrator ->getMigrationFiles ($ this ->getMigrationPaths ());
5756
58- foreach ($ files as $ file ) {
57+ //if file option is given.
58+ $ file = $ this ->argument ('file ' );
59+ if (!empty ($ file )) {
60+ $ file = rtrim ($ file , '.php ' ) . '.php ' ;
61+ $ fileExists = true ;
62+ if (!file_exists ($ file )) {
63+ $ fileExists = false ;
64+ foreach ($ this ->getMigrationPaths () as $ path ) {
65+ if (file_exists ($ path . '/ ' . $ file )) {
66+ $ file = $ path . '/ ' . $ file ;
67+ $ fileExists = true ;
68+ break ;
69+ }
70+ }
71+ }
72+
73+ if (!$ fileExists ) {
74+ $ this ->error ("File not found: $ file " );
75+ return ;
76+ }
77+
5978 $ this ->processMigration (file_get_contents ($ file ));
79+ } else {
80+ $ files = $ this ->migrator ->getMigrationFiles ($ this ->getMigrationPaths ());
81+
82+ foreach ($ files as $ file ) {
83+ $ this ->processMigration (file_get_contents ($ file ));
84+ }
6085 }
6186
6287 $ this ->abondedTables ()->each (function ($ table ) {
6388 $ this ->error ("Schemas doesn't have table <fg=black;bg=white> {$ table } </> seems you have delete it " );
6489
65- $ this ->confirm ("Do you want to drop <fg=black;bg=white> {$ table } </> ? " ,
66- true ) && LaravelSchema::dropIfExists ($ table );
90+ $ this ->confirm (
91+ "Do you want to drop <fg=black;bg=white> {$ table } </> ? " ,
92+ true
93+ ) && LaravelSchema::dropIfExists ($ table );
6794 })->isEmpty () && $ this ->syncedOrNot ();
6895
6996 }
@@ -76,7 +103,7 @@ protected function syncedOrNot()
76103 protected function tables ()
77104 {
78105 return Collection::make (DB ::select ('SHOW TABLES ' ))->map (function ($ table ) {
79- return array_values ((array )$ table );
106+ return array_values ((array ) $ table );
80107 })->flatten ();
81108 }
82109
0 commit comments