-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Improve schema update for H2 and PostgreSQL and document various dev approaches #1886
Comments
@gsmet could this be related to Panache? Or to |
hi @rbaumgar ! could you please verify if you still have this problem with version 0.13 ? If you still have it, could you give us some more details? I couldn't reproduce it on version 0.13. thanks |
This seems to be due to the naming strategy and databases using case-insensitive table names, which the |
Still in 0.13
|
Works on MariaDB. Probably related to case-sensitive/insensitive identifiers on the database. In this case, H2 - as pointed on the issue. |
Right the problem is the way H2 and PostgreSQL handle capitalization. I don't think we can fix this in Quarkus; using "update" requires some care:
For Regarding |
P.S. I think we'll have to close this issue but I'm happy to keep it open for a bit longer, so to have a conversation about what should be done - maybe no changes at all, but we could consider at least logging a warning when people combine "update" within |
I wish to use "update" for live code demos, therefore this is no import.sql (takes too long to key that in). If I understand the issue, Java likes classes that begin with a capital letter (e.g. Customer.java) but postgres and H2 want that to be a lower-case "c". Can we not just force table names to lower case? Also, if the table/column name is a reserved word, can we get an better error message? |
Here is the compromise we will lean towards
3.b. would work to a certain extend, PostgreSQL and MySQL are probably going to be fine. Older database with more baggage like DB2 or Oracle will possibly not work and the user would have to set a different naming strategy or use |
@burrsutter I do demo with |
import.sql is not incompatible but the file is just not present as it takes too long to type from scratch, not too mention it is yet another syntax to be learned |
FTR I tried to change the implicit naming strategy to both |
So, in public TableInformation getTableInformation(Table table) {
return tables.get( identifierHelper.toMetaDataObjectName( table.getQualifiedTableName().getTableName() ) );
}
|
It looks like we call |
@emmanuelbernard or @Sanne could you pass this over to the right person in Hibernate that could tell us what to do if we wanted to support |
I can't find in the code in |
OK, so here's a workaround: public class QuarkusPostgreSQL95Dialect extends PostgreSQL95Dialect {
@Override
public IdentifierHelper buildIdentifierHelper(IdentifierHelperBuilder builder, DatabaseMetaData dbMetaData)
throws SQLException {
builder.setUnquotedCaseStrategy(IdentifierCaseStrategy.LOWER);
return super.buildIdentifierHelper(builder, dbMetaData);
}
} And in private Optional<String> guessDialect(Optional<String> driver) {
// For now select the latest dialect from the driver
// later, we can keep doing that but also avoid DCE
// of all the dialects we want in so that people can override them
String resolvedDriver = driver.orElse("NODRIVER");
if (resolvedDriver.contains("postgresql")) {
return Optional.of(QuarkusPostgreSQL95Dialect.class.getName());
}
... This gets me unstuck. I wonder why the postgres dialect does not do that by default? I've never seen a postgres DB configured with unquoted mixed case. |
I spoke with @Sanne and we will change Quarkus ORM extension behavior to adapt the naming strategy to the dialect. For Postgres, we would go lower case by default. With the expectation that users can change the naming strategy. |
This we think will be a better approach that hacking Hibernate or subclassing dialects. |
H2 and Postgres go for lower case |
I have tried setting the naming strategy to no effect. I also did not find in the code where the schema-update code uses the strategy, which may be related to the lack of effect. |
@emmanuelbernard but that does mean that it will still not work by default with Hibernate ORM? What I'm wondering is if the change suggested by @FroMage should go in ORM proper. It seems like the behavior we would want. |
@FroMage I'll investigate that |
@gsmet with ORM 6 coming I think I'm fine with that compromise. Can't cure world hunger in one commit. |
If we do the change here and people love it, it makes it easier to justify porting it upstream later, for a lower risk to non-Quarkus ORM users. |
Ok so update for everyone. It turns out that the Dialect has a way to tell whether a DB is upper case or lower case for its identifiers and that setup is separate for quoted identifiers and non quoted ones. H2 seems to be uppercase for non quoted, and mixed for quoted So changing the dialect tree probably would be a better approach than changing the physical naming strategy |
@Sanne @gsmet @FroMage I looked at the code and I now agree that the dialect I think the dialect changes should go in ORM upstream but with Steve and Andrea's load I did not want it to be a roadbloacker. It would be good to get their perspective. |
CC @gsmet For now it's fine to put it like that in Quarkus. And we can decide to go for the physical naming strategy approach later. Or the strategy I proposed which was to ignore casing for DB comparisons. The latter we can add a flag for the few that do DB casing for some reason. I'd love to see the Pg DB config options around that though as I think it might go against SQL-92 to enforce casing on unquoted identifiers. |
+1 for such a solution in quarkus. Power users can switch dialects. |
application.properties
Developer.java
When I uncomment favoriteFramework, I get
Actions todo #1886 (comment)
drop-and-create
vsupdate
The text was updated successfully, but these errors were encountered: