Delete rename trigger before creating to prevent error
What does this MR do?
Migration helpers like rename_column_concurrently
create triggers to keep old and new columns in sync.
In specs, down
methods of migrations might be run multiple times (https://gitlab.com/gitlab-org/gitlab-ce/blob/f74de0c144473b20bded6d236bfef0ca010fd0c4/spec/spec_helper.rb#L249). If a down
method contains a call to rename_column_concurrently
, it will create a trigger and the next time the same down
method is called, it will try to create the trigger again. Since the trigger already exists, an error will occur.
For example in https://gitlab.com/gitlab-org/gitlab-ce/-/jobs/279249744, the error is ERROR: trigger "trigger_981a520d34e5" for relation "application_settings" already exists
.
The later errors (ERROR: column "allow_local_requests_from_hooks_and_services" of relation "application_settings" already exists
) are caused by migrations running only partially and failing. And since ddl transactions are disabled when using the *_concurrently
migration helpers, the partial changes are not rolled back.
Issue: https://gitlab.com/gitlab-org/gitlab-ce/issues/66540
Screenshots
Does this MR meet the acceptance criteria?
Conformity
-
Changelog entry for user-facing changes, or community contribution. Check the link for other scenarios. -
Documentation created/updated or follow-up review issue created -
Code review guidelines -
Merge request performance guidelines -
Style guides -
Database guides -
Separation of EE specific content
Performance and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process. -
Tested in all supported browsers
Security
If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:
-
Label as security and @ mention @gitlab-com/gl-security/appsec
-
The MR includes necessary changes to maintain consistency between UI, API, email, or other methods -
Security reports checked/validated by a reviewer from the AppSec team