-
-
Notifications
You must be signed in to change notification settings - Fork 3.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
[jdbc] Add support for case sensitive table names reflecting item names 1:1 #13544
[jdbc] Add support for case sensitive table names reflecting item names 1:1 #13544
Conversation
This pull request has been mentioned on openHAB Community. There might be relevant details there: |
I am looking forward to this fix. Currently I have the slight feeling that it will break a lot of users persistence when they are already using the Furthermore I would like to question if the mentioned |
Good point, this needs to be verified (I have not started any testing yet): Lines 320 to 377 in 37a91ab
This should be possible by using the existing configuration option rebuildTableNames: But now it needs to support also migration from old to new behavior.
Agreed, by principle it shouldn't be needed, although it might require some additional effort to get rid of. Also, case sensitivity would need to be checked - I believe I saw some example in the forum thread with lower case table names while having camel case item names. |
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
a3579f9
to
c843a1c
Compare
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
234b19e
to
c62672a
Compare
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
6ae8e54
to
d896763
Compare
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
bf4bbd2
to
151a43f
Compare
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
@cweitkamp - as I've been working my way through this, getting more acquainted with the code and also started testing things, I have now realized a few things and could use some feedback. Even though current implementation of tableUseRealItemNames is inconsistent with the documentation, you have a valid point that users might be using this, so we need backwards compatibility. Therefore I would suggest to fix the documentation and keep current behavior when using just tableUseRealItemNames. In the latest commit I introduced tablePreserveCase, but now I would suggest to change/simplify this so we don't have many strange combinations of options, but instead just this:
A better name for the new option would be needed. :-) The thinking is that without case sensitive naming of tables, we risk collisions since item names in openHAB are case sensitive, i.e. you can have both MyItem and myItem. So to really solve that, we would need a suffix of some sort anyway. Case sensitive table names can depend on database, OS, filesystem, database configuration and other things, but IMHO this would be required for this fix to make any sense. So either users can choose current behavior with number suffix, or if supported by their database, they can use direct mapping from item name to table name. Now, the only problem left could be difference in rules between item naming and table naming. I didn't mange to find the regex for item names yet, but from the UI at least it seems to be quite restrictive, so I'm hoping this won't be a problem. If an item could be named my-item, for example, this would be stripped to myitem, and then we would again risk collisions. I have provided unit tests documenting the issues and migration paths. Next, if we agree on some sensible approach, I would then adapt the code, tests and documentation accordingly, which shouldn't be much additional work at this point. I would also be prepared to drop the items table entirely when running in "new mode". |
Remove real name in lower case without suffix mode Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
b8456df
to
6da14c2
Compare
Now found item name regex: As it is more restrictive than the current regex for table names, case sensitive table names will be safe from collisions. |
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
88da107
to
330aae2
Compare
@cweitkamp - done. Backwards compatibility ensured and all migration paths supported. |
This pull request has been mentioned on openHAB Community. There might be relevant details there: |
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
@openhab/add-ons-maintainers - I'm not sure whether this should be labelled as "bug" or "enhancement". For sure the documentation was misleading. In either case, would anyone be up for reviewing this? It would be really nice to finalize for the next milestone, so there would still be time for user feedback before the release. tableUseRealItemNames
True, they were used, but lowercased and with a number suffix added (MyItem -> myitem_0001).
True.
True. However, without using tableIdDigitCount
(which was also the case when
True. But there would still be sequential numbers with padding according to this setting with |
@cweitkamp - do you think you could find time to have a look at this? |
@jlaur : having a look at the global result of the static code analysis (all bindings), I found that one. Maybe you could check,. |
I already checked this in context of #13429, but I'm not sure what to do with it: Lines 97 to 104 in 813489c
It looks like it was generated by Eclipse: It will work according to implementation requirements, but of course it would be nice to get rid of this checkstyle warning. |
@lolodomo - would you be able to find time for reviewing this PR before M4? I have time the next few evenings for making corrections during review. |
Probably only a limited time until next weekend. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have not reviewed in details but looks good to me.
Just one question.
...openhab.persistence.jdbc/src/main/java/org/openhab/persistence/jdbc/internal/JdbcMapper.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you
…es 1:1 (openhab#13544) * Do not append number when using real item names * Extract getTableName to separate class * Add initial test coverage * Extract migration logic to separate class * Support migration from real names back to numbered * Simplify zero-padding * Fix NullPointerException * Fix MySQL compatibility when CLIENT_MULTI_STATEMENTS option is not set * Add option for case sensitive table names * Add real name with suffix mode for backwards compatibility * Remove real name in lower case without suffix mode * Map directly from item name to table name * Fix ambiguous table name scenario * Add additional testcase * Add migration path for changed table prefix * Drop items table when using direct mapping * Add configuration note * Fix table alignment * Extend description as more migration paths are now supported * Do not stop halfway through a migration * For clarity, do not use abbreviation for operating system Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
@lolodomo - this is now addressed by commit 18892b8 in #13719. |
…es 1:1 (openhab#13544) * Do not append number when using real item names * Extract getTableName to separate class * Add initial test coverage * Extract migration logic to separate class * Support migration from real names back to numbered * Simplify zero-padding * Fix NullPointerException * Fix MySQL compatibility when CLIENT_MULTI_STATEMENTS option is not set * Add option for case sensitive table names * Add real name with suffix mode for backwards compatibility * Remove real name in lower case without suffix mode * Map directly from item name to table name * Fix ambiguous table name scenario * Add additional testcase * Add migration path for changed table prefix * Drop items table when using direct mapping * Add configuration note * Fix table alignment * Extend description as more migration paths are now supported * Do not stop halfway through a migration * For clarity, do not use abbreviation for operating system Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
…es 1:1 (openhab#13544) * Do not append number when using real item names * Extract getTableName to separate class * Add initial test coverage * Extract migration logic to separate class * Support migration from real names back to numbered * Simplify zero-padding * Fix NullPointerException * Fix MySQL compatibility when CLIENT_MULTI_STATEMENTS option is not set * Add option for case sensitive table names * Add real name with suffix mode for backwards compatibility * Remove real name in lower case without suffix mode * Map directly from item name to table name * Fix ambiguous table name scenario * Add additional testcase * Add migration path for changed table prefix * Drop items table when using direct mapping * Add configuration note * Fix table alignment * Extend description as more migration paths are now supported * Do not stop halfway through a migration * For clarity, do not use abbreviation for operating system Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
…es 1:1 (openhab#13544) * Do not append number when using real item names * Extract getTableName to separate class * Add initial test coverage * Extract migration logic to separate class * Support migration from real names back to numbered * Simplify zero-padding * Fix NullPointerException * Fix MySQL compatibility when CLIENT_MULTI_STATEMENTS option is not set * Add option for case sensitive table names * Add real name with suffix mode for backwards compatibility * Remove real name in lower case without suffix mode * Map directly from item name to table name * Fix ambiguous table name scenario * Add additional testcase * Add migration path for changed table prefix * Drop items table when using direct mapping * Add configuration note * Fix table alignment * Extend description as more migration paths are now supported * Do not stop halfway through a migration * For clarity, do not use abbreviation for operating system Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
Add support for case sensitive tables named 1:1 by corresponding items, eliminating the need for an items management/mapping table.
Additionally:
Fixes #11906
MySQL and Multiple Statement Execution Support
When Multiple Statement Execution Support is not configured/supported, the following exception would be thrown when migrating tables:
References
Testing
I have manually tested most combinations of migration paths:
S = Source, T = Target
Prefix = tableNamePrefix, Real = tableUseRealItemNames, Case = tableCaseSensitiveItemNames, Digit = tableIdDigitCount
All of the above on a test database both with a copy of my production schema consisting of more than 200 tables, as well as small dedicated test scenarios with tricky naming etc.
Additionally I have performed tests of creating new items and tables with different configurations.
All tests have been performed only in MySQL. A forum user has tested with MariaDB.
JAR for testing: https://drive.google.com/file/d/1_CmJtYa2pwrN_LlrWu1H75muOW6seam7/view?usp=sharing
Note: Place the corresponding database driver into the addons directory. For example, download the MySQL connector and rename it to mysql-connector-java.jar.