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

[536] [913] [910] SchemaMigrator/SchemaValidator support for PostgreSQL and CockroachDB #903

Merged
merged 1 commit into from
Aug 31, 2021

Conversation

gbadner
Copy link
Contributor

@gbadner gbadner commented Jul 24, 2021

For #536, #913, and #910 .

Requires ORM PR:
hibernate/hibernate-orm#4106

@gbadner gbadner requested review from DavideD and gavinking July 24, 2021 00:20
@DavideD DavideD added the waiting We are waiting for another PR or issue to be solved before merging this one label Jul 26, 2021
@DavideD
Copy link
Member

DavideD commented Jul 26, 2021

I will convert this to a draft, it contains changes to the gradle.properties file that we don't want on the main branch. And also because we have to wait for ORM to include the PR that we need.

@DavideD DavideD marked this pull request as draft July 26, 2021 14:14
.thenAccept( result ->
context.assertEquals(
result,
"CREATE UNIQUE INDEX aanother_pkey ON public.aanother USING btree (id)"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not critical, but when using context.equals(expected, actual), the firs value is the expected one and the second the actual one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I normally do it that way, I don't know why I didn't in this test. I'll change it.

Copy link
Contributor Author

@gbadner gbadner Jul 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DavideD, I pushed a commit that corrects the order.

@@ -50,6 +50,7 @@
CompletionStage<Result> select(String sql);
CompletionStage<Result> select(String sql, Object[] paramValues);
CompletionStage<ResultSet> selectJdbc(String sql, Object[] paramValues);
CompletionStage<ResultSet> selectJdbcOutsideTransaction(String sql, Object[] paramValues);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remind us why you need the additional method?

Copy link
Contributor Author

@gbadner gbadner Jul 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DavideD , since SchemaMigrator executes select queries on system tables and executes DDL statements (which update system tables), I assumed that these queries should be executed outside of a transaction (i.e., with autocommit=true). IIUC, this would help avoid contention with other work the DB is doing on schemas used by various applications.

If you look at the corresponding ORM code in GenerationTargetToDatabase, you can see that the statement is created using a connection obtained from a DdlTransactionIsolator.

Javadoc for DdlTransactionIsolator says:

 * Provides access to a Connection that is isolated from
 * any "current transaction" with the designed purpose of
 * performing DDL commands

If you look at the DdlTransactionIsolator implementations, you will see that autocommit is set to true on the Connection that is obtained:
DdlTransactionIsolatorJtaImpl
DdlTransactionIsolatorNonJtaImpl
DdlTransactionIsolatorProvidedConnectionImpl relies on JdbcConnectionAccessProvidedConnectionImpl which sets autocommit to true

I didn't see any other way to execute a query outside of a transaction that returned a CompletionStage<ResultSet>, so I created a new method.

Is there some other method that should be used instead?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we had this requirement before. I don't see any problem adding a new method.

But I mainly wanted a bit of an explanation written somewhere so that others know as well (maybe it wasn't obvious only to me though ;-)

At some point, we will need to add some javadoc to that class. Anyway, not something you need to worry about at the moment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I know this stuff is lacking in documentation. I will be adding that.

@gavinking
Copy link
Member

I have not tested it but the code looks great! Thanks @gbadner

(The only very minor comment I have is I would prefer that SQL keywords were in lowercase like the rest of the SQL we generate.)

@gbadner
Copy link
Contributor Author

gbadner commented Jul 27, 2021

@DavideD, thanks for doing making it a draft. I thought I defined it as a draft when I created it, but maybe I missed that.

@gbadner
Copy link
Contributor Author

gbadner commented Jul 27, 2021

I have not tested it but the code looks great! Thanks @gbadner

Thanks @gavinking!

(The only very minor comment I have is I would prefer that SQL keywords were in lowercase like the rest of the SQL we generate.)

That's fine. I can change that.

@gbadner
Copy link
Contributor Author

gbadner commented Jul 27, 2021

I'm currently using the Hibernate ORM codestyle. Which of the codestyles do you use for Hibernate Reactive?

@gbadner
Copy link
Contributor Author

gbadner commented Jul 28, 2021

I finally got around to taking a good look at what else needs to be done for SchemaValidator, and, AFAICT, it's already working with the code provided here!?!

@gbadner gbadner changed the title [536] SchemaMigrator support for PostgreSQL [536] SchemaMigrator/SchemaValidator support for PostgreSQL Jul 28, 2021
@gbadner
Copy link
Contributor Author

gbadner commented Jul 28, 2021

@gavinking, I added a new commit that changes SQL keywords to lower-case.

@gavinking
Copy link
Member

Thanks, @gbadner

@DavideD
Copy link
Member

DavideD commented Jul 28, 2021

@DavideD, thanks for doing making it a draft. I thought I defined it as a draft when I created it, but maybe I missed that.

no problem

I'm currently using the Hibernate ORM codestyle. Which of the codestyles do you use for Hibernate Reactive?

Yes, that's what we should use. Thanks.

Although, our build doesn't check the code style (except of a couple of basic rules) so you might find that we are a bit inconsistent sometimes.

@gbadner
Copy link
Contributor Author

gbadner commented Aug 4, 2021

@DavideD, I just pushed a commit that adds Javadoc and a couple of small tweaks.

I forgot that I had already pushed a commit for encapsulating methods into ExtractionTool and ended up squashing the two commits, so I had to force-push.

Sanne is still looking at the ORM PR. I think this PR is ready to review, although we will obviously have to wait for the ORM PR to be finalized.

Unless I hear of any required changes to this PR, I will start work on adding support for MySQL.

@gavinking
Copy link
Member

This all looks very nice, @gbadner!

@gbadner
Copy link
Contributor Author

gbadner commented Aug 5, 2021

Thanks @gavinking, I'm pretty happy with it.

@gbadner
Copy link
Contributor Author

gbadner commented Aug 5, 2021

I just added a commit to deal with a non-standard information_schema.columns column name used by PostgreSQL.

@gbadner
Copy link
Contributor Author

gbadner commented Aug 30, 2021

Merged commits from #940.

@gbadner gbadner changed the title [536] [913] SchemaMigrator/SchemaValidator support for PostgreSQL and CockroachDB [536] [913] [910] SchemaMigrator/SchemaValidator support for PostgreSQL and CockroachDB Aug 30, 2021
@gavinking
Copy link
Member

Merged commits from #940.

Great.

@@ -124,17 +126,17 @@ protected Configuration constructConfiguration() {
doneTablespace = true;
}
//Use JAVA_TOOL_OPTIONS='-Dhibernate.show_sql=true'
configuration.setProperty( Settings.SHOW_SQL, System.getProperty(Settings.SHOW_SQL, "false") );
configuration.setProperty( Settings.SHOW_SQL, System.getProperty(Settings.SHOW_SQL, "true") );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gbadner could you roll back this change please?

P.S. A more convenient way to enable SQL logging during development is to set:

logger.hibernate.level = debug

in log4j.properties.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gavinking, this is done.

@gavinking
Copy link
Member

I'm seeing failures in tests that restrict ORM versions [5.5,5.6).

Is this the only thing blocking us from merging this?

@Sanne
Copy link
Member

Sanne commented Aug 31, 2021

We should no longer test with Hibernate ORM 5.5 since this requires those changes which are exclusively in 5.6

@Sanne
Copy link
Member

Sanne commented Aug 31, 2021

P.S. I've already upgraded Quarkus to use ORM 5.6.0.Beta1 so I'm not concerned about dropping compatibility with 5.5

@gavinking
Copy link
Member

We should no longer test with Hibernate ORM 5.5 since this requires those changes which are exclusively in 5.6

Yes, I agree.

@gavinking
Copy link
Member

So am I understanding correctly that as of this change, we now have two redundant runs of the test suite for every CI build?

@gavinking
Copy link
Member

Anyway, OK, right, @gbadner, this seemed to fix it:

gavinking@7d8e19b

@gbadner
Copy link
Contributor Author

gbadner commented Aug 31, 2021

I pushed a commit that disables SQL logging and includes @gavinking 's commit to fix DI. Crossing my fingers that everything passes...

@gbadner
Copy link
Contributor Author

gbadner commented Aug 31, 2021

Hurray, all passed!

@gavinking
Copy link
Member

WDYT shall we merge it?

@gbadner
Copy link
Contributor Author

gbadner commented Aug 31, 2021

@gavinking, yes, please do!

@gavinking
Copy link
Member

It's still a "Draft" :)

@gbadner gbadner marked this pull request as ready for review August 31, 2021 19:04
@gbadner gbadner requested review from gavinking and DavideD August 31, 2021 19:04
@gbadner
Copy link
Contributor Author

gbadner commented Aug 31, 2021

Oops, it's "Open" now.

@gavinking
Copy link
Member

There's a lot of commits here, should we squash?

@gbadner
Copy link
Contributor Author

gbadner commented Aug 31, 2021

Sure, I'll squash and push to my branch...

[536] Correct order of arguments to TestContext#assertEquals

[536] : Change SQL keywords to lowercase

[536] Encapsulate extraction methods into ReactiveExtractionTool

[536] : Added Javodoc, made minor changes to sych up with ORM, changed more SQL keywords that were upper-case to lower-case

[536] : Use org.hibernate.reactive.pool.impl.Parameters#process for dialect-specific parameter placeholders

[536] : Add a method for non-standard information_schema.columns column name used by PostgreSQL

[536] Change `ResultSetAdapter#getLong(String)` to be convert String to Long

[536] Change `ResultSetAdapter#getLong(String)` to throw the original exception if the value is neither a long nor a String that can be parsed as a long.

[913] SchemaMigrator/SchemaValidator support for CockroachDB

[536] [913] Comment out settings in gradle.properties

[910] SchemaMigrator/SchemaValidator support for MySQL

[910] Fix off-by-one bug in ResultSetAdaptor#getXXX(int columnIndex) methods

[910] SchemaMigrator/SchemaValidator support for MariaDB

[910] Improve Javadoc; simplify MySqlReactiveInformationExtractorImpl methods

[536] Disable SQL logging

attempt to fix CI build
@gbadner gbadner force-pushed the 536-schema-update branch from ee87282 to 0223cb4 Compare August 31, 2021 19:11
@gbadner gbadner removed the waiting We are waiting for another PR or issue to be solved before merging this one label Aug 31, 2021
@gavinking gavinking merged commit b5e88aa into hibernate:main Aug 31, 2021
@gavinking
Copy link
Member

Excellent! Fantastic to finally have this done!

Thanks @gbadner

@gbadner gbadner deleted the 536-schema-update branch August 31, 2021 19:41
@Sanne
Copy link
Member

Sanne commented Sep 1, 2021

Nice!

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

Successfully merging this pull request may close these issues.

4 participants