Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'db/post_migrate/20210825182303_remove_duplicate_dast_site_tokens_with_same_token.rb')
-rw-r--r--db/post_migrate/20210825182303_remove_duplicate_dast_site_tokens_with_same_token.rb23
1 files changed, 23 insertions, 0 deletions
diff --git a/db/post_migrate/20210825182303_remove_duplicate_dast_site_tokens_with_same_token.rb b/db/post_migrate/20210825182303_remove_duplicate_dast_site_tokens_with_same_token.rb
new file mode 100644
index 00000000000..4d8e18ba8ed
--- /dev/null
+++ b/db/post_migrate/20210825182303_remove_duplicate_dast_site_tokens_with_same_token.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+class RemoveDuplicateDastSiteTokensWithSameToken < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ INDEX_NAME = 'index_dast_site_token_on_token'
+
+ # rubocop: disable Migration/AddIndex
+ def up
+ execute("WITH duplicate_tokens AS(
+ SELECT id, rank() OVER (PARTITION BY token ORDER BY id) r FROM dast_site_tokens
+ )
+ DELETE FROM dast_site_tokens c USING duplicate_tokens t
+ WHERE c.id = t.id AND t.r > 1;")
+
+ add_index :dast_site_tokens, :token, name: INDEX_NAME, unique: true
+ end
+
+ # rubocop: disable Migration/RemoveIndex
+ def down
+ remove_index :dast_site_tokens, :token, name: INDEX_NAME
+ end
+end