Add notifications_schema table & verify on daemon startup#422
Open
yhabteab wants to merge 1 commit into
Open
Conversation
Member
|
Focusing on the schema differences here: That the I too find it confusing that the schema table of icingadb uses a integer that differs from the file name or product version… |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds a new
notifications_schematable to the database, which is used to store the schema version for notifications. It quite similar to the one used in Icinga DB, but with a small but important difference: theversioncolumn is of typeTEXTinstead ofINTEGERas opposed to Icinga DB. Instead of using an independent integer versioning system that can't be easily determined to which Icinga Notifications version it corresponds, we will use the actual semver version exactly as its upgrade script is named. This way, we can easily determine which version of the upgrade script corresponds to which version of Icinga Notifications or at least to which version of the upgrade script it corresponds.In order to prevent users from applying the upgrade scripts out of order or the same script multiple times, any upgrade script after Icinga Notifications
v1.0will have use an SQL procedure introduced in this PR, which will check if the current version in thenotifications_schematable matches the expected one before applying the upgrade. If the version does not match, the procedure will raise an error and prevent the upgrade from being applied. For instance, if we have an upgrade script for versionv1.1, at the top of the script we will have a call to the procedure like this:CALL assert_correct_schema_version('v1.0');This ensures that the current upgrade script can only be applied if the current version in the
notifications_schematable isv1.0, which means that the previous upgrade script has been applied. If the current version is notv1.0, the procedure will raise an error and prevent the upgrade from being applied, thus ensuring that the upgrade scripts are applied in the correct order and that no script is applied multiple times. And of course, Icinga Notifications performs a check at startup to ensure that the expected schema version is applied before doing anything else, but it doesn't go through thenotifications_schemaentries to determine for missing upgrade scripts since that is supposed to be handled by the upgrade scripts themselves.resolves #343