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

[jdbc] Add safety valve for suspicious migrations #13797

Merged
merged 3 commits into from
Nov 28, 2022

Conversation

jlaur
Copy link
Contributor

@jlaur jlaur commented Nov 28, 2022

This is a small follow-up to #13544 and #13737 since the combination of these features and an invalid configuration can potentially be dangerous.

Consider this case:

  • Configuration: itemsManageTable=items; tableNamePrefix=Item; tableUseRealItemNames=false; tableIdDigitCount=4, rebuildTableNames=true
  • Tables: Items, Item1, Item4, Item5

This is logically considered as a migration from real names to indexed scheme with prefixes and sequential numbers, since index (items manage table) is not found. As a result:

  • Index table items is created.
  • Item1 is renamed to Item0001 and indexed as item name "Item1".
  • Item4 is renamed to Item0002 and indexed as item name "Item4".
  • Item5 is renamed to Item0003 and indexed as item name "Item5".
  • Items is renamed to Item0004 and indexed as item name "Items".

This resulting mess can be avoided with a small sanity check: If most tables start with either the configured prefix or the hardcoded default prefix "item" (case insensitive), then log an error and abort the migration. It would be very unlikely for any user to have most items named like this.

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>
@jlaur jlaur requested a review from a team as a code owner November 28, 2022 21:11
Copy link
Contributor

@lolodomo lolodomo left a comment

Choose a reason for hiding this comment

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

LGTM

@lolodomo lolodomo merged commit 3912487 into openhab:main Nov 28, 2022
@lolodomo lolodomo added the enhancement An enhancement or new feature for an existing add-on label Nov 28, 2022
@lolodomo lolodomo added this to the 3.4 milestone Nov 28, 2022
andrasU pushed a commit to andrasU/openhab-addons that referenced this pull request Dec 24, 2022
* Abort migration from real names when most tables have table name prefix
* Add missing checks for database connection from console commands
* Add additional documentation for check/fix schema

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
Signed-off-by: Andras Uhrin <andras.uhrin@gmail.com>
borazslo pushed a commit to borazslo/openhab-mideaac-addon that referenced this pull request Jan 8, 2023
* Abort migration from real names when most tables have table name prefix
* Add missing checks for database connection from console commands
* Add additional documentation for check/fix schema

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
psmedley pushed a commit to psmedley/openhab-addons that referenced this pull request Feb 23, 2023
* Abort migration from real names when most tables have table name prefix
* Add missing checks for database connection from console commands
* Add additional documentation for check/fix schema

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
nemerdaud pushed a commit to nemerdaud/openhab-addons that referenced this pull request Feb 28, 2023
* Abort migration from real names when most tables have table name prefix
* Add missing checks for database connection from console commands
* Add additional documentation for check/fix schema

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
andrasU pushed a commit to andrasU/openhab-addons that referenced this pull request Jan 6, 2024
* Abort migration from real names when most tables have table name prefix
* Add missing checks for database connection from console commands
* Add additional documentation for check/fix schema

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
Signed-off-by: Andras Uhrin <andras.uhrin@gmail.com>
@jlaur jlaur deleted the 11906-jdbc-migration-safety-valve branch June 15, 2024 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement or new feature for an existing add-on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants