Phinx: Migrate cannot run with postgres schema that needs to be escaped

Created on 11 May 2020  路  4Comments  路  Source: cakephp/phinx

If you have a schema which contains characters which need escaping

this-needs-quotes

and you specify the default migration table as follows

'default_migration_table' => 'this-needs-quotes.phinxlog',

The the create table portion of the migration process works without issue. However it then tries to run a select using the unescaped schema to see which migrations have run and fails preventing migration.

If you specify the schema as follows

'default_migration_table' => '"this-needs-quotes".phinxlog',

Then the create process double escapes

CREATE TABLE ""this-needs-quotes""."phinxlog"

And the SQL fails to execute.

If you do not include a default migration table then it appears that the schema selected is public and not the default search path schema.

There appears to be no way of creating migrations for a schema which requires escaping.

bug

All 4 comments

Hi, this is a relatively simple fix and I would love to open a PR, but it seems I do not have permission to do so.

There are two lines that need changing in src/Phinx/Db/Adapter/PostgresAdapter.php
$db->exec('SET search_path TO ' . $options['schema']);

$this->fetchAll(sprintf('SET search_path TO %s', $this->getGlobalSchemaName()));

If you escape the schema name then this resolves the problem and you can migrate when the schema contains characters which require escaping.

There's no way you don't have permission to open a PR. Anyone can do so.

Did the PR resolve this?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

doctordesh picture doctordesh  路  4Comments

Jeckerson picture Jeckerson  路  3Comments

sooners87 picture sooners87  路  3Comments

elct9620 picture elct9620  路  4Comments

djpate picture djpate  路  5Comments