dev/core#1383: Fix Re-Installation of Extensions With Logging Enabled #15816
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.
Overview
If logging is enabled, CiviCRM will create log tables for every table in the CiviCRM Schema. If an extension added custom groups and fields, logging tables for those custom groups will be created. When the extension is uninstalled, custom groups and fields will get deleted. However, logging tables will remain unaffected. This may be desireable behaviour (ie. keeping the log of tables that used to exist in DB), but if the extension is re-installed, current handling of custom fields will cause a DB error, as fields will try to be added again to the logging tables as duplicates.
Before
When uninstalling an extension, logging tables associated to custom groups and fields will not be deleted. On re-installation, addition of custom fields will cause DB errors to be thrown, as columns existing on logging tables are tried to be created again (they already exist on logging tables, as they were never removed).
After
Fixed by checking if the column exists on log table before trying to create it, treating it as a modification of the schema if it exists.