dbal icon indicating copy to clipboard operation
dbal copied to clipboard

PostgreSQLSchemaManager wrongly resolves an empty existing table set

Open NoiseByNorthwest opened this issue 2 years ago • 5 comments

Bug Report

PostgreSQLSchemaManager wrongly resolves an empty existing table set.

Q A
Version 3.4.0

Summary

When running doctrine:schema:update command it wrongly considers all my existing tables as missing and thus generates the corresponding DDL statments which will fail if executed (i.e. duplicate table...).

My context: I have many schemas, all tables are located in a schema different from public.

Current behaviour

doctrine:schema:update generates DDL statments for missing tables whereas they already exists and are up to date.

How to reproduce

1 . You need a mapping with several tables in different schemas. 2. Run doctrine:schema:update

Expected behaviour

doctrine:schema:update generates no DDL statment when the DB is up to date.

NoiseByNorthwest avatar Aug 08 '22 12:08 NoiseByNorthwest

@NoiseByNorthwest could you provide a reproducer, please? I will not be able to fix the issue without reproducing it first.

morozov avatar Aug 09 '22 02:08 morozov

Why are you using current_schemas(false)?

I'm not entirely sure. It was originally introduced in https://github.com/doctrine/dbal/pull/3821 as a replacement to some other filter.

morozov avatar Aug 09 '22 02:08 morozov

Rolling back to 3.3.8 fix this problem until we get a solution

johnnestebann avatar Aug 09 '22 02:08 johnnestebann

@morozov It seems to be in fact not (directly) related to the addition of current_schemas(false).

Here are the execution flow differences between 3.3.x & 3.4.x

3.3.x

AbstractSchemaManager::createSchema()
    AbstractSchemaManager::listTables()
        AbstractSchemaManager::listTableNames()
            PostgreSQLPlatform::getListTablesSQL()
                -> OK expected table list, simple query with few adhoc filters and no current_schemas()

3.4.x

AbstractSchemaManager::createSchema()
    PostgreSQLSchemaManager::listTables()
        AbstractSchemaManager::doListTables()
            AbstractSchemaManager::fetchTableColumnsByTable()
                PostgreSQLSchemaManager::selectTableColumns()
                    -> KO empty table list, complex query with common filters,
                          provided by buildQueryConditions(), including current_schemas()

NoiseByNorthwest avatar Aug 09 '22 10:08 NoiseByNorthwest

I can reproduce the issue. It depends on the changes in https://github.com/doctrine/dbal/pull/5576 (at least the testing part), so let's get it merged first.

morozov avatar Aug 10 '22 02:08 morozov

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

github-actions[bot] avatar Sep 13 '22 00:09 github-actions[bot]