diff options
Diffstat (limited to 'db')
10 files changed, 229 insertions, 2 deletions
diff --git a/db/migrate/20140414131055_change_state_to_allow_empty_merge_request_diffs.rb b/db/migrate/20140414131055_change_state_to_allow_empty_merge_request_diffs.rb index 148b46f8830..1f9ae3f0080 100644 --- a/db/migrate/20140414131055_change_state_to_allow_empty_merge_request_diffs.rb +++ b/db/migrate/20140414131055_change_state_to_allow_empty_merge_request_diffs.rb @@ -1,4 +1,3 @@ -# rubocop:disable all class ChangeStateToAllowEmptyMergeRequestDiffs < ActiveRecord::Migration[4.2] def up change_column :merge_request_diffs, :state, :string, null: true, diff --git a/db/migrate/20190325105715_add_fields_to_user_preferences.rb b/db/migrate/20190325105715_add_fields_to_user_preferences.rb new file mode 100644 index 00000000000..9ea3b4f9cd8 --- /dev/null +++ b/db/migrate/20190325105715_add_fields_to_user_preferences.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +# See http://doc.gitlab.com/ce/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class AddFieldsToUserPreferences < ActiveRecord::Migration[5.0] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + DOWNTIME = false + + def up + add_column(:user_preferences, :timezone, :string) + add_column(:user_preferences, :time_display_relative, :boolean) + add_column(:user_preferences, :time_format_in_24h, :boolean) + end + + def down + remove_column(:user_preferences, :timezone) + remove_column(:user_preferences, :time_display_relative) + remove_column(:user_preferences, :time_format_in_24h) + end +end diff --git a/db/migrate/20190415030217_add_variable_type_to_ci_variables.rb b/db/migrate/20190415030217_add_variable_type_to_ci_variables.rb new file mode 100644 index 00000000000..433f510299a --- /dev/null +++ b/db/migrate/20190415030217_add_variable_type_to_ci_variables.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddVariableTypeToCiVariables < ActiveRecord::Migration[5.0] + include Gitlab::Database::MigrationHelpers + disable_ddl_transaction! + + DOWNTIME = false + ENV_VAR_VARIABLE_TYPE = 1 + + def up + add_column_with_default(:ci_variables, :variable_type, :smallint, default: ENV_VAR_VARIABLE_TYPE) + end + + def down + remove_column(:ci_variables, :variable_type) + end +end diff --git a/db/migrate/20190416213556_add_variable_type_to_ci_group_variables.rb b/db/migrate/20190416213556_add_variable_type_to_ci_group_variables.rb new file mode 100644 index 00000000000..dce73caeb5e --- /dev/null +++ b/db/migrate/20190416213556_add_variable_type_to_ci_group_variables.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddVariableTypeToCiGroupVariables < ActiveRecord::Migration[5.0] + include Gitlab::Database::MigrationHelpers + disable_ddl_transaction! + + DOWNTIME = false + ENV_VAR_VARIABLE_TYPE = 1 + + def up + add_column_with_default(:ci_group_variables, :variable_type, :smallint, default: ENV_VAR_VARIABLE_TYPE) + end + + def down + remove_column(:ci_group_variables, :variable_type) + end +end diff --git a/db/migrate/20190416213615_add_variable_type_to_ci_pipeline_variables.rb b/db/migrate/20190416213615_add_variable_type_to_ci_pipeline_variables.rb new file mode 100644 index 00000000000..1010d9bd29e --- /dev/null +++ b/db/migrate/20190416213615_add_variable_type_to_ci_pipeline_variables.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddVariableTypeToCiPipelineVariables < ActiveRecord::Migration[5.0] + include Gitlab::Database::MigrationHelpers + disable_ddl_transaction! + + DOWNTIME = false + ENV_VAR_VARIABLE_TYPE = 1 + + def up + add_column_with_default(:ci_pipeline_variables, :variable_type, :smallint, default: ENV_VAR_VARIABLE_TYPE) + end + + def down + remove_column(:ci_pipeline_variables, :variable_type) + end +end diff --git a/db/migrate/20190416213631_add_variable_type_to_ci_pipeline_schedule_variables.rb b/db/migrate/20190416213631_add_variable_type_to_ci_pipeline_schedule_variables.rb new file mode 100644 index 00000000000..3079b2afd9c --- /dev/null +++ b/db/migrate/20190416213631_add_variable_type_to_ci_pipeline_schedule_variables.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddVariableTypeToCiPipelineScheduleVariables < ActiveRecord::Migration[5.0] + include Gitlab::Database::MigrationHelpers + disable_ddl_transaction! + + DOWNTIME = false + ENV_VAR_VARIABLE_TYPE = 1 + + def up + add_column_with_default(:ci_pipeline_schedule_variables, :variable_type, :smallint, default: ENV_VAR_VARIABLE_TYPE) + end + + def down + remove_column(:ci_pipeline_schedule_variables, :variable_type) + end +end diff --git a/db/migrate/20190418182545_create_merge_request_trains_table.rb b/db/migrate/20190418182545_create_merge_request_trains_table.rb new file mode 100644 index 00000000000..ac927c9c6b9 --- /dev/null +++ b/db/migrate/20190418182545_create_merge_request_trains_table.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class CreateMergeRequestTrainsTable < ActiveRecord::Migration[5.1] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def change + create_table :merge_trains, id: :bigserial do |t| + t.references :merge_request, foreign_key: { on_delete: :cascade }, type: :integer, index: false, null: false + t.references :user, foreign_key: { on_delete: :cascade }, type: :integer, null: false + t.references :pipeline, foreign_key: { to_table: :ci_pipelines, on_delete: :nullify }, type: :integer + t.timestamps_with_timezone null: false + + t.index [:merge_request_id], unique: true + end + end +end diff --git a/db/migrate/20190506135337_add_temporary_indexes_to_state_id.rb b/db/migrate/20190506135337_add_temporary_indexes_to_state_id.rb new file mode 100644 index 00000000000..8e9838e1afb --- /dev/null +++ b/db/migrate/20190506135337_add_temporary_indexes_to_state_id.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +# This migration adds temporary indexes to state_id column of issues +# and merge_requests tables. It will be used only to peform the scheduling +# for populating state_id in a post migrate and will be removed after it. +# Check: ScheduleSyncIssuablesStateIdWhereNil. + +class AddTemporaryIndexesToStateId < ActiveRecord::Migration[5.1] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + %w(issues merge_requests).each do |table| + add_concurrent_index( + table, + 'id', + name: index_name_for(table), + where: "state_id IS NULL" + ) + end + end + + def down + remove_concurrent_index_by_name(:issues, index_name_for("issues")) + remove_concurrent_index_by_name(:merge_requests, index_name_for("merge_requests")) + end + + def index_name_for(table) + "idx_on_#{table}_where_state_id_is_null" + end +end diff --git a/db/post_migrate/20190506135400_schedule_sync_issuables_state_id_where_nil.rb b/db/post_migrate/20190506135400_schedule_sync_issuables_state_id_where_nil.rb new file mode 100644 index 00000000000..4c31b5968ff --- /dev/null +++ b/db/post_migrate/20190506135400_schedule_sync_issuables_state_id_where_nil.rb @@ -0,0 +1,63 @@ +# frozen_string_literal: true + +class ScheduleSyncIssuablesStateIdWhereNil < ActiveRecord::Migration[5.1] + # Issues and MergeRequests imported by GitHub are being created with + # state_id = null, this fixes them. + # + # Part of a bigger plan: https://gitlab.com/gitlab-org/gitlab-ce/issues/51789 + + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + # 2019-05-02 gitlab.com issuable numbers + # issues with state_id nil: ~40000 + # merge requests with state_id nil: ~200000 + # + # Using 5000 as batch size and 120 seconds interval will create: + # ~8 jobs for issues - taking ~16 minutes + # ~40 jobs for merge requests - taking ~1.34 hours + # + BATCH_SIZE = 5000 + DELAY_INTERVAL = 120.seconds.to_i + ISSUES_MIGRATION = 'SyncIssuesStateId'.freeze + MERGE_REQUESTS_MIGRATION = 'SyncMergeRequestsStateId'.freeze + + disable_ddl_transaction! + + class Issue < ActiveRecord::Base + include EachBatch + + self.table_name = 'issues' + end + + class MergeRequest < ActiveRecord::Base + include EachBatch + + self.table_name = 'merge_requests' + end + + def up + queue_background_migration_jobs_by_range_at_intervals( + Issue.where(state_id: nil), + ISSUES_MIGRATION, + DELAY_INTERVAL, + batch_size: BATCH_SIZE + ) + + queue_background_migration_jobs_by_range_at_intervals( + MergeRequest.where(state_id: nil), + MERGE_REQUESTS_MIGRATION, + DELAY_INTERVAL, + batch_size: BATCH_SIZE + ) + + # Remove temporary indexes added on "AddTemporaryIndexesToStateId" + remove_concurrent_index_by_name(:issues, "idx_on_issues_where_state_id_is_null") + remove_concurrent_index_by_name(:merge_requests, "idx_on_merge_requests_where_state_id_is_null") + end + + def down + # No op + end +end diff --git a/db/schema.rb b/db/schema.rb index 501cb96d479..159e7e03cf4 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: 20190426180107) do +ActiveRecord::Schema.define(version: 20190506135400) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -419,6 +419,7 @@ ActiveRecord::Schema.define(version: 20190426180107) do t.datetime_with_timezone "created_at", null: false t.datetime_with_timezone "updated_at", null: false t.boolean "masked", default: false, null: false + t.integer "variable_type", limit: 2, default: 1, null: false t.index ["group_id", "key"], name: "index_ci_group_variables_on_group_id_and_key", unique: true, using: :btree end @@ -458,6 +459,7 @@ ActiveRecord::Schema.define(version: 20190426180107) do t.integer "pipeline_schedule_id", null: false t.datetime_with_timezone "created_at" t.datetime_with_timezone "updated_at" + t.integer "variable_type", limit: 2, default: 1, null: false t.index ["pipeline_schedule_id", "key"], name: "index_ci_pipeline_schedule_variables_on_schedule_id_and_key", unique: true, using: :btree end @@ -484,6 +486,7 @@ ActiveRecord::Schema.define(version: 20190426180107) do t.string "encrypted_value_salt" t.string "encrypted_value_iv" t.integer "pipeline_id", null: false + t.integer "variable_type", limit: 2, default: 1, null: false t.index ["pipeline_id", "key"], name: "index_ci_pipeline_variables_on_pipeline_id_and_key", unique: true, using: :btree end @@ -618,6 +621,7 @@ ActiveRecord::Schema.define(version: 20190426180107) do t.boolean "protected", default: false, null: false t.string "environment_scope", default: "*", null: false t.boolean "masked", default: false, null: false + t.integer "variable_type", limit: 2, default: 1, null: false t.index ["project_id", "key", "environment_scope"], name: "index_ci_variables_on_project_id_and_key_and_environment_scope", unique: true, using: :btree end @@ -1370,6 +1374,17 @@ ActiveRecord::Schema.define(version: 20190426180107) do t.index ["merge_request_id"], name: "index_merge_requests_closing_issues_on_merge_request_id", using: :btree end + create_table "merge_trains", force: :cascade do |t| + t.integer "merge_request_id", null: false + t.integer "user_id", null: false + t.integer "pipeline_id" + t.datetime_with_timezone "created_at", null: false + t.datetime_with_timezone "updated_at", null: false + t.index ["merge_request_id"], name: "index_merge_trains_on_merge_request_id", unique: true, using: :btree + t.index ["pipeline_id"], name: "index_merge_trains_on_pipeline_id", using: :btree + t.index ["user_id"], name: "index_merge_trains_on_user_id", using: :btree + end + create_table "milestones", id: :serial, force: :cascade do |t| t.string "title", null: false t.integer "project_id" @@ -2240,6 +2255,9 @@ ActiveRecord::Schema.define(version: 20190426180107) do t.integer "first_day_of_week" t.string "issues_sort" t.string "merge_requests_sort" + t.string "timezone" + t.boolean "time_display_relative" + t.boolean "time_format_in_24h" t.index ["user_id"], name: "index_user_preferences_on_user_id", unique: true, using: :btree end @@ -2525,6 +2543,9 @@ ActiveRecord::Schema.define(version: 20190426180107) do add_foreign_key "merge_requests", "users", column: "updated_by_id", name: "fk_641731faff", on_delete: :nullify add_foreign_key "merge_requests_closing_issues", "issues", on_delete: :cascade add_foreign_key "merge_requests_closing_issues", "merge_requests", on_delete: :cascade + add_foreign_key "merge_trains", "ci_pipelines", column: "pipeline_id", on_delete: :nullify + add_foreign_key "merge_trains", "merge_requests", on_delete: :cascade + add_foreign_key "merge_trains", "users", on_delete: :cascade add_foreign_key "milestones", "namespaces", column: "group_id", name: "fk_95650a40d4", on_delete: :cascade add_foreign_key "milestones", "projects", name: "fk_9bd0a0c791", on_delete: :cascade add_foreign_key "note_diff_files", "notes", column: "diff_note_id", on_delete: :cascade |