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/migrate/20210816095826_add_unique_index_on_dast_profile_to_dast_profile_schedules.rb')
-rw-r--r--db/migrate/20210816095826_add_unique_index_on_dast_profile_to_dast_profile_schedules.rb38
1 files changed, 38 insertions, 0 deletions
diff --git a/db/migrate/20210816095826_add_unique_index_on_dast_profile_to_dast_profile_schedules.rb b/db/migrate/20210816095826_add_unique_index_on_dast_profile_to_dast_profile_schedules.rb
new file mode 100644
index 00000000000..b7ea8545df1
--- /dev/null
+++ b/db/migrate/20210816095826_add_unique_index_on_dast_profile_to_dast_profile_schedules.rb
@@ -0,0 +1,38 @@
+# frozen_string_literal: true
+
+# See https://docs.gitlab.com/ee/development/migration_style_guide.html
+# for more information on how to write migrations for GitLab.
+
+class AddUniqueIndexOnDastProfileToDastProfileSchedules < ActiveRecord::Migration[6.1]
+ include Gitlab::Database::MigrationHelpers
+
+ INDEX_NAME = 'index_dast_profile_schedules_on_dast_profile_id'
+ TABLE = :dast_profile_schedules
+ # We disable these cops here because changing this index is safe. The table does not
+ # have any data in it as it's behind a feature flag.
+ # rubocop: disable Migration/AddIndex
+ # rubocop: disable Migration/RemoveIndex
+ def up
+ execute('DELETE FROM dast_profile_schedules')
+
+ if index_exists_by_name?(TABLE, INDEX_NAME)
+ remove_index TABLE, :dast_profile_id, name: INDEX_NAME
+ end
+
+ unless index_exists_by_name?(TABLE, INDEX_NAME)
+ add_index TABLE, :dast_profile_id, unique: true, name: INDEX_NAME
+ end
+ end
+
+ def down
+ execute('DELETE FROM dast_profile_schedules')
+
+ if index_exists_by_name?(TABLE, INDEX_NAME)
+ remove_index TABLE, :dast_profile_id, name: INDEX_NAME
+ end
+
+ unless index_exists_by_name?(TABLE, INDEX_NAME)
+ add_index TABLE, :dast_profile_id
+ end
+ end
+end