Join GitHub today
JDBCStateRepository not schema aware #38
It seems as if the JDBCStateRepository is not schema aware. At least I ran into problems when I tried to let Togglz create and migrate the metadata. It didn't add the strategy columns. And I noticed that the SchemaUpdater provides "null" for the schema pattern when fiddling with the metadata.
Version 2.0.0.Beta1, PostgreSQL
referenced this issue
Apr 30, 2013
first of all: Sorry, for my delayed response. I was traveling last week, so I wasn't able to answer earlier.
is this perhaps related to #39? Looks like the same issue to me.
The JDBC spec says regarding the schema parameter:
I guess you are right. Passing null here is not a good idea. Although I would expect that Postgres returns the table (and maybe more located in other schemas) when passing null.
To be honest, I'm a bit unsure how to handle this case consistently across all databases.
The schema is important in two places:
Any thought on this?
For the delayed response: no problem at all. I could work around the problem quite easily.
The SQL queries itself are not problematic (in my case) as they will use the default schema/user.
So it might be a good idea to provide the JDBCStateRepository with another optional argument for the schema to be used - especially for the metadata queries. What do you think?
I also thought of using the user name, but this isn't the default for MSSQL which uses "dbo" as the default schema.
I'll play a bit with different approaches. Could you perhaps help me by testing the new approach against Postgres as soon as it is done? That would be awesome. :)
No, sorry, but I'll hope to find some time tomorrow to work on this.
The recommended way to work around this issue is to do the following:
See the java docs for JDBCStateRepository for details:
Thanks for your quick reply, i used this quick "hack" since i keep creating new environments:
throws an exception on startup but works great until the patch will comeout :)
I think this issue should be fixed now. I deployed new snapshots for you to test. If you want to give it a try, you have to add this snapshot repository to your pom.xml:
Then set the Togglz version to
Let me know if you need more detailed instructions on how to use the snapshots.
Looking forward to your feedback. :)
Nice to hear that it's working now.
I had a look at the Liquibase source (a popular tool for database schema migration) to find out how they do it. Actually they are using database dependent classes who can answer questions like "what is the default schema for this db?". However IMHO this is an overkill for Togglz.
So I decided to go with a very naive way of determining the current version of the database schema. Actually I perform multiple queries which read the table and/or specific column. If specific queries work and others not, I can identify which version of the table is currently in the DB and send the corresponding migration commands.
I know, this is very dirty. But I see no other easy way to solve this issue. And actually it works fine. :)
I think I'll publish a new beta release by the end of this week or early next week. So stay tuned. :)