diff options
Diffstat (limited to 'db')
4 files changed, 20 insertions, 104 deletions
diff --git a/db/migrate/20200116051619_drop_activate_prometheus_services_for_shared_cluster_applications_background_migration.rb b/db/migrate/20200116051619_drop_activate_prometheus_services_for_shared_cluster_applications_background_migration.rb new file mode 100644 index 00000000000..39f450be716 --- /dev/null +++ b/db/migrate/20200116051619_drop_activate_prometheus_services_for_shared_cluster_applications_background_migration.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class DropActivatePrometheusServicesForSharedClusterApplicationsBackgroundMigration < ActiveRecord::Migration[5.2] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + DROPPED_JOB_CLASS = 'ActivatePrometheusServicesForSharedClusterApplications' + QUEUE = 'background_migration' + + def up + Sidekiq::Queue.new(QUEUE).each do |job| + klass, project_id, *should_be_empty = job.args + next unless klass == DROPPED_JOB_CLASS && project_id.is_a?(Integer) && should_be_empty.empty? + + job.delete + end + end +end diff --git a/db/migrate/20200129234037_replace_conan_metadata_index.rb b/db/migrate/20200129234037_replace_conan_metadata_index.rb deleted file mode 100644 index 4f55a2974d8..00000000000 --- a/db/migrate/20200129234037_replace_conan_metadata_index.rb +++ /dev/null @@ -1,25 +0,0 @@ -# frozen_string_literal: true - -class ReplaceConanMetadataIndex < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - OLD_INDEX = 'index_packages_conan_metadata_on_package_id' - NEW_INDEX = 'index_packages_conan_metadata_on_package_id_username_channel' - - disable_ddl_transaction! - - def up - add_concurrent_index :packages_conan_metadata, - [:package_id, :package_username, :package_channel], - unique: true, name: NEW_INDEX - - remove_concurrent_index_by_name :packages_conan_metadata, OLD_INDEX - end - - def down - add_concurrent_index :packages_conan_metadata, :package_id, name: OLD_INDEX - - remove_concurrent_index_by_name :packages_conan_metadata, NEW_INDEX - end -end diff --git a/db/post_migrate/20200114113341_patch_prometheus_services_for_shared_cluster_applications.rb b/db/post_migrate/20200114113341_patch_prometheus_services_for_shared_cluster_applications.rb index 68361f7b176..d49bd10887c 100644 --- a/db/post_migrate/20200114113341_patch_prometheus_services_for_shared_cluster_applications.rb +++ b/db/post_migrate/20200114113341_patch_prometheus_services_for_shared_cluster_applications.rb @@ -1,88 +1,11 @@ # 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 + # no-op 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 45fa6ca279c..8d08f7a9301 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -2945,7 +2945,7 @@ ActiveRecord::Schema.define(version: 2020_02_06_111847) do t.datetime_with_timezone "updated_at", null: false t.string "package_username", limit: 255, null: false t.string "package_channel", limit: 255, null: false - t.index ["package_id", "package_username", "package_channel"], name: "index_packages_conan_metadata_on_package_id_username_channel", unique: true + t.index ["package_id"], name: "index_packages_conan_metadata_on_package_id", unique: true end create_table "packages_dependencies", force: :cascade do |t| |