diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-01-18 22:00:14 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-01-18 22:00:14 +0300 |
commit | 05f0ebba3a2c8ddf39e436f412dc2ab5bf1353b2 (patch) | |
tree | 11d0f2a6ec31c7793c184106cedc2ded3d9a2cc5 /db/migrate/20221209174157_truncate_sbom_occurrences.rb | |
parent | ec73467c23693d0db63a797d10194da9e72a74af (diff) |
Add latest changes from gitlab-org/gitlab@15-8-stable-eev15.8.0-rc42
Diffstat (limited to 'db/migrate/20221209174157_truncate_sbom_occurrences.rb')
-rw-r--r-- | db/migrate/20221209174157_truncate_sbom_occurrences.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/db/migrate/20221209174157_truncate_sbom_occurrences.rb b/db/migrate/20221209174157_truncate_sbom_occurrences.rb new file mode 100644 index 00000000000..e9db6526e2d --- /dev/null +++ b/db/migrate/20221209174157_truncate_sbom_occurrences.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +class TruncateSbomOccurrences < Gitlab::Database::Migration[2.1] + def up + # Because existing data in the table violates the new + # uniqueness constraints, we need to remove the non-distinct rows. + # Rather than do an expensive and error-prone batch migration + # to find and remove the duplicates, we'll just remove all records + # from the table. + # + # The `cyclonedx_sbom_ingestion` feature flag should + # be OFF in all environments to avoid having more duplicate records + # added between this migration and the one where the new unqiue index + # is added. + + # TRUNCATE is a DDL statement (it drops the table and re-creates it), so we want to run the + # migration in DDL mode, but we also don't want to execute it against all schemas because + # it's considered a write operation. So, we'll manually check and skip the migration if + # it's on not `:gitlab_main`. + return unless Gitlab::Database.gitlab_schemas_for_connection(connection).include?(:gitlab_main) + + execute('TRUNCATE sbom_occurrences') + end + + def down + # no-op + end +end |