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
path: root/db
diff options
context:
space:
mode:
Diffstat (limited to 'db')
-rw-r--r--db/post_migrate/20200406102120_backfill_deployment_clusters_from_deployments.rb2
-rw-r--r--db/post_migrate/20200811130433_create_missing_vulnerabilities_issue_links.rb4
-rw-r--r--db/post_migrate/20210311045139_set_traversal_ids_for_gitlab_org_group_com.rb88
-rw-r--r--db/schema_migrations/202103110451391
4 files changed, 92 insertions, 3 deletions
diff --git a/db/post_migrate/20200406102120_backfill_deployment_clusters_from_deployments.rb b/db/post_migrate/20200406102120_backfill_deployment_clusters_from_deployments.rb
index 76b00796d1a..ab217ba92ab 100644
--- a/db/post_migrate/20200406102120_backfill_deployment_clusters_from_deployments.rb
+++ b/db/post_migrate/20200406102120_backfill_deployment_clusters_from_deployments.rb
@@ -17,7 +17,7 @@ class BackfillDeploymentClustersFromDeployments < ActiveRecord::Migration[6.0]
class Deployment < ActiveRecord::Base
include EachBatch
- default_scope { where('cluster_id IS NOT NULL') } # rubocop:disable Cop/DefaultScope
+ default_scope { where.not(cluster_id: nil) } # rubocop:disable Cop/DefaultScope
self.table_name = 'deployments'
end
diff --git a/db/post_migrate/20200811130433_create_missing_vulnerabilities_issue_links.rb b/db/post_migrate/20200811130433_create_missing_vulnerabilities_issue_links.rb
index 891201eaa52..031d9ea49e2 100644
--- a/db/post_migrate/20200811130433_create_missing_vulnerabilities_issue_links.rb
+++ b/db/post_migrate/20200811130433_create_missing_vulnerabilities_issue_links.rb
@@ -18,11 +18,11 @@ class CreateMissingVulnerabilitiesIssueLinks < ActiveRecord::Migration[6.0]
disable_ddl_transaction!
def up
- VulnerabilitiesFeedback.where('issue_id IS NOT NULL').each_batch do |relation|
+ VulnerabilitiesFeedback.where.not(issue_id: nil).each_batch do |relation|
timestamp = Time.now
issue_links = relation
.joins("JOIN vulnerability_occurrences vo ON vo.project_id = vulnerability_feedback.project_id AND vo.report_type = vulnerability_feedback.category AND encode(vo.project_fingerprint, 'hex') = vulnerability_feedback.project_fingerprint")
- .where('vo.vulnerability_id IS NOT NULL')
+ .where.not('vo.vulnerability_id' => nil)
.pluck(:vulnerability_id, :issue_id)
.map do |v_id, i_id|
{
diff --git a/db/post_migrate/20210311045139_set_traversal_ids_for_gitlab_org_group_com.rb b/db/post_migrate/20210311045139_set_traversal_ids_for_gitlab_org_group_com.rb
new file mode 100644
index 00000000000..8cef1f1cc2b
--- /dev/null
+++ b/db/post_migrate/20210311045139_set_traversal_ids_for_gitlab_org_group_com.rb
@@ -0,0 +1,88 @@
+# frozen_string_literal: true
+
+class SetTraversalIdsForGitlabOrgGroupCom < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ def up
+ return unless Gitlab.com?
+
+ # namespace ID 9970 is gitlab-org on .com
+ with_lock_retries do
+ execute(<<~SQL)
+ UPDATE
+ namespaces
+ SET
+ traversal_ids = cte.traversal_ids
+ FROM
+ (
+ WITH RECURSIVE cte(id, traversal_ids, cycle) AS (
+ VALUES
+ (9970, ARRAY[9970], false)
+ UNION ALL
+ SELECT
+ n.id,
+ cte.traversal_ids || n.id,
+ n.id = ANY(cte.traversal_ids)
+ FROM
+ namespaces n,
+ cte
+ WHERE
+ n.parent_id = cte.id
+ AND NOT cycle
+ )
+ SELECT
+ id,
+ traversal_ids
+ FROM
+ cte FOR
+ UPDATE
+ ) as cte
+ WHERE
+ namespaces.id = cte.id
+ AND namespaces.traversal_ids <> cte.traversal_ids
+ SQL
+ end
+ end
+
+ def down
+ return unless Gitlab.com?
+
+ # namespace ID 9970 is gitlab-org on .com
+ with_lock_retries do
+ execute(<<~SQL)
+ UPDATE
+ namespaces
+ SET
+ traversal_ids = '{}'
+ FROM
+ (
+ WITH RECURSIVE cte(id, traversal_ids, cycle) AS (
+ VALUES
+ (9970, ARRAY[9970], false)
+ UNION ALL
+ SELECT
+ n.id,
+ cte.traversal_ids || n.id,
+ n.id = ANY(cte.traversal_ids)
+ FROM
+ namespaces n,
+ cte
+ WHERE
+ n.parent_id = cte.id
+ AND NOT cycle
+ )
+ SELECT
+ id,
+ traversal_ids
+ FROM
+ cte FOR
+ UPDATE
+ ) as cte
+ WHERE
+ namespaces.id = cte.id
+ SQL
+ end
+ end
+end
diff --git a/db/schema_migrations/20210311045139 b/db/schema_migrations/20210311045139
new file mode 100644
index 00000000000..71026c1b2af
--- /dev/null
+++ b/db/schema_migrations/20210311045139
@@ -0,0 +1 @@
+2387c8a5516aaf8bcf44c9bad45bfc9844d68d2c03330f67773ce046b21a7a6c \ No newline at end of file