diff options
Diffstat (limited to 'db')
7 files changed, 156 insertions, 1 deletions
diff --git a/db/fixtures/development/25_api_personal_access_token.rb b/db/fixtures/development/25_api_personal_access_token.rb new file mode 100644 index 00000000000..a2e6c674c1f --- /dev/null +++ b/db/fixtures/development/25_api_personal_access_token.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +require './spec/support/sidekiq' + +# Create an api access token for root user with the value: ypCa3Dzb23o5nvsixwPA +Gitlab::Seeder.quiet do + PersonalAccessToken.create!( + user_id: User.find_by(username: 'root').id, + name: "seeded-api-token", + scopes: ["api"], + token_digest: "/O0jfLERYT/L5gG8nfByQxqTj43TeLlRzOtJGTzRsbQ=" + ) + + print '.' +end diff --git a/db/migrate/20190222051615_add_indexes_for_merge_request_diffs_query.rb b/db/migrate/20190222051615_add_indexes_for_merge_request_diffs_query.rb new file mode 100644 index 00000000000..0048268ca6f --- /dev/null +++ b/db/migrate/20190222051615_add_indexes_for_merge_request_diffs_query.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +class AddIndexesForMergeRequestDiffsQuery < ActiveRecord::Migration[5.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + INDEX_SPECS = [ + [ + :merge_request_metrics, + :latest_closed_at, + { where: 'latest_closed_at IS NOT NULL' } + ], + [ + :merge_request_metrics, + [:merge_request_id, :merged_at], + { where: 'merged_at IS NOT NULL' } + ], + [ + :merge_request_diffs, + [:merge_request_id, :id], + { + name: 'index_merge_request_diffs_on_merge_request_id_and_id_partial', + where: 'NOT stored_externally OR stored_externally IS NULL' + } + ] + ].freeze + + disable_ddl_transaction! + + def up + INDEX_SPECS.each do |spec| + add_concurrent_index(*spec) + end + end + + def down + INDEX_SPECS.reverse.each do |spec| + remove_concurrent_index(*spec) + end + end +end diff --git a/db/migrate/20190228192410_add_multi_line_attributes_to_suggestion.rb b/db/migrate/20190228192410_add_multi_line_attributes_to_suggestion.rb new file mode 100644 index 00000000000..856dfc89fa3 --- /dev/null +++ b/db/migrate/20190228192410_add_multi_line_attributes_to_suggestion.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddMultiLineAttributesToSuggestion < ActiveRecord::Migration[5.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_column_with_default :suggestions, :lines_above, :integer, default: 0, allow_null: false + add_column_with_default :suggestions, :lines_below, :integer, default: 0, allow_null: false + add_column_with_default :suggestions, :outdated, :boolean, default: false, allow_null: false + end + + def down + remove_columns :suggestions, :outdated, :lines_above, :lines_below + end +end diff --git a/db/migrate/20190315191339_create_merge_request_assignees_table.rb b/db/migrate/20190315191339_create_merge_request_assignees_table.rb new file mode 100644 index 00000000000..6fc4463f281 --- /dev/null +++ b/db/migrate/20190315191339_create_merge_request_assignees_table.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +class CreateMergeRequestAssigneesTable < ActiveRecord::Migration[5.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + INDEX_NAME = 'index_merge_request_assignees_on_merge_request_id_and_user_id' + + def up + create_table :merge_request_assignees do |t| + t.references :user, foreign_key: { on_delete: :cascade }, index: true, null: false + t.references :merge_request, foreign_key: { on_delete: :cascade }, null: false + end + + add_index :merge_request_assignees, [:merge_request_id, :user_id], unique: true, name: INDEX_NAME + end + + def down + drop_table :merge_request_assignees + end +end diff --git a/db/migrate/20190325165127_add_managed_to_cluster.rb b/db/migrate/20190325165127_add_managed_to_cluster.rb new file mode 100644 index 00000000000..e960df9d502 --- /dev/null +++ b/db/migrate/20190325165127_add_managed_to_cluster.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddManagedToCluster < ActiveRecord::Migration[5.0] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + DOWNTIME = false + + def up + add_column_with_default(:clusters, :managed, :boolean, default: true) + end + + def down + remove_column(:clusters, :managed) + end +end diff --git a/db/post_migrate/20190322132835_schedule_populate_merge_request_assignees_table.rb b/db/post_migrate/20190322132835_schedule_populate_merge_request_assignees_table.rb new file mode 100644 index 00000000000..1ecb38e1a86 --- /dev/null +++ b/db/post_migrate/20190322132835_schedule_populate_merge_request_assignees_table.rb @@ -0,0 +1,23 @@ +# 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 SchedulePopulateMergeRequestAssigneesTable < ActiveRecord::Migration[5.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + BATCH_SIZE = 10_000 + MIGRATION = 'PopulateMergeRequestAssigneesTable' + DELAY_INTERVAL = 8.minutes.to_i + + disable_ddl_transaction! + + def up + say 'Scheduling `PopulateMergeRequestAssigneesTable` jobs' + # We currently have ~4_500_000 merge request records on GitLab.com. + # This means it'll schedule ~450 jobs (10k MRs each) with a 8 minutes gap, + # so this should take ~60 hours for all background migrations to complete. + queue_background_migration_jobs_by_range_at_intervals(MergeRequest, MIGRATION, DELAY_INTERVAL, batch_size: BATCH_SIZE) + end +end diff --git a/db/schema.rb b/db/schema.rb index eee38651b33..e7dc80c8e72 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: 20190312071108) do +ActiveRecord::Schema.define(version: 20190325165127) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -670,6 +670,7 @@ ActiveRecord::Schema.define(version: 20190312071108) do t.string "environment_scope", default: "*", null: false t.integer "cluster_type", limit: 2, default: 3, null: false t.string "domain" + t.boolean "managed", default: true, null: false t.index ["enabled"], name: "index_clusters_on_enabled", using: :btree t.index ["user_id"], name: "index_clusters_on_user_id", using: :btree end @@ -1201,6 +1202,14 @@ ActiveRecord::Schema.define(version: 20190312071108) do t.index ["user_id"], name: "index_members_on_user_id", using: :btree end + create_table "merge_request_assignees", force: :cascade do |t| + t.integer "user_id", null: false + t.integer "merge_request_id", null: false + t.index ["merge_request_id", "user_id"], name: "index_merge_request_assignees_on_merge_request_id_and_user_id", unique: true, using: :btree + t.index ["merge_request_id"], name: "index_merge_request_assignees_on_merge_request_id", using: :btree + t.index ["user_id"], name: "index_merge_request_assignees_on_user_id", using: :btree + end + create_table "merge_request_diff_commits", id: false, force: :cascade do |t| t.datetime_with_timezone "authored_date" t.datetime_with_timezone "committed_date" @@ -1248,6 +1257,7 @@ ActiveRecord::Schema.define(version: 20190312071108) do t.integer "external_diff_store" t.boolean "stored_externally" t.index ["merge_request_id", "id"], name: "index_merge_request_diffs_on_merge_request_id_and_id", using: :btree + t.index ["merge_request_id", "id"], name: "index_merge_request_diffs_on_merge_request_id_and_id_partial", where: "((NOT stored_externally) OR (stored_externally IS NULL))", using: :btree end create_table "merge_request_metrics", force: :cascade do |t| @@ -1263,7 +1273,9 @@ ActiveRecord::Schema.define(version: 20190312071108) do t.integer "latest_closed_by_id" t.datetime_with_timezone "latest_closed_at" t.index ["first_deployed_to_production_at"], name: "index_merge_request_metrics_on_first_deployed_to_production_at", using: :btree + t.index ["latest_closed_at"], name: "index_merge_request_metrics_on_latest_closed_at", where: "(latest_closed_at IS NOT NULL)", using: :btree t.index ["latest_closed_by_id"], name: "index_merge_request_metrics_on_latest_closed_by_id", using: :btree + t.index ["merge_request_id", "merged_at"], name: "index_merge_request_metrics_on_merge_request_id_and_merged_at", where: "(merged_at IS NOT NULL)", using: :btree t.index ["merge_request_id"], name: "index_merge_request_metrics", using: :btree t.index ["merged_by_id"], name: "index_merge_request_metrics_on_merged_by_id", using: :btree t.index ["pipeline_id"], name: "index_merge_request_metrics_on_pipeline_id", using: :btree @@ -2032,6 +2044,9 @@ ActiveRecord::Schema.define(version: 20190312071108) do t.string "commit_id" t.text "from_content", null: false t.text "to_content", null: false + t.integer "lines_above", default: 0, null: false + t.integer "lines_below", default: 0, null: false + t.boolean "outdated", default: false, null: false t.index ["note_id", "relative_order"], name: "index_suggestions_on_note_id_and_relative_order", unique: true, using: :btree end @@ -2455,6 +2470,8 @@ ActiveRecord::Schema.define(version: 20190312071108) do add_foreign_key "lists", "boards", name: "fk_0d3f677137", on_delete: :cascade add_foreign_key "lists", "labels", name: "fk_7a5553d60f", on_delete: :cascade add_foreign_key "members", "users", name: "fk_2e88fb7ce9", on_delete: :cascade + add_foreign_key "merge_request_assignees", "merge_requests", on_delete: :cascade + add_foreign_key "merge_request_assignees", "users", on_delete: :cascade add_foreign_key "merge_request_diff_commits", "merge_request_diffs", on_delete: :cascade add_foreign_key "merge_request_diff_files", "merge_request_diffs", on_delete: :cascade add_foreign_key "merge_request_diffs", "merge_requests", name: "fk_8483f3258f", on_delete: :cascade |