Upgrades after db restore of 15.1.x fails with duplicate function insert_vulnerability_reads_from_vulnerability
Summary
Upgrades can fail with a duplicate function error if users have previously restored a gitlab backup due to a migration introduced in !92198 (merged)
The error during db:migrate rake task:
ActiveRecord::StatementInvalid: PG::DuplicateFunction: ERROR: function "insert_vulnerability_reads_from_vulnerability" already exists with same argument types
The function will exist if users where on a version of gitlab that included it, but then restore from backup to a previous version. The restore doesn't clear out these functions. The restore will function fine, but later upgrades will hit this error during migrations as they attempt to create functions that already exist.
Steps to reproduce
- Using gdk, setup an fresh database using the 15-1-stable branch, or any commit prior to !92198 (merged)
- Take a backup of the working instance
- Upgrade the database to the latest master (or any commit after the MR that introduced this function)
- Restore the backup
- Upgrade once again to the latest master (or any commit after the MR that introduced this function)
Example Project
This is tripping up our backup/restore tests on the master branch of the helm chart project. Issue here: gitlab-org/charts/gitlab#3422 (closed)
What is the current bug behavior?
Duplicate function name error during migrations
What is the expected correct behavior?
If exists, the function should just be replaced during migrations.