Re-installation of Extension With Custom Fields and Logging Enabled Causes Error
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 loog 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.
Reproduction steps
- Enable DB logging.
- Install an extension that creates custom groups and fields, and deletes them on uninstallation (ie. https://github.com/compucorp/uk.co.compucorp.manualdirectdebit).
- Uninstall the extension.
- Re-install the extension.
- A DB error is thrown, making it impossible to re-install the extension, and leaving the DB in an inconsistent state, as the extension will be half-way through installation, with some changes already commited to DB.
Current behaviour
- Enable DB logging.
- Install an extension that creates custom groups and fields, and deletes them on uninstallation (ie. https://github.com/compucorp/uk.co.compucorp.manualdirectdebit).
- Uninstall the extension.
- Re-install the extension.
- A DB error is thrown, making it impossible to install the extension, and leaving the DB in an inconsistent state, as the extension will be half-way through installation, with some changes already commited to DB.
Expected behaviour
- Enable DB logging.
- Install an extension that creates custom groups and fields, and deletes them on uninstallation (ie. https://github.com/compucorp/uk.co.compucorp.manualdirectdebit).
- Uninstall the extension.
- Re-install the extension.
- The extension is installed successfully.
Environment information
- CiviCRM: _Master/5.20.0/5.19.1/5.19.0
- PHP: 7.0/7.1/7.2/7.3/...
- CMS: Drupal 7.30...
- Database: MySQL 5.7.7
- Web Server: Apache 2.4/Nginx 1.16
Comments
Anything else you would like the reviewer to note.