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

Closed
FlakM opened this issue Dec 1, 2017 · 3 comments
Closed

CockroachDb invalid default database name #1851

FlakM opened this issue Dec 1, 2017 · 3 comments

Comments

@FlakM
Copy link
Contributor

@FlakM 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)

API

What database are you using (type & version)?

CockroachDb latest (v1.1.3)

What operating system are you using?

ElementaryOS

What did you do?

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

jdbc:postgresql://127.0.0.1:26257/?sslmode=disable

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 https://www.cockroachlabs.com/docs/stable/set-vars.html
It is possible to set database to default with expression:

SET DATABASE=DEFAULT;

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

    @Override
    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

@axelfontaine
Copy link
Contributor

@axelfontaine axelfontaine commented Dec 1, 2017

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.

@FlakM
Copy link
Contributor Author

@FlakM 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 https://gist.github.com/FlakM/2870a512093b085cba6490348eb9967a

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 added a commit to flyway/flywaydb.org that referenced this issue Dec 4, 2017
@axelfontaine
Copy link
Contributor

@axelfontaine axelfontaine commented Dec 4, 2017

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

selliera pushed a commit to selliera/flyway that referenced this issue Dec 7, 2017
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
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.