@@ -64,6 +64,27 @@ public function refresh()
6464 Artisan::call ('migrate:fresh --force --drop-types --drop-views ' );
6565 }
6666
67+ /**
68+ * Rollback all database migrations
69+ */
70+ public function reset ()
71+ {
72+ // Require --force in production environments
73+ $ this ->forceChecker ();
74+
75+ $ force = (bool ) $ this ->option ('force ' );
76+
77+ $ migration = new Migration ();
78+ $ response = $ migration ->drop ($ force );
79+
80+ if ($ response ['status ' ] != Constant::STATUS_200 ) {
81+ $ this ->error ($ response ['message ' ]);
82+ return ;
83+ }
84+
85+ $ this ->info ($ response ['message ' ]);
86+ }
87+
6788 /**
6889 * Show the status of each migration
6990 */
@@ -92,11 +113,12 @@ public function status()
92113 return 0 ;
93114 }
94115
95- Logger::info ("Migration status: " );
116+ // Build a single table output
117+ $ rows = [];
96118 foreach ($ files as $ file ) {
97119 $ fullPath = $ migrationsDir . $ file ;
98120
99- // Try to detect created table from file content first
121+ // Detect created table from file content or filename
100122 $ table = null ;
101123 $ content = File::get ($ fullPath ) ?: '' ;
102124 if (preg_match ("/Schema::create \\([' \"]([a-zA-Z0-9_]+)[' \"]/ " , $ content , $ m )) {
@@ -111,35 +133,40 @@ public function status()
111133 }
112134
113135 $ exists = (bool ) $ conn ->tableExists ($ table );
114- if ($ exists ) {
115- $ this ->success (sprintf ("%-30s %s " , $ table , '[OK] ' ));
116- } else {
117- $ this ->warning (sprintf ("%-30s %s " , $ table , '[MISSING] ' ));
118- }
136+ $ rows [] = [$ file , $ table , $ exists ? 'OK ' : 'MISSING ' ];
119137 }
120138
121- return 0 ;
122- }
123-
124- /**
125- * Rollback all database migrations
126- */
127- public function reset ()
128- {
129- // Require --force in production environments
130- $ this ->forceChecker ();
131-
132- $ force = (bool ) $ this ->option ('force ' );
139+ if (empty ($ rows )) {
140+ $ this ->info ("No detectable migration tables. " );
141+ return 0 ;
142+ }
133143
134- $ migration = new Migration ();
135- $ response = $ migration ->drop ($ force );
144+ // Compute column widths
145+ $ headers = ['Migration ' , 'Table ' , 'Status ' ];
146+ $ w0 = strlen ($ headers [0 ]);
147+ $ w1 = strlen ($ headers [1 ]);
148+ $ w2 = strlen ($ headers [2 ]);
149+ foreach ($ rows as [$ f , $ t , $ s ]) {
150+ $ w0 = max ($ w0 , strlen ((string )$ f ));
151+ $ w1 = max ($ w1 , strlen ((string )$ t ));
152+ $ w2 = max ($ w2 , strlen ((string )$ s ));
153+ }
136154
137- if ($ response ['status ' ] != Constant::STATUS_200 ) {
138- $ this ->error ($ response ['message ' ]);
139- return 0 ;
155+ // Helpers to draw lines
156+ $ sep = '+ ' . str_repeat ('- ' , $ w0 + 2 ) . '+ ' . str_repeat ('- ' , $ w1 + 2 ) . '+ ' . str_repeat ('- ' , $ w2 + 2 ) . '+ ' ;
157+ $ rowFn = static function ($ a , $ b , $ c ) use ($ w0 , $ w1 , $ w2 ) {
158+ return sprintf ('| %- ' . $ w0 . 's | %- ' . $ w1 . 's | %- ' . $ w2 . 's | ' , $ a , $ b , $ c );
159+ };
160+
161+ // Render table
162+ Logger::writeln ($ sep );
163+ Logger::writeln ($ rowFn ($ headers [0 ], $ headers [1 ], $ headers [2 ]));
164+ Logger::writeln ($ sep );
165+ foreach ($ rows as [$ f , $ t , $ s ]) {
166+ Logger::writeln ($ rowFn ($ f , $ t , $ s ));
140167 }
168+ Logger::writeln ($ sep );
141169
142- $ this ->info ($ response ['message ' ]);
143170 return 0 ;
144171 }
145172
0 commit comments