question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Incorrect schema name in the search path is called when using the "--defaultSchemaName" on a non-default schema

See original GitHub issue

Environment

Windows, Linux, PostgreSQL Liquibase Version: version 4.0.0-beta1 Liquibase Integration & Version: CLI

Description

When attempting to create a view to a table in a specific schema, Liquibase attempts to apply the “create view” changeSet to query to the table in the default schema instead.

Steps To Reproduce

  1. Create a new postgreSQL database with schemas: public (default schema), lookup.
  2. Create a changeLog with 2 changeSets, “create table” and “create view”. For example:
<changeSet author="SteveZ" id="1">
        <createTable tableName="execSales">
            <column name="id" type="INTEGER">
                <constraints nullable="false" primaryKey="true" primaryKeyName="id_pkey"/>
            </column>
            <column name="name" type="VARCHAR(255)"/>
        </createTable>
    </changeSet>
    <changeSet author="SteveZ" id="2">
        <createView fullDefinition="false" viewName="newView"> SELECT "execSales".id,
    "execSales".name
   FROM "execSales";
        </createView>
    </changeSet>

Run: liquibase --defaultSchemaName=lookup update

Actual Behavior

The will produce the following error: liquibase.exception.DatabaseException: ERROR: relation "execSales" does not exist It appears that the statement from changeSet “create view”:

SELECT "execSales".id,"execSales".name FROM "execSales";

is trying to query the table in public.execSales. Since there is no table “execSales” in the schema “public” the error occur.

Expected/Desired Behavior

The following SQL should be in the “lookup” schema search path.

SELECT "execSales".id, "execSales".name FROM "execSales";

Workaround

This can be worked around with adding ?currentSchema=lookup to the end of the jdbc connection string before running the update command. For example: url: jdbc:postgresql://localhost:5432/testDB?currentSchema=lookup However, this will not work well when using a multi-schema project (ie: using --schemas=public,users,lookup,accounts).

Acceptance Criteria

  1. When specified by a user, --defaultSchemaName=<myschema> should behave as expected, guiding liquibase commands such as update, updateSQL, rollback, and more to work on the specified schema

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:23 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
ZigZag59commented, Dec 10, 2020

Hi,

I updated my version from 3.10.0 to 3.10.3 and this new feature introduced a bug.

We use types declared in the ‘public’ schema (like the hstore and other types), specific schemas (one by domain and eventually migration) and optionally, the parameter in the ‘currentSchema’ connection string (if the current user does not fit the schema name). Thus, we can use the types declared in the ‘public’ schema.

The problem with this new feature is that the hstore type is no longer accessible. Is there a workaround?

In my opinion, adding the ‘defaultSchema’ in the ‘search-path’ is a good idea. But rather than replacing the existing ‘search_path’, it should be added to the existing value.

SELECT set_config( 'search_path', 'my_schema,' || current_setting('search_path'), true ) WHERE current_setting('search_path') !~ '(^|,)my_schema(,|$)';

1reaction
nvoxlandcommented, May 23, 2022

Yes, this seems to be working with me in the code going out in 4.11.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

Search_path is not being set correctly - Liquibase Forum
... search_path being reset: Incorrect schema name in the search path is called when using the “–defaultSchemaName” on a non-default schema ...
Read more >
How do I resolve issues with missing or incorrect schema ...
I have run into various cases where errors are occurring related to the DatabaseSchemaVersion property in the LSW_SYSTEM_SCHEMA table for the BPM and...
Read more >
Documentation: 15: 5.9. Schemas - PostgreSQL
Schema names beginning with pg_ are reserved for system purposes and cannot be ... The first schema named in the search path is...
Read more >
Reflecting Database Objects — SQLAlchemy 1.4 Documentation
As described at Specifying a Default Schema Name with MetaData, ... into the notion of a schema search path where multiple schema names...
Read more >
java - Is it possible to specify the schema when connecting to ...
I know this was answered already, but I just ran into the same issue trying to specify the schema to use for the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found