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

CockroachDb invalid default database name #1851

FlakM opened this issue Dec 1, 2017 · 3 comments

CockroachDb invalid default database name #1851

FlakM opened this issue Dec 1, 2017 · 3 comments


Copy link

FlakM commented Dec 1, 2017

What version of Flyway are you using?

current master (I believe future 5.0.0)

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


What database are you using (type & version)?

CockroachDb latest (v1.1.3)

What operating system are you using?


What did you do?

Running migrations with newly implemented support for roach with url (without schema param):


results in method org.flywaydb.core.internal.database.Connection#doGetCurrentSchemaName
implemented for roach as SHOW database returning empty String and that results in Errors during executing doChangeCurrentSchemaTo

due to expression "SET DATABASE =" being invalid

According to documentation
It is possible to set database to default with expression:


Dont you think it would be good idea to change doChangeCurrentSchemaTo to something like that:

    public void doChangeCurrentSchemaTo(String schema) throws SQLException {
        if (schema == null || schema.equals("")){
            // avoid empty schema name when original schema was the default one
            schema = "DEFAULT";
        jdbcTemplate.execute("SET database = " + schema);

I have tested it manually. Should you agree I'd be happy to send a PR

Copy link

Thanks for reporting this. Can you help me understand which problem you are trying to solve?

Note that CockroachDB 1.1 doesn't support working with objects in other databases and doesn't have a real default database.

Copy link
Contributor Author

FlakM commented Dec 2, 2017

Thanks for all the work! Well I'm trying to run my migrations without specifying database in url.
Flyway itself runs migration smoothly but trips up on going back to original database.
Checkout scenario

I've also specified schema mydatabse in connection url (that did not exist at the point of migraiting) and it went ok (except for running create schema_version table 4 times)

I reported this mainly because the migration itself went well and the result seems strange to me.

axelfontaine pushed a commit to flyway/ that referenced this issue Dec 4, 2017
Copy link

Thanks for the detailed explanation and the gist. That was super helpful. Merged

dohrayme pushed a commit to dohrayme/flyway that referenced this issue Feb 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

2 participants