Skip to content

Commit

Permalink
Change priority order of migration's db group
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbalandan committed Dec 9, 2023
1 parent 70aa8c3 commit fa68681
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
5 changes: 0 additions & 5 deletions phpstan-baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -1146,11 +1146,6 @@
'count' => 1,
'path' => __DIR__ . '/system/Database/Migration.php',
];
$ignoreErrors[] = [
'message' => '#^Property CodeIgniter\\\\Database\\\\Migration\\:\\:\\$DBGroup \\(string\\) on left side of \\?\\? is not nullable\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Database/Migration.php',
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 8,
Expand Down
13 changes: 8 additions & 5 deletions system/Database/Migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ abstract class Migration
/**
* The name of the database group to use.
*
* @var string
* @var string|null
*/
protected $DBGroup;

Expand All @@ -39,12 +39,15 @@ abstract class Migration
*/
protected $forge;

/**
* Constructor.
*/
public function __construct(?Forge $forge = null)
{
$this->forge = $forge ?? Database::forge($this->DBGroup ?? config(Database::class)->defaultGroup);
if (isset($this->DBGroup)) {
$this->forge = Database::forge($this->DBGroup);
} elseif ($forge !== null) {
$this->forge = $forge;
} else {
$this->forge = Database::forge(config(Database::class)->defaultGroup);
}

$this->db = $this->forge->getConnection();
}
Expand Down

0 comments on commit fa68681

Please sign in to comment.