Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not create schema to see if the migrations table exists. #94

Merged
merged 1 commit into from
Oct 5, 2012

Conversation

kimhemsoe
Copy link
Member

Sorry for the extra changed lines.

beberlei added a commit that referenced this pull request Oct 5, 2012
Do not create schema to see if the migrations table exists.
@beberlei beberlei merged commit b38ddb1 into doctrine:master Oct 5, 2012
@rhunwicks
Copy link

This commit breaks Migrations for postgresql users with a schema-specific migrations table.

I do not have a public schema in my postgresql database and my migrations table is specified as "schema_name.doctrine_migrations_table". This worked fine until this commit was merged.

The change to $this->connection->getSchemaManager()->tablesExist(array($this->migrationsTableName)) now breaks because tablesExist returns a array of table names without schema prefixes and consequently createMigrationTable attempts to create the table but fails because it already exists.

@kimhemsoe
Copy link
Member Author

I see if i can get pg up and running and figure something out..

have some "issues" with my PG install.

getting "PDOException: SQLSTATE[08006] [7] FATAL: sorry, too many clients already" and have not investigated what going on. Installed with macports. Any good idea's. I will try to fix the bug.

@kimhemsoe
Copy link
Member Author

@rhunwicks what version of dbal are you using ?

@rhunwicks
Copy link

cat composer.lock | grep -A4 -i dbal
            "package": "doctrine/dbal",
            "version": "2.3.x-dev",
            "source-reference": "fdc866a37959e43620e4f7ec519dc7dd8e30fc5b",
            "commit-date": "1348120597"
        },

@rhunwicks
Copy link

Further investigation shows the problem is with Doctrine\DBAL\Schema\PostgreSqlSchemaManager::_getPortableTableDefinition($table)

If the schema for the table is the same as the first schema in the search path, then it returns the bare table name without a schema qualifier. This seems fine in general, but when we call tablesExist() with a schema-qualified name in the first-searched schema it returns false because tablesExist() calls $this->listTableNames() which in turn calls _getPortableTablesList() which returns the bare table name without the schema prefix and so the array_intersect misses it

@kimhemsoe
Copy link
Member Author

also why im looking into maybe using listTableColumns or some other direct call to the db if possible. Havent tested it yet tho. Just an idea. That or go back to the super slow createSchema

@rhunwicks
Copy link

The least intrusive way, given the error is a result of the definition of _getPortableTableDefinition() in PostgreSqlSchemaManager is to create PostgreSqlSchemaManager::tablesExist

    /**
     * Return true if all the given tables exist.
     *
     * @param array $tableNames
     * @return bool
     */
    public function tablesExist($tableNames)
    {
        foreach ($tableNames as $key => $tableName) {
            if (strpos($tableName, '.') !== false) {
                $tableName = explode('.', $tableName, 2);
                $tableNames[$key] = $this->_getPortableTableDefinition(array('schema_name'=>$tableName[0], 'table_name'=>$tableName[1]));
            }
        }
        return parent::tablesExist($tableNames);
    }

@kimhemsoe
Copy link
Member Author

Think i add some unit tests to tests this for each db. I never been a big user of PG or.. other dbs then mysql. Something i will change soonish...

@rhunwicks
Copy link

I think this issue should be reopened - as the current situation will break Migrations for some Postgresql users the next time they do a composer.phar update and it will not be obvious if they look on GitHub that the issue is known.

@stof
Copy link
Member

stof commented Oct 24, 2012

@rhunwicks This is a PR, not an issue. So we cannot reopen it as it has been merged. If there is an issue, pleas eopen a dedicated ticket instead of using comments on a merged PR.

@kimhemsoe
Copy link
Member Author

I will post a fix later today you can test out for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants