66
77use Tamedevelopers \Support \Env ;
88use Tamedevelopers \Database \Constant ;
9+ use Tamedevelopers \Support \Capsule \File ;
910use Tamedevelopers \Support \Capsule \Artisan ;
1011use Tamedevelopers \Database \DatabaseManager ;
1112use Tamedevelopers \Database \Migrations \Migration ;
@@ -67,8 +68,55 @@ public function refresh()
6768 */
6869 public function status ()
6970 {
70- echo "[demo] status database... \n" ;
71- // TODO: call your seeder pipeline here
71+ // Resolve migrations directory
72+ $ migrationsDir = Env::getServers ('server ' ) . "database/migrations/ " ;
73+
74+ if (!is_dir ($ migrationsDir )) {
75+ $ this ->warning ("Migrations directory not found: {$ migrationsDir }" );
76+ return 0 ;
77+ }
78+
79+ // Connect to DB and validate connection
80+ $ conn = DatabaseManager::connection ();
81+ $ this ->checkConnection ($ conn );
82+
83+ // Gather migration files
84+ $ files = array_values (array_filter (scandir ($ migrationsDir ), static function ($ f ) use ($ migrationsDir ) {
85+ return is_file ($ migrationsDir . $ f ) && str_ends_with ($ f , '.php ' );
86+ }));
87+ sort ($ files );
88+
89+ if (empty ($ files )) {
90+ $ this ->info ("No migration files found in: {$ migrationsDir }" );
91+ return 0 ;
92+ }
93+
94+ $ this ->info ("Migration status: " );
95+ foreach ($ files as $ file ) {
96+ $ fullPath = $ migrationsDir . $ file ;
97+
98+ // Try to detect created table from file content first
99+ $ table = null ;
100+ $ content = File::get ($ fullPath ) ?: '' ;
101+ if (preg_match ("/Schema::create \\([' \"]([a-zA-Z0-9_]+)[' \"]/ " , $ content , $ m )) {
102+ $ table = $ m [1 ];
103+ } elseif (preg_match ('/create_(.+)_table \\.php$/ ' , $ file , $ m )) {
104+ $ table = $ m [1 ];
105+ }
106+
107+ if (!$ table ) {
108+ $ this ->warning ("Unable to detect table for migration: {$ file }" );
109+ continue ;
110+ }
111+
112+ $ exists = (bool ) $ conn ->tableExists ($ table );
113+ if ($ exists ) {
114+ $ this ->success (sprintf ("%-30s %s " , $ table , '[OK] ' ));
115+ } else {
116+ $ this ->warning (sprintf ("%-30s %s " , $ table , '[MISSING] ' ));
117+ }
118+ }
119+
72120 return 0 ;
73121 }
74122
@@ -77,7 +125,20 @@ public function status()
77125 */
78126 public function reset ()
79127 {
80- // No-op placeholder to show that options with values are also routed
128+ // Require --force in production environments
129+ $ this ->forceChecker ();
130+
131+ $ force = (bool ) $ this ->option ('force ' );
132+
133+ $ migration = new Migration ();
134+ $ response = $ migration ->drop ($ force );
135+
136+ if ($ response ['status ' ] != Constant::STATUS_200 ) {
137+ $ this ->error ($ response ['message ' ]);
138+ return 0 ;
139+ }
140+
141+ $ this ->info ($ response ['message ' ]);
81142 return 0 ;
82143 }
83144
0 commit comments