Skip to content

Delete rename trigger before creating to prevent error

Reuben Pereira requested to merge fix-migration into master

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

Performance and Testing

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
Edited by 🤖 GitLab Bot 🤖

Merge request reports