summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-01-14 12:07:41 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-01-14 12:07:41 +0000
commit4ce0bee95df15c05cdb0d777eba31fe753bc443b (patch)
tree3dc6a1aae7e0a01280f6d9f7d774dd369f7863e1 /db
parent02ab65d49fc94be7c91e511899762236c122977d (diff)
downloadgitlab-ce-4ce0bee95df15c05cdb0d777eba31fe753bc443b.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'db')
-rw-r--r--db/post_migrate/20191204114127_delete_legacy_triggers.rb17
-rw-r--r--db/post_migrate/20191220102807_patch_prometheus_services_for_shared_cluster_applications.rb88
-rw-r--r--db/schema.rb2
3 files changed, 18 insertions, 89 deletions
diff --git a/db/post_migrate/20191204114127_delete_legacy_triggers.rb b/db/post_migrate/20191204114127_delete_legacy_triggers.rb
new file mode 100644
index 00000000000..82d901ae689
--- /dev/null
+++ b/db/post_migrate/20191204114127_delete_legacy_triggers.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class DeleteLegacyTriggers < ActiveRecord::Migration[5.2]
+ DOWNTIME = false
+
+ def up
+ execute <<~SQL
+ DELETE FROM ci_triggers WHERE owner_id IS NULL
+ SQL
+
+ change_column_null :ci_triggers, :owner_id, false
+ end
+
+ def down
+ change_column_null :ci_triggers, :owner_id, true
+ end
+end
diff --git a/db/post_migrate/20191220102807_patch_prometheus_services_for_shared_cluster_applications.rb b/db/post_migrate/20191220102807_patch_prometheus_services_for_shared_cluster_applications.rb
deleted file mode 100644
index 68361f7b176..00000000000
--- a/db/post_migrate/20191220102807_patch_prometheus_services_for_shared_cluster_applications.rb
+++ /dev/null
@@ -1,88 +0,0 @@
-# frozen_string_literal: true
-
-class PatchPrometheusServicesForSharedClusterApplications < ActiveRecord::Migration[5.2]
- include Gitlab::Database::MigrationHelpers
-
- DOWNTIME = false
- MIGRATION = 'ActivatePrometheusServicesForSharedClusterApplications'.freeze
- BATCH_SIZE = 500
- DELAY = 2.minutes
-
- disable_ddl_transaction!
-
- module Migratable
- module Applications
- class Prometheus < ActiveRecord::Base
- self.table_name = 'clusters_applications_prometheus'
-
- enum status: {
- errored: -1,
- installed: 3,
- updated: 5
- }
- end
- end
-
- class Project < ActiveRecord::Base
- self.table_name = 'projects'
- include ::EachBatch
-
- scope :with_application_on_group_clusters, -> {
- joins("INNER JOIN namespaces ON namespaces.id = projects.namespace_id")
- .joins("INNER JOIN cluster_groups ON cluster_groups.group_id = namespaces.id")
- .joins("INNER JOIN clusters ON clusters.id = cluster_groups.cluster_id AND clusters.cluster_type = #{Cluster.cluster_types['group_type']}")
- .joins("INNER JOIN clusters_applications_prometheus ON clusters_applications_prometheus.cluster_id = clusters.id
- AND clusters_applications_prometheus.status IN (#{Applications::Prometheus.statuses[:installed]}, #{Applications::Prometheus.statuses[:updated]})")
- }
-
- scope :without_active_prometheus_services, -> {
- joins("LEFT JOIN services ON services.project_id = projects.id AND services.type = 'PrometheusService'")
- .where("services.id IS NULL OR (services.active = FALSE AND services.properties = '{}')")
- }
- end
-
- class Cluster < ActiveRecord::Base
- self.table_name = 'clusters'
-
- enum cluster_type: {
- instance_type: 1,
- group_type: 2
- }
-
- def self.has_prometheus_application?
- joins("INNER JOIN clusters_applications_prometheus ON clusters_applications_prometheus.cluster_id = clusters.id
- AND clusters_applications_prometheus.status IN (#{Applications::Prometheus.statuses[:installed]}, #{Applications::Prometheus.statuses[:updated]})").exists?
- end
- end
- end
-
- def up
- projects_without_active_prometheus_service.group('projects.id').each_batch(of: BATCH_SIZE) do |batch, index|
- bg_migrations_batch = batch.select('projects.id').map { |project| [MIGRATION, project.id] }
- delay = index * DELAY
- BackgroundMigrationWorker.bulk_perform_in(delay.seconds, bg_migrations_batch)
- end
- end
-
- def down
- # no-op
- end
-
- private
-
- def projects_without_active_prometheus_service
- scope = Migratable::Project.without_active_prometheus_services
-
- return scope if migrate_instance_cluster?
-
- scope.with_application_on_group_clusters
- end
-
- def migrate_instance_cluster?
- if instance_variable_defined?('@migrate_instance_cluster')
- @migrate_instance_cluster
- else
- @migrate_instance_cluster = Migratable::Cluster.instance_type.has_prometheus_application?
- end
- end
-end
diff --git a/db/schema.rb b/db/schema.rb
index 689428ea4cb..56b0cbde61a 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -994,7 +994,7 @@ ActiveRecord::Schema.define(version: 2020_01_08_233040) do
t.datetime "created_at"
t.datetime "updated_at"
t.integer "project_id"
- t.integer "owner_id"
+ t.integer "owner_id", null: false
t.string "description"
t.string "ref"
t.index ["owner_id"], name: "index_ci_triggers_on_owner_id"