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

Default placeholder is not populated #2699

Closed
feoktant opened this issue Mar 2, 2020 · 3 comments
Closed

Default placeholder is not populated #2699

feoktant opened this issue Mar 2, 2020 · 3 comments
Assignees
Labels
Milestone

Comments

@feoktant
Copy link

@feoktant feoktant commented Mar 2, 2020

Which version and edition of Flyway are you using?

6.2.3, 6.2.4

Which client are you using? (Command-line, Java API, Maven plugin, Gradle plugin)

Java API

Which database are you using (type & version)?

Postgres 11.6

Which operating system are you using?

Ubuntu

What did you do?

Little repo to reproduce my issue.
I try to get default placeholders in my migration scripts as it is described here.
Here is sample java main:

    public static void main(String[] args) {
        String schemaName = "test_schema";
        Flyway.configure()
            .dataSource(
                "jdbc:postgresql://localhost:5432/postgres",
                "postgres",
                "mysecretpassword")
            .locations("db/migrations")
            .defaultSchema(schemaName)
            .schemas(schemaName)
            .load()
            .migrate();
    }

And my scripts:

create table A(schema_name varchar);
insert into A values('${flyway:defaultSchema}');
What did you expect to see?

Placeholder was substituted by value test_schema.
test_schema string inserted into table A.

What did you see instead?
INFO: Current version of schema "test_schema": << Empty Schema >>
Exception in thread "main" org.flywaydb.core.api.FlywayException: Unable to parse statement in db/migrations/V1__create_table.sql at line 1 col 37: Failed to populate value for default placeholder: ${flyway:defaultSchema}
@bhavanki
Copy link

@bhavanki bhavanki commented Mar 4, 2020

I am seeing this same problem under Flyway 6.1.0.

It seems that the placeholder doesn't get filled in if the schema doesn't yet exist. I find that PostgreSQL (9.6.15) returns an empty string for SELECT current_schema if the schema does not yet exist, even if it is the sole member of search_path. (Flyway executes this select in PostgreSQLConnection::doGetCurrentSchema.)

My Java application fails to start the first time I run it, but before it fails, Flyway creates the schema and does some migrations, before hitting one needing flyway:defaultSchema. If I run the application again, it stays up, because the schema exists now.

@juliahayward
Copy link
Member

@juliahayward juliahayward commented Mar 9, 2020

What I'm seeing is that PostgreSQLConnection::doGetCurrentSchema() returns public rather than test_schema, so in the above example table A is populated but not with what I'd expect. I'm thinking that this placeholder value would be more correctly substituted by the defaultSchema config parameter rather than the current schema, which as we've seen may not exist or may be the wrong one. What do you think?

@Lyeeedar
Copy link
Contributor

@Lyeeedar Lyeeedar commented Mar 12, 2020

Fixed in c229730

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

No branches or pull requests

5 participants