Skip to content

Support PostgreSQL schema other than public (CFM-356) #136

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions app/src/Command/TransmogrifyCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,12 @@ public function execute(Arguments $args, ConsoleIo $io) {
}

$this->inconn = DriverManager::getConnection($cargs, $inconfig);

// If a PostgreSQL schema is configured force DBAL to respect it
// by setting the SEARCH_PATH.
if(!empty($incfg['schema']) && ($incfg['driver'] == 'Cake\Database\Driver\Postgres')) {
$this->inconn->exec("SET SEARCH_PATH TO " . $incfg['schema'] . ";");
}

$outconfig = new \Doctrine\DBAL\Configuration();

Expand All @@ -572,6 +578,13 @@ public function execute(Arguments $args, ConsoleIo $io) {
}

$this->outconn = DriverManager::getConnection($cargs, $outconfig);

// If a PostgreSQL schema is configured force DBAL to respect it
// by setting the SEARCH_PATH.
if(!empty($outcfg['schema']) && ($outcfg['driver'] == 'Cake\Database\Driver\Postgres')) {
$this->outconn->exec("SET SEARCH_PATH TO " . $outcfg['schema'] . ";");
}

$this->outdriver = $cargs['driver'];

// We accept a list of table names, mostly for testing purposes
Expand Down
7 changes: 7 additions & 0 deletions app/src/Lib/Util/SchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ public function __construct(?ConsoleIo $io=null, string $connection='default') {
}

$this->conn = DriverManager::getConnection($cfargs, $config);

// If a PostgreSQL schema is configured force DBAL to respect it
// by setting the SEARCH_PATH.
if(!empty($cfg['schema']) && ($cfg['driver'] == 'Cake\Database\Driver\Postgres')) {
$this->conn->exec("SET SEARCH_PATH TO " . $cfg['schema'] . ";");
}

$this->driver = $cfg['driver'];
}

Expand Down