44
55namespace Bow \Console \Command ;
66
7- use Bow \Console \AbstractCommand ;
7+ use Exception ;
8+ use ErrorException ;
9+ use Bow \Support \Str ;
810use Bow \Console \Color ;
911use Bow \Database \Database ;
12+ use Bow \Database \QueryBuilder ;
13+ use Bow \Console \AbstractCommand ;
14+ use Bow \Database \Migration \Table ;
15+ use Bow \Database \Exception \MigrationException ;
1016use Bow \Database \Exception \ConnectionException ;
1117use Bow \Database \Exception \QueryBuilderException ;
12- use Bow \Database \Migration \Table ;
13- use Bow \Database \QueryBuilder ;
14- use Bow \Support \Str ;
15- use ErrorException ;
16- use Exception ;
1718
1819class MigrationCommand extends AbstractCommand
1920{
@@ -84,7 +85,13 @@ private function createMigrationTable(): void
8485 {
8586 $ connection = $ this ->arg ->getParameter ("--connection " , config ("database.default " ));
8687
87- Database::connection ($ connection );
88+ try {
89+ Database::connection ($ connection );
90+ } catch (Exception $ exception ) {
91+ echo Color::red ("▶ Please check your database configuration on .env.json file \n" );
92+ throw new MigrationException ($ exception ->getMessage (), (int )$ exception ->getCode ());
93+ }
94+
8895 $ adapter = Database::getConnectionAdapter ();
8996
9097 $ table = $ adapter ->getTablePrefix () . config ('database.migration ' , 'migrations ' );
@@ -107,7 +114,12 @@ private function createMigrationTable(): void
107114 $ generator ->make ()
108115 );
109116
110- Database::statement ($ sql );
117+ try {
118+ Database::statement ($ sql );
119+ } catch (Exception $ exception ) {
120+ echo sprintf ("%s %s \n" , Color::red ("▶ " ), $ sql );
121+ throw new MigrationException ($ exception ->getMessage (), (int )$ exception ->getCode ());
122+ }
111123 }
112124
113125 /**
0 commit comments