-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
CockroachDatabase: Limit calls to version() #2556
Conversation
… cockroachdb connection
Testing notes:
|
@nvoxland, there are no functional tests that run against CockroachDb. However, the test-harness runs CockroachDb tests; this makes it easy to start up the database in multiple versions. I will run those locally. |
liquibase-core/src/main/java/liquibase/database/core/PostgresDatabase.java
Show resolved
Hide resolved
Liquibase determines if a JDBC URL connecting to the database through the Postgres driver is H2 or Cockroach. This prevents Liquibase from calling the wrong method to determine the database version, avoiding exceptions from being thrown when connecting to H2 with the Postgres driver. NOTE On a "fresh" H2 database where DATABASECHANGELOGLOCK does not exist, H2 throws a JdbcSQLSyntaxErrorException when Liquibase queries the to see if the database is locked. This is expected behavior. The JdbcSQLSyntaxErrorException addressed in this PR is specific to calling the incorrect Validate test-harness suite passes. PASS Validate update calls the correct
Cockroach SetupAs a new-to-crdb tester, I followed the documentation to start a Cockroach demo environment in memory.
To configure Liquibase to interact with Cockroach DB, I used followed these instructions. The liquibase.properties file to connect to the Cockroach demo database is:
The queries Liquibase runs are displayed on the webpage for SQL Activity. H2 SetupA local H2 database creates a trace db file where all SQL statements causing an exception are recorded. To create the in-memory H2 database and the trace db, configure the liquibase.properties url as:
The first time Liquibase runs, the /tmp/h2-db.db and /tmp/h2-db.trace.db files are created in the current working directory. Open h2-db.trace.db with Notepad++ to see the SQL exceptions. As noted above, an exception is expected when connecting to a new H2 database where DATABASECHANGELOGLOCK table does not exist. Test Environment |
Description
Rather than making a likely invalid SQL call to
select version()
regardless of the connection to determine if it's a cockroachdb database, first check that the URL looks like a cockroachdb database before checking whether it is or not.Checking for both
jdbc:postgres:
andpostgres:
without the:
to also supportjdbc:postgresql:
andpostgresql:
based on https://www.cockroachlabs.com/docs/stable/connection-parameters.html#connect-using-a-urlFixes #2483