From 40254b9ace2a74a3c9f1cc51a1b1d5e3e78c1ae9 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Fri, 17 Jan 2020 21:08:29 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- ..._retry_count_and_group_id_to_import_failures.rb | 11 ++++++++ ...34_add_group_index_and_fk_to_import_failures.rb | 22 +++++++++++++++ ...2554_update_project_index_to_import_failures.rb | 22 +++++++++++++++ .../20190924152703_migrate_issue_trackers_data.rb | 31 ++++++++++++++++++++++ db/schema.rb | 10 ++++--- 5 files changed, 93 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20200115135132_add_retry_count_and_group_id_to_import_failures.rb create mode 100644 db/migrate/20200115135234_add_group_index_and_fk_to_import_failures.rb create mode 100644 db/migrate/20200117112554_update_project_index_to_import_failures.rb create mode 100644 db/post_migrate/20190924152703_migrate_issue_trackers_data.rb (limited to 'db') diff --git a/db/migrate/20200115135132_add_retry_count_and_group_id_to_import_failures.rb b/db/migrate/20200115135132_add_retry_count_and_group_id_to_import_failures.rb new file mode 100644 index 00000000000..8f62aaba60e --- /dev/null +++ b/db/migrate/20200115135132_add_retry_count_and_group_id_to_import_failures.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class AddRetryCountAndGroupIdToImportFailures < ActiveRecord::Migration[5.2] + DOWNTIME = false + + def change + add_column :import_failures, :retry_count, :integer + add_column :import_failures, :group_id, :integer + change_column_null(:import_failures, :project_id, true) + end +end diff --git a/db/migrate/20200115135234_add_group_index_and_fk_to_import_failures.rb b/db/migrate/20200115135234_add_group_index_and_fk_to_import_failures.rb new file mode 100644 index 00000000000..ae0d6d31c42 --- /dev/null +++ b/db/migrate/20200115135234_add_group_index_and_fk_to_import_failures.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +class AddGroupIndexAndFkToImportFailures < ActiveRecord::Migration[5.2] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + GROUP_INDEX = 'index_import_failures_on_group_id_not_null'.freeze + + disable_ddl_transaction! + + def up + add_concurrent_index(:import_failures, :group_id, where: 'group_id IS NOT NULL', name: GROUP_INDEX) + + add_concurrent_foreign_key(:import_failures, :namespaces, column: :group_id) + end + + def down + remove_foreign_key(:import_failures, column: :group_id) + + remove_concurrent_index_by_name(:import_failures, GROUP_INDEX) + end +end diff --git a/db/migrate/20200117112554_update_project_index_to_import_failures.rb b/db/migrate/20200117112554_update_project_index_to_import_failures.rb new file mode 100644 index 00000000000..1e8347aad44 --- /dev/null +++ b/db/migrate/20200117112554_update_project_index_to_import_failures.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +class UpdateProjectIndexToImportFailures < ActiveRecord::Migration[5.2] + include Gitlab::Database::MigrationHelpers + + # Set this constant to true if this migration requires downtime. + DOWNTIME = false + PROJECT_INDEX_OLD = 'index_import_failures_on_project_id'.freeze + PROJECT_INDEX_NEW = 'index_import_failures_on_project_id_not_null'.freeze + + disable_ddl_transaction! + + def up + add_concurrent_index(:import_failures, :project_id, where: 'project_id IS NOT NULL', name: PROJECT_INDEX_NEW) + remove_concurrent_index_by_name(:import_failures, PROJECT_INDEX_OLD) + end + + def down + add_concurrent_index(:import_failures, :project_id, name: PROJECT_INDEX_OLD) + remove_concurrent_index_by_name(:import_failures, PROJECT_INDEX_NEW) + end +end diff --git a/db/post_migrate/20190924152703_migrate_issue_trackers_data.rb b/db/post_migrate/20190924152703_migrate_issue_trackers_data.rb new file mode 100644 index 00000000000..93ea501e7e0 --- /dev/null +++ b/db/post_migrate/20190924152703_migrate_issue_trackers_data.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +class MigrateIssueTrackersData < ActiveRecord::Migration[5.1] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + INTERVAL = 3.minutes.to_i + BATCH_SIZE = 5_000 + MIGRATION = 'MigrateIssueTrackersSensitiveData' + + disable_ddl_transaction! + + class Service < ActiveRecord::Base + self.table_name = 'services' + self.inheritance_column = :_type_disabled + + include ::EachBatch + end + + def up + relation = Service.where(category: 'issue_tracker').where("properties IS NOT NULL AND properties != '{}' AND properties != ''") + queue_background_migration_jobs_by_range_at_intervals(relation, + MIGRATION, + INTERVAL, + batch_size: BATCH_SIZE) + end + + def down + # no need + end +end diff --git a/db/schema.rb b/db/schema.rb index 8c019f96f94..8ee1f2ffea6 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2020_01_14_204949) do +ActiveRecord::Schema.define(version: 2020_01_17_112554) do # These are extensions that must be enabled in order to support this database enable_extension "pg_trgm" @@ -2037,14 +2037,17 @@ ActiveRecord::Schema.define(version: 2020_01_14_204949) do create_table "import_failures", force: :cascade do |t| t.integer "relation_index" - t.bigint "project_id", null: false + t.bigint "project_id" t.datetime_with_timezone "created_at", null: false t.string "relation_key", limit: 64 t.string "exception_class", limit: 128 t.string "correlation_id_value", limit: 128 t.string "exception_message", limit: 255 + t.integer "retry_count" + t.integer "group_id" t.index ["correlation_id_value"], name: "index_import_failures_on_correlation_id_value" - t.index ["project_id"], name: "index_import_failures_on_project_id" + t.index ["group_id"], name: "index_import_failures_on_group_id_not_null", where: "(group_id IS NOT NULL)" + t.index ["project_id"], name: "index_import_failures_on_project_id_not_null", where: "(project_id IS NOT NULL)" end create_table "index_statuses", id: :serial, force: :cascade do |t| @@ -4645,6 +4648,7 @@ ActiveRecord::Schema.define(version: 2020_01_14_204949) do add_foreign_key "identities", "saml_providers", name: "fk_aade90f0fc", on_delete: :cascade add_foreign_key "import_export_uploads", "namespaces", column: "group_id", name: "fk_83319d9721", on_delete: :cascade add_foreign_key "import_export_uploads", "projects", on_delete: :cascade + add_foreign_key "import_failures", "namespaces", column: "group_id", name: "fk_24b824da43", on_delete: :cascade add_foreign_key "index_statuses", "projects", name: "fk_74b2492545", on_delete: :cascade add_foreign_key "insights", "namespaces", on_delete: :cascade add_foreign_key "insights", "projects", on_delete: :cascade -- cgit v1.2.3