diff options
author | Luke "Jared" Bennett <lbennett@gitlab.com> | 2017-09-18 10:54:12 +0100 |
---|---|---|
committer | Luke "Jared" Bennett <lbennett@gitlab.com> | 2017-09-18 10:54:12 +0100 |
commit | 9ca7c94f66e8f8a5e9d8bd5169df41db176aa8d8 (patch) | |
tree | c263bfa5d1e33020f24aa37053a8ca97358f9e0d /db | |
parent | 1b52d8a4832f0231fa3f6c5cb28d065bbea9ba94 (diff) | |
parent | 0a60758b498c868f121bb8a203a3e3da35639628 (diff) | |
download | gitlab-ce-9ca7c94f66e8f8a5e9d8bd5169df41db176aa8d8.tar.gz |
Merge remote-tracking branch 'origin/master' into 18608-lock-issues
Diffstat (limited to 'db')
5 files changed, 129 insertions, 3 deletions
diff --git a/db/migrate/20170913131410_environments_project_id_not_null.rb b/db/migrate/20170913131410_environments_project_id_not_null.rb new file mode 100644 index 00000000000..d5404f8ede9 --- /dev/null +++ b/db/migrate/20170913131410_environments_project_id_not_null.rb @@ -0,0 +1,16 @@ +# See http://doc.gitlab.com/ce/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class EnvironmentsProjectIdNotNull < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def up + change_column_null :environments, :project_id, false + end + + def down + change_column_null :environments, :project_id, true + end +end diff --git a/db/migrate/20170914135630_add_index_for_recent_push_events.rb b/db/migrate/20170914135630_add_index_for_recent_push_events.rb new file mode 100644 index 00000000000..99f593b0465 --- /dev/null +++ b/db/migrate/20170914135630_add_index_for_recent_push_events.rb @@ -0,0 +1,40 @@ +# See http://doc.gitlab.com/ce/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class AddIndexForRecentPushEvents < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_concurrent_index_if_not_present( + :merge_requests, + [:source_project_id, :source_branch] + ) + + remove_concurrent_index_if_present(:merge_requests, :source_project_id) + end + + def down + add_concurrent_index_if_not_present(:merge_requests, :source_project_id) + + remove_concurrent_index_if_present( + :merge_requests, + [:source_project_id, :source_branch] + ) + end + + def add_concurrent_index_if_not_present(table, columns) + return if index_exists?(table, columns) + + add_concurrent_index(table, columns) + end + + def remove_concurrent_index_if_present(table, columns) + return unless index_exists?(table, columns) + + remove_concurrent_index(table, columns) + end +end diff --git a/db/post_migrate/20170907170235_delete_conflicting_redirect_routes.rb b/db/post_migrate/20170907170235_delete_conflicting_redirect_routes.rb new file mode 100644 index 00000000000..3e84b295be4 --- /dev/null +++ b/db/post_migrate/20170907170235_delete_conflicting_redirect_routes.rb @@ -0,0 +1,37 @@ +# See http://doc.gitlab.com/ce/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class DeleteConflictingRedirectRoutes < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + MIGRATION = 'DeleteConflictingRedirectRoutesRange'.freeze + BATCH_SIZE = 200 # At 200, I expect under 20s per batch, which is under our query timeout of 60s. + DELAY_INTERVAL = 12.seconds + + disable_ddl_transaction! + + class Route < ActiveRecord::Base + include EachBatch + + self.table_name = 'routes' + end + + def up + say opening_message + + queue_background_migration_jobs_by_range_at_intervals(Route, MIGRATION, DELAY_INTERVAL, batch_size: BATCH_SIZE) + end + + def down + # nothing + end + + def opening_message + <<~MSG + Clean up redirect routes that conflict with regular routes. + See initial bug fix: + https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/13357 + MSG + end +end diff --git a/db/post_migrate/20170913180600_fix_projects_without_project_feature.rb b/db/post_migrate/20170913180600_fix_projects_without_project_feature.rb new file mode 100644 index 00000000000..bfa9ad80c7d --- /dev/null +++ b/db/post_migrate/20170913180600_fix_projects_without_project_feature.rb @@ -0,0 +1,33 @@ +class FixProjectsWithoutProjectFeature < ActiveRecord::Migration + DOWNTIME = false + + def up + # Deletes corrupted project features + sql = "DELETE FROM project_features WHERE project_id IS NULL" + execute(sql) + + # Creates missing project features with private visibility + sql = + %Q{ + INSERT INTO project_features(project_id, repository_access_level, issues_access_level, merge_requests_access_level, wiki_access_level, + builds_access_level, snippets_access_level, created_at, updated_at) + SELECT projects.id as project_id, + 10 as repository_access_level, + 10 as issues_access_level, + 10 as merge_requests_access_level, + 10 as wiki_access_level, + 10 as builds_access_level , + 10 as snippets_access_level, + projects.created_at, + projects.updated_at + FROM projects + LEFT OUTER JOIN project_features ON project_features.project_id = projects.id + WHERE (project_features.id IS NULL) + } + + execute(sql) + end + + def down + end +end diff --git a/db/schema.rb b/db/schema.rb index ceaa7a7deea..779b85f7a66 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: 20170905112933) do +ActiveRecord::Schema.define(version: 20170914135630) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -520,7 +520,7 @@ ActiveRecord::Schema.define(version: 20170905112933) do add_index "emails", ["user_id"], name: "index_emails_on_user_id", using: :btree create_table "environments", force: :cascade do |t| - t.integer "project_id" + t.integer "project_id", null: false t.string "name", null: false t.datetime "created_at" t.datetime "updated_at" @@ -894,7 +894,7 @@ ActiveRecord::Schema.define(version: 20170905112933) do add_index "merge_requests", ["head_pipeline_id"], name: "index_merge_requests_on_head_pipeline_id", using: :btree add_index "merge_requests", ["milestone_id"], name: "index_merge_requests_on_milestone_id", using: :btree add_index "merge_requests", ["source_branch"], name: "index_merge_requests_on_source_branch", using: :btree - add_index "merge_requests", ["source_project_id"], name: "index_merge_requests_on_source_project_id", using: :btree + add_index "merge_requests", ["source_project_id", "source_branch"], name: "index_merge_requests_on_source_project_id_and_source_branch", using: :btree add_index "merge_requests", ["target_branch"], name: "index_merge_requests_on_target_branch", using: :btree add_index "merge_requests", ["target_project_id", "iid"], name: "index_merge_requests_on_target_project_id_and_iid", unique: true, using: :btree add_index "merge_requests", ["title"], name: "index_merge_requests_on_title", using: :btree |