Help! My Kentico database is corrupt after importing the CI repository

Quite recently, one of our development teams panicked when all of a sudden they were confronted with the Kentico Database Setup wizard. After having a quick look we noticed that the database and contents was still there except the CMS_SettingsKey table which was empty...

The project leverages Continuous Integration, one of the new development features introduced with Kentico v9. The benefit of continuous integration within Kentico is that it quickly provides information in what was changed, using your favorite version control system, and helps pinpoint the cause of corruption!

Simply rolling back to earlier versions did not resolve the issue. However it resulted in some useful insights, especially because we already knew that something deleted all the Kentico settings.

In the changesets we noticed the repository.config file located in the App_Data\CIRepository folder. This file allows you to specify which object types need to be excluded from the continuous integration process. By default cms.settingskey is in the excluded list, because it could contain sensitive data. In the changeset however it was commented out:

Excluded CI object types
Excluding the settings does not directly result in errors, because Kentico will not serialize the settings to file and also not import them back using the ContinuousIntegration.exe utility. It is very important though to follow the correct workflow when utilizing the repository.config file.

To illustrate this please imagine the following scenario (don't try this at home work!):
  1. Developer A navigates to the Continuous Integration module, serializes all objects and checks in the CIRepository files and folders (without settings)
  2. Developer B fetches the changes and he comments out the cms.settingskey excluded object type in the repository.config
  3. Developer B runs ContinuousIntegration.exe -r from the command line
  4. Developer B rebuilds the project and causes the application to restart. He will be confronted with the Kentico Database Setup wizard.
Notice that in step 3 the command line utility will actually inform you of the deletion of the settings:

Settings deleted by CI

To prevent this from happening it is very important to follow the correct flow of serializing and syncing of the Continuous Integration repository. Before running the ContinuousIntegration.exe utility you need to ensure that the required state of object data is in the CIRepository. For more information check out the Kentico documentation.

In case you are left with an empty settings table, please check your version control system for changesets containing the settings or ask a fellow developer to serialize his settings and check them back in.

Hope this helps!