diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-27 21:09:21 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-27 21:09:21 +0300 |
commit | e0fa0638a422c3e20d4423c9bb69d79afc9c7d3d (patch) | |
tree | 9abb3c0706576bbda895fe9539a55556930606e2 /db | |
parent | f8d15ca65390475e356b06dedc51e10ccd179f86 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'db')
11 files changed, 231 insertions, 6 deletions
diff --git a/db/migrate/20191001170300_create_ci_ref.rb b/db/migrate/20191001170300_create_ci_ref.rb new file mode 100644 index 00000000000..af25e67430b --- /dev/null +++ b/db/migrate/20191001170300_create_ci_ref.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class CreateCiRef < ActiveRecord::Migration[5.2] + DOWNTIME = false + + def change + create_table :ci_refs do |t| + t.references :project, null: false, index: false, foreign_key: { on_delete: :cascade }, type: :integer + t.integer :lock_version, default: 0 + t.integer :last_updated_by_pipeline_id + t.boolean :tag, default: false, null: false + t.string :ref, null: false, limit: 255 + t.string :status, null: false, limit: 255 + t.foreign_key :ci_pipelines, column: :last_updated_by_pipeline_id, on_delete: :nullify + t.index [:project_id, :ref, :tag], unique: true + t.index [:last_updated_by_pipeline_id] + end + end +end diff --git a/db/migrate/20191111165017_add_fixed_pipeline_to_notification_settings.rb b/db/migrate/20191111165017_add_fixed_pipeline_to_notification_settings.rb new file mode 100644 index 00000000000..7a857807468 --- /dev/null +++ b/db/migrate/20191111165017_add_fixed_pipeline_to_notification_settings.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddFixedPipelineToNotificationSettings < ActiveRecord::Migration[5.2] + DOWNTIME = false + + def change + add_column :notification_settings, :fixed_pipeline, :boolean + end +end diff --git a/db/migrate/20200226162156_rename_closed_at_to_dismissed_at_in_vulnerabilities.rb b/db/migrate/20200226162156_rename_closed_at_to_dismissed_at_in_vulnerabilities.rb new file mode 100644 index 00000000000..ce7170cb335 --- /dev/null +++ b/db/migrate/20200226162156_rename_closed_at_to_dismissed_at_in_vulnerabilities.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class RenameClosedAtToDismissedAtInVulnerabilities < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + rename_column_concurrently :vulnerabilities, :closed_at, :dismissed_at + end + + def down + undo_rename_column_concurrently :vulnerabilities, :closed_at, :dismissed_at + end +end diff --git a/db/migrate/20200226162634_rename_closed_by_to_dismissed_by_in_vulnerabilities.rb b/db/migrate/20200226162634_rename_closed_by_to_dismissed_by_in_vulnerabilities.rb new file mode 100644 index 00000000000..04b1f0d7136 --- /dev/null +++ b/db/migrate/20200226162634_rename_closed_by_to_dismissed_by_in_vulnerabilities.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class RenameClosedByToDismissedByInVulnerabilities < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + rename_column_concurrently :vulnerabilities, :closed_by_id, :dismissed_by_id + end + + def down + undo_rename_column_concurrently :vulnerabilities, :closed_by_id, :dismissed_by_id + end +end diff --git a/db/post_migrate/20191115115043_migrate_epic_mentions_to_db.rb b/db/post_migrate/20191115115043_migrate_epic_mentions_to_db.rb index 97f2e568a7e..2cbf7a69159 100644 --- a/db/post_migrate/20191115115043_migrate_epic_mentions_to_db.rb +++ b/db/post_migrate/20191115115043_migrate_epic_mentions_to_db.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class MigrateEpicMentionsToDb < ActiveRecord::Migration[5.2] + include Gitlab::Database::MigrationHelpers + DOWNTIME = false disable_ddl_transaction! @@ -26,7 +28,7 @@ class MigrateEpicMentionsToDb < ActiveRecord::Migration[5.2] .where(QUERY_CONDITIONS) .each_batch(of: BATCH_SIZE) do |batch, index| range = batch.pluck(Arel.sql('MIN(epics.id)'), Arel.sql('MAX(epics.id)')).first - BackgroundMigrationWorker.perform_in(index * DELAY, MIGRATION, ['Epic', JOIN, QUERY_CONDITIONS, false, *range]) + migrate_in(index * DELAY, MIGRATION, ['Epic', JOIN, QUERY_CONDITIONS, false, *range]) end end diff --git a/db/post_migrate/20200214173000_cleanup_empty_epic_user_mentions.rb b/db/post_migrate/20200214173000_cleanup_empty_epic_user_mentions.rb new file mode 100644 index 00000000000..ef6486675e0 --- /dev/null +++ b/db/post_migrate/20200214173000_cleanup_empty_epic_user_mentions.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +class CleanupEmptyEpicUserMentions < ActiveRecord::Migration[5.2] + DOWNTIME = false + BATCH_SIZE = 10000 + + class EpicUserMention < ActiveRecord::Base + include EachBatch + + self.table_name = 'epic_user_mentions' + end + + def up + return unless Gitlab.ee? + + # cleanup epic user mentions with no actual mentions, + # re https://gitlab.com/gitlab-org/gitlab/-/merge_requests/24586#note_285982468 + EpicUserMention + .where(mentioned_users_ids: nil) + .where(mentioned_groups_ids: nil) + .where(mentioned_projects_ids: nil) + .each_batch(of: BATCH_SIZE) do |batch| + batch.delete_all + end + end + + def down + # no-op + end +end diff --git a/db/post_migrate/20200214174519_remigrate_epic_mentions_to_db.rb b/db/post_migrate/20200214174519_remigrate_epic_mentions_to_db.rb new file mode 100644 index 00000000000..68fe031be5d --- /dev/null +++ b/db/post_migrate/20200214174519_remigrate_epic_mentions_to_db.rb @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +class RemigrateEpicMentionsToDb < ActiveRecord::Migration[5.2] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + DELAY = 2.minutes.to_i + BATCH_SIZE = 10000 + MIGRATION = 'UserMentions::CreateResourceUserMention' + + JOIN = "LEFT JOIN epic_user_mentions on epics.id = epic_user_mentions.epic_id" + QUERY_CONDITIONS = "(description like '%@%' OR title like '%@%') AND epic_user_mentions.epic_id is null" + + class Epic < ActiveRecord::Base + include EachBatch + + self.table_name = 'epics' + end + + def up + return unless Gitlab.ee? + + Epic + .joins(JOIN) + .where(QUERY_CONDITIONS) + .each_batch(of: BATCH_SIZE) do |batch, index| + range = batch.pluck(Arel.sql('MIN(epics.id)'), Arel.sql('MAX(epics.id)')).first + migrate_in(index * DELAY, MIGRATION, ['Epic', JOIN, QUERY_CONDITIONS, false, *range]) + end + end + + def down + # no-op + end +end diff --git a/db/post_migrate/20200214174607_remigrate_epic_notes_mentions_to_db.rb b/db/post_migrate/20200214174607_remigrate_epic_notes_mentions_to_db.rb new file mode 100644 index 00000000000..cb442233229 --- /dev/null +++ b/db/post_migrate/20200214174607_remigrate_epic_notes_mentions_to_db.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: true + +class RemigrateEpicNotesMentionsToDb < ActiveRecord::Migration[5.2] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + DELAY = 2.minutes.to_i + BATCH_SIZE = 10000 + MIGRATION = 'UserMentions::CreateResourceUserMention' + + INDEX_NAME = 'epic_mentions_temp_index' + INDEX_CONDITION = "note LIKE '%@%'::text AND notes.noteable_type = 'Epic'" + QUERY_CONDITIONS = "#{INDEX_CONDITION} AND epic_user_mentions.epic_id IS NULL" + JOIN = 'INNER JOIN epics ON epics.id = notes.noteable_id LEFT JOIN epic_user_mentions ON notes.id = epic_user_mentions.note_id' + + class Note < ActiveRecord::Base + include EachBatch + + self.table_name = 'notes' + end + + def up + return unless Gitlab.ee? + + # create temporary index for notes with mentions, may take well over 1h + add_concurrent_index(:notes, :id, where: INDEX_CONDITION, name: INDEX_NAME) + + Note + .joins(JOIN) + .where(QUERY_CONDITIONS) + .each_batch(of: BATCH_SIZE) do |batch, index| + range = batch.pluck(Arel.sql('MIN(notes.id)'), Arel.sql('MAX(notes.id)')).first + migrate_in(index * DELAY, MIGRATION, ['Epic', JOIN, QUERY_CONDITIONS, true, *range]) + end + end + + def down + # no-op + # temporary index is to be dropped in a different migration in an upcoming release: + # https://gitlab.com/gitlab-org/gitlab/issues/196842 + end +end diff --git a/db/post_migrate/20200226162239_cleanup_closed_at_rename_in_vulnerabilities.rb b/db/post_migrate/20200226162239_cleanup_closed_at_rename_in_vulnerabilities.rb new file mode 100644 index 00000000000..eb7df0b8d22 --- /dev/null +++ b/db/post_migrate/20200226162239_cleanup_closed_at_rename_in_vulnerabilities.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class CleanupClosedAtRenameInVulnerabilities < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + cleanup_concurrent_column_rename :vulnerabilities, :closed_at, :dismissed_at + end + + def down + undo_cleanup_concurrent_column_rename :vulnerabilities, :closed_at, :dismissed_at + end +end diff --git a/db/post_migrate/20200226162723_cleanup_closed_by_rename_in_vulnerabilities.rb b/db/post_migrate/20200226162723_cleanup_closed_by_rename_in_vulnerabilities.rb new file mode 100644 index 00000000000..4aa3568db14 --- /dev/null +++ b/db/post_migrate/20200226162723_cleanup_closed_by_rename_in_vulnerabilities.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class CleanupClosedByRenameInVulnerabilities < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + cleanup_concurrent_column_rename :vulnerabilities, :closed_by_id, :dismissed_by_id + end + + def down + undo_cleanup_concurrent_column_rename :vulnerabilities, :closed_by_id, :dismissed_by_id + end +end diff --git a/db/schema.rb b/db/schema.rb index f49b1af4ea9..623fdcd0542 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_02_24_163804) do +ActiveRecord::Schema.define(version: 2020_02_26_162723) do # These are extensions that must be enabled in order to support this database enable_extension "pg_trgm" @@ -878,6 +878,17 @@ ActiveRecord::Schema.define(version: 2020_02_24_163804) do t.index ["pipeline_id"], name: "index_ci_pipelines_config_on_pipeline_id" end + create_table "ci_refs", force: :cascade do |t| + t.integer "project_id", null: false + t.integer "lock_version", default: 0 + t.integer "last_updated_by_pipeline_id" + t.boolean "tag", default: false, null: false + t.string "ref", limit: 255, null: false + t.string "status", limit: 255, null: false + t.index ["last_updated_by_pipeline_id"], name: "index_ci_refs_on_last_updated_by_pipeline_id" + t.index ["project_id", "ref", "tag"], name: "index_ci_refs_on_project_id_and_ref_and_tag", unique: true + end + create_table "ci_resource_groups", force: :cascade do |t| t.datetime_with_timezone "created_at", null: false t.datetime_with_timezone "updated_at", null: false @@ -2845,6 +2856,7 @@ ActiveRecord::Schema.define(version: 2020_02_24_163804) do t.boolean "issue_due" t.boolean "new_epic" t.string "notification_email" + t.boolean "fixed_pipeline" t.boolean "new_release" t.index ["source_id", "source_type"], name: "index_notification_settings_on_source_id_and_source_type" t.index ["user_id", "source_id", "source_type"], name: "index_notifications_on_user_id_and_source_id_and_source_type", unique: true @@ -4356,8 +4368,6 @@ ActiveRecord::Schema.define(version: 2020_02_24_163804) do t.text "description_html" t.bigint "start_date_sourcing_milestone_id" t.bigint "due_date_sourcing_milestone_id" - t.bigint "closed_by_id" - t.datetime_with_timezone "closed_at" t.integer "state", limit: 2, default: 1, null: false t.integer "severity", limit: 2, null: false t.boolean "severity_overridden", default: false @@ -4369,9 +4379,11 @@ ActiveRecord::Schema.define(version: 2020_02_24_163804) do t.integer "cached_markdown_version" t.bigint "confirmed_by_id" t.datetime_with_timezone "confirmed_at" + t.datetime_with_timezone "dismissed_at" + t.bigint "dismissed_by_id" t.index ["author_id"], name: "index_vulnerabilities_on_author_id" - t.index ["closed_by_id"], name: "index_vulnerabilities_on_closed_by_id" t.index ["confirmed_by_id"], name: "index_vulnerabilities_on_confirmed_by_id" + t.index ["dismissed_by_id"], name: "index_vulnerabilities_on_dismissed_by_id" t.index ["due_date_sourcing_milestone_id"], name: "index_vulnerabilities_on_due_date_sourcing_milestone_id" t.index ["epic_id"], name: "index_vulnerabilities_on_epic_id" t.index ["last_edited_by_id"], name: "index_vulnerabilities_on_last_edited_by_id" @@ -4650,6 +4662,8 @@ ActiveRecord::Schema.define(version: 2020_02_24_163804) do add_foreign_key "ci_pipelines", "merge_requests", name: "fk_a23be95014", on_delete: :cascade add_foreign_key "ci_pipelines", "projects", name: "fk_86635dbd80", on_delete: :cascade add_foreign_key "ci_pipelines_config", "ci_pipelines", column: "pipeline_id", on_delete: :cascade + add_foreign_key "ci_refs", "ci_pipelines", column: "last_updated_by_pipeline_id", on_delete: :nullify + add_foreign_key "ci_refs", "projects", on_delete: :cascade add_foreign_key "ci_resource_groups", "projects", name: "fk_774722d144", on_delete: :cascade add_foreign_key "ci_resources", "ci_builds", column: "build_id", name: "fk_e169a8e3d5", on_delete: :nullify add_foreign_key "ci_resources", "ci_resource_groups", column: "resource_group_id", on_delete: :cascade @@ -5026,8 +5040,8 @@ ActiveRecord::Schema.define(version: 2020_02_24_163804) do add_foreign_key "vulnerabilities", "milestones", name: "fk_131d289c65", on_delete: :nullify add_foreign_key "vulnerabilities", "projects", name: "fk_efb96ab1e2", on_delete: :cascade add_foreign_key "vulnerabilities", "users", column: "author_id", name: "fk_b1de915a15", on_delete: :nullify - add_foreign_key "vulnerabilities", "users", column: "closed_by_id", name: "fk_cf5c60acbf", on_delete: :nullify add_foreign_key "vulnerabilities", "users", column: "confirmed_by_id", name: "fk_959d40ad0a", on_delete: :nullify + add_foreign_key "vulnerabilities", "users", column: "dismissed_by_id", name: "fk_725465b774", on_delete: :nullify add_foreign_key "vulnerabilities", "users", column: "last_edited_by_id", name: "fk_1302949740", on_delete: :nullify add_foreign_key "vulnerabilities", "users", column: "resolved_by_id", name: "fk_76bc5f5455", on_delete: :nullify add_foreign_key "vulnerabilities", "users", column: "updated_by_id", name: "fk_7ac31eacb9", on_delete: :nullify |