Skip to content

Commit ccf543d

Browse files
committed
✨ add connectDB() method to handle migrations connection to database
Signed-off-by: otengkwame <developerkwame@gmail.com>
1 parent 86509fa commit ccf543d

1 file changed

Lines changed: 27 additions & 10 deletions

File tree

Core/controllers/commands/Migration.php

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,31 @@ public function __construct()
7676

7777
$this->onlydev();
7878

79-
$this->use->database();
79+
$this->connectDB();
8080
$this->use->dbforge();
8181

8282
$this->migration = (new Migrate);
8383

8484
$this->migrationRequirements();
8585
}
8686

87+
/**
88+
* Connect to a database
89+
*
90+
* @return void
91+
*/
92+
private function connectDB()
93+
{
94+
try {
95+
shut_up();
96+
$this->use->database();
97+
speak_up();
98+
} catch(\Exception $e) {
99+
echo $this->error($e->getMessage());
100+
exit;
101+
}
102+
}
103+
87104
/**
88105
* Migration Requirements
89106
*
@@ -253,7 +270,7 @@ protected function findMigrations($path = null)
253270
* @param string $database
254271
* @return void
255272
*/
256-
public function useDB($database = 'default')
273+
public function useDB($database = 'default')
257274
{
258275
$this->useDb = $database;
259276
}
@@ -354,7 +371,7 @@ public function reset()
354371
$this->rollback(INF); // infinity
355372
}
356373

357-
echo $this->warning("Migration has been reset to initial state successfully");
374+
echo $this->warning("Migration has been reset to initial state successfully");
358375
}
359376

360377
/**
@@ -363,7 +380,7 @@ public function reset()
363380
* @param integer $step
364381
* @return void
365382
*/
366-
public function rollback($step = 0)
383+
public function rollback($step = 0)
367384
{
368385
$previousMigrations = $this->executedMigrations();
369386

@@ -439,22 +456,22 @@ function($migration) { return $migration->run_at.' '.$migration->migration; },
439456
*
440457
* @return void
441458
*/
442-
public function latest()
459+
public function latest()
443460
{
444461
$migration = $this->executedMigrations(true, true);
445462

446463
$output = '';
447464

448465
$this->output->set_header('Content-type: text/plain');
449466

450-
if (!$migration) {
451-
echo $output = $this->warning('No Current Migration Available');
452-
exit;
453-
}
467+
if (!$migration) {
468+
echo $output = $this->warning('No Current Migration Available');
469+
exit;
470+
}
454471

455472
$list = $migration->run_at.' '.$migration->migration;
456473

457-
if ($list) {
474+
if ($list) {
458475
$output = $this->info("\nLatest Migration", 2);
459476
$output .= $this->warning($list, 2);
460477
} else {

0 commit comments

Comments
 (0)