Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
Diffstat (limited to 'db')
-rw-r--r--db/fixtures/development/20_nested_groups.rb28
-rw-r--r--db/migrate/20180628124813_alter_web_hook_logs_indexes.rb28
-rw-r--r--db/post_migrate/20180619121030_enqueue_delete_diff_files_workers.rb70
-rw-r--r--db/post_migrate/20180629191052_add_partial_index_to_projects_for_last_repository_check_at.rb18
-rw-r--r--db/schema.rb4
5 files changed, 51 insertions, 97 deletions
diff --git a/db/fixtures/development/20_nested_groups.rb b/db/fixtures/development/20_nested_groups.rb
index 2bc78e120a5..3d95e243f8a 100644
--- a/db/fixtures/development/20_nested_groups.rb
+++ b/db/fixtures/development/20_nested_groups.rb
@@ -1,30 +1,5 @@
require './spec/support/sidekiq'
-def create_group_with_parents(user, full_path)
- parent_path = nil
- group = nil
-
- until full_path.blank?
- path, _, full_path = full_path.partition('/')
-
- if parent_path
- parent = Group.find_by_full_path(parent_path)
-
- parent_path += '/'
- parent_path += path
-
- group = Groups::CreateService.new(user, path: path, parent_id: parent.id).execute
- else
- parent_path = path
-
- group = Group.find_by_full_path(parent_path) ||
- Groups::CreateService.new(user, path: path).execute
- end
- end
-
- group
-end
-
Sidekiq::Testing.inline! do
Gitlab::Seeder.quiet do
flag = 'SEED_NESTED_GROUPS'
@@ -48,7 +23,8 @@ Sidekiq::Testing.inline! do
full_path = url.sub('https://android.googlesource.com/', '')
full_path = full_path.sub(/\.git\z/, '')
full_path, _, project_path = full_path.rpartition('/')
- group = Group.find_by_full_path(full_path) || create_group_with_parents(user, full_path)
+ group = Group.find_by_full_path(full_path) ||
+ Groups::NestedCreateService.new(user, group_path: full_path).execute
params = {
import_url: url,
diff --git a/db/migrate/20180628124813_alter_web_hook_logs_indexes.rb b/db/migrate/20180628124813_alter_web_hook_logs_indexes.rb
new file mode 100644
index 00000000000..1878e76811d
--- /dev/null
+++ b/db/migrate/20180628124813_alter_web_hook_logs_indexes.rb
@@ -0,0 +1,28 @@
+# 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 AlterWebHookLogsIndexes < ActiveRecord::Migration
+ include Gitlab::Database::MigrationHelpers
+
+ # Set this constant to true if this migration requires downtime.
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ # "created_at" comes first so the Sidekiq worker pruning old webhook logs can
+ # use a composite index index.
+ #
+ # We leave the old standalone index on "web_hook_id" in place so future code
+ # that doesn't care about "created_at" can still use that index.
+ COLUMNS_TO_INDEX = %i[created_at web_hook_id]
+
+ def up
+ add_concurrent_index(:web_hook_logs, COLUMNS_TO_INDEX)
+ end
+
+ def down
+ remove_concurrent_index(:web_hook_logs, COLUMNS_TO_INDEX)
+ end
+end
diff --git a/db/post_migrate/20180619121030_enqueue_delete_diff_files_workers.rb b/db/post_migrate/20180619121030_enqueue_delete_diff_files_workers.rb
deleted file mode 100644
index 5fb3d545624..00000000000
--- a/db/post_migrate/20180619121030_enqueue_delete_diff_files_workers.rb
+++ /dev/null
@@ -1,70 +0,0 @@
-class EnqueueDeleteDiffFilesWorkers < ActiveRecord::Migration
- include Gitlab::Database::MigrationHelpers
-
- class MergeRequestDiff < ActiveRecord::Base
- self.table_name = 'merge_request_diffs'
-
- belongs_to :merge_request
-
- include EachBatch
- end
-
- DOWNTIME = false
- BATCH_SIZE = 1000
- MIGRATION = 'DeleteDiffFiles'
- DELAY_INTERVAL = 8.minutes
- TMP_INDEX = 'tmp_partial_diff_id_with_files_index'.freeze
-
- disable_ddl_transaction!
-
- def up
- # We add temporary index, to make iteration over batches more performant.
- # Conditional here is to avoid the need of doing that in a separate
- # migration file to make this operation idempotent.
- #
- unless index_exists_by_name?(:merge_request_diffs, TMP_INDEX)
- add_concurrent_index(:merge_request_diffs, :id, where: "(state NOT IN ('without_files', 'empty'))", name: TMP_INDEX)
- end
-
-
- diffs_with_files = MergeRequestDiff.where.not(state: ['without_files', 'empty'])
-
- # explain (analyze, buffers) example for the iteration:
- #
- # Index Only Scan using tmp_index_20013 on merge_request_diffs (cost=0.43..1630.19 rows=60567 width=4) (actual time=0.047..9.572 rows=56976 loops=1)
- # Index Cond: ((id >= 764586) AND (id < 835298))
- # Heap Fetches: 8
- # Buffers: shared hit=18188
- # Planning time: 0.752 ms
- # Execution time: 12.430 ms
- #
- diffs_with_files.each_batch(of: BATCH_SIZE) do |relation, outer_index|
- ids = relation.pluck(:id)
-
- ids.each_with_index do |diff_id, inner_index|
- # This will give some space between batches of workers.
- interval = DELAY_INTERVAL * outer_index + inner_index.minutes
-
- # A single `merge_request_diff` can be associated with way too many
- # `merge_request_diff_files`. It's better to avoid batching these and
- # schedule one at a time.
- #
- # Considering roughly 6M jobs, this should take ~30 days to process all
- # of them.
- #
- BackgroundMigrationWorker.perform_in(interval, MIGRATION, [diff_id])
- end
- end
-
- # We remove temporary index, because it is not required during standard
- # operations and runtime.
- #
- remove_concurrent_index_by_name(:merge_request_diffs, TMP_INDEX)
- end
-
- def down
- if index_exists_by_name?(:merge_request_diffs, TMP_INDEX)
- remove_concurrent_index_by_name(:merge_request_diffs, TMP_INDEX)
- end
- end
-end
diff --git a/db/post_migrate/20180629191052_add_partial_index_to_projects_for_last_repository_check_at.rb b/db/post_migrate/20180629191052_add_partial_index_to_projects_for_last_repository_check_at.rb
new file mode 100644
index 00000000000..a701d3678db
--- /dev/null
+++ b/db/post_migrate/20180629191052_add_partial_index_to_projects_for_last_repository_check_at.rb
@@ -0,0 +1,18 @@
+class AddPartialIndexToProjectsForLastRepositoryCheckAt < ActiveRecord::Migration
+ include Gitlab::Database::MigrationHelpers
+
+ # Set this constant to true if this migration requires downtime.
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ INDEX_NAME = "index_projects_on_last_repository_check_at"
+
+ def up
+ add_concurrent_index(:projects, :last_repository_check_at, where: "last_repository_check_at IS NOT NULL", name: INDEX_NAME)
+ end
+
+ def down
+ remove_concurrent_index(:projects, :last_repository_check_at, where: "last_repository_check_at IS NOT NULL", name: INDEX_NAME)
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 504d57b8aa2..9a4e3fe5555 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20180626125654) do
+ActiveRecord::Schema.define(version: 20180629191052) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -1646,6 +1646,7 @@ ActiveRecord::Schema.define(version: 20180626125654) do
add_index "projects", ["description"], name: "index_projects_on_description_trigram", using: :gin, opclasses: {"description"=>"gin_trgm_ops"}
add_index "projects", ["id"], name: "index_projects_on_id_partial_for_visibility", unique: true, where: "(visibility_level = ANY (ARRAY[10, 20]))", using: :btree
add_index "projects", ["last_activity_at"], name: "index_projects_on_last_activity_at", using: :btree
+ add_index "projects", ["last_repository_check_at"], name: "index_projects_on_last_repository_check_at", where: "(last_repository_check_at IS NOT NULL)", using: :btree
add_index "projects", ["last_repository_check_failed"], name: "index_projects_on_last_repository_check_failed", using: :btree
add_index "projects", ["last_repository_updated_at"], name: "index_projects_on_last_repository_updated_at", using: :btree
add_index "projects", ["name"], name: "index_projects_on_name_trigram", using: :gin, opclasses: {"name"=>"gin_trgm_ops"}
@@ -2146,6 +2147,7 @@ ActiveRecord::Schema.define(version: 20180626125654) do
t.datetime "updated_at", null: false
end
+ add_index "web_hook_logs", ["created_at", "web_hook_id"], name: "index_web_hook_logs_on_created_at_and_web_hook_id", using: :btree
add_index "web_hook_logs", ["web_hook_id"], name: "index_web_hook_logs_on_web_hook_id", using: :btree
create_table "web_hooks", force: :cascade do |t|