diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-03 03:09:41 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-03 03:09:41 +0300 |
commit | a020b8c048bf621f5193c38833bbdea4c0e080af (patch) | |
tree | 41003e2fd63ddc6cdc935294284cdad1b2072150 /db | |
parent | 36e4abb3dd21deb8b8938ddaccec3bb59d6cbb7e (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'db')
9 files changed, 158 insertions, 3 deletions
diff --git a/db/migrate/20210105025900_add_default_projects_has_external_wiki.rb b/db/migrate/20210105025900_add_default_projects_has_external_wiki.rb new file mode 100644 index 00000000000..cd74208d58c --- /dev/null +++ b/db/migrate/20210105025900_add_default_projects_has_external_wiki.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddDefaultProjectsHasExternalWiki < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def up + with_lock_retries do + change_column_default(:projects, :has_external_wiki, from: nil, to: false) + end + end + + def down + with_lock_retries do + change_column_default(:projects, :has_external_wiki, from: false, to: nil) + end + end +end diff --git a/db/migrate/20210129225244_add_index_to_oncall_shfts_on_starts_at_and_ends_at.rb b/db/migrate/20210129225244_add_index_to_oncall_shfts_on_starts_at_and_ends_at.rb new file mode 100644 index 00000000000..8285aceb24a --- /dev/null +++ b/db/migrate/20210129225244_add_index_to_oncall_shfts_on_starts_at_and_ends_at.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +class AddIndexToOncallShftsOnStartsAtAndEndsAt < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + NEW_NAME = 'index_oncall_shifts_on_rotation_id_and_starts_at_and_ends_at' + OLD_NAME = 'index_incident_management_oncall_shifts_on_rotation_id' + + def up + add_concurrent_index :incident_management_oncall_shifts, %i[rotation_id starts_at ends_at], name: NEW_NAME + + remove_concurrent_index_by_name :incident_management_oncall_shifts, OLD_NAME + end + + def down + add_concurrent_index :incident_management_oncall_shifts, :rotation_id, name: OLD_NAME + + remove_concurrent_index_by_name :incident_management_oncall_shifts, NEW_NAME + end +end diff --git a/db/post_migrate/20210105025903_add_not_null_constraint_to_projects_has_external_wiki.rb b/db/post_migrate/20210105025903_add_not_null_constraint_to_projects_has_external_wiki.rb new file mode 100644 index 00000000000..0560258592f --- /dev/null +++ b/db/post_migrate/20210105025903_add_not_null_constraint_to_projects_has_external_wiki.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class AddNotNullConstraintToProjectsHasExternalWiki < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_not_null_constraint :projects, :has_external_wiki, validate: false + end + + def down + remove_not_null_constraint :projects, :has_external_wiki + end +end diff --git a/db/post_migrate/20210105030124_cleanup_projects_with_null_has_external_wiki.rb b/db/post_migrate/20210105030124_cleanup_projects_with_null_has_external_wiki.rb new file mode 100644 index 00000000000..7995ac6a393 --- /dev/null +++ b/db/post_migrate/20210105030124_cleanup_projects_with_null_has_external_wiki.rb @@ -0,0 +1,89 @@ +# frozen_string_literal: true + +class CleanupProjectsWithNullHasExternalWiki < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + TMP_INDEX_NAME = 'tmp_index_projects_on_id_where_has_external_wiki_is_true_null'.freeze + BATCH_SIZE = 100 + + disable_ddl_transaction! + + class Service < ActiveRecord::Base + include EachBatch + belongs_to :project + + self.table_name = 'services' + self.inheritance_column = :_type_disabled + end + + class Project < ActiveRecord::Base + include EachBatch + + self.table_name = 'projects' + end + + def up + update_projects_with_active_external_wikis + update_projects_without_active_external_wikis + end + + def down + # no-op : can't go back to `NULL` without first dropping the `NOT NULL` constraint + end + + private + + def update_projects_with_active_external_wikis + # 11 projects are scoped in this query on GitLab.com. + scope = Service.where(active: true, type: 'ExternalWikiService').where.not(project_id: nil) + + scope.each_batch(of: BATCH_SIZE) do |relation| + scope_with_projects = relation + .joins(:project) + .select('project_id') + .merge(Project.where(has_external_wiki: [false, nil]).where(pending_delete: false).where(archived: false)) + + execute(<<~SQL) + WITH project_ids_to_update (id) AS ( + #{scope_with_projects.to_sql} + ) + UPDATE projects SET has_external_wiki = true WHERE id IN (SELECT id FROM project_ids_to_update) + SQL + end + end + + def update_projects_without_active_external_wikis + # Add a temporary index to speed up the scoping of projects. + index_where = <<~SQL + ( + "projects"."has_external_wiki" = TRUE + OR "projects"."has_external_wiki" IS NULL + ) + AND "projects"."pending_delete" = FALSE + AND "projects"."archived" = FALSE + SQL + + add_concurrent_index(:projects, :id, where: index_where, name: TMP_INDEX_NAME) + + services_sub_query = Service + .select('1') + .where('services.project_id = projects.id') + .where(type: 'ExternalWikiService') + .where(active: true) + + # 322 projects are scoped in this query on GitLab.com. + Project.where(index_where).each_batch(of: BATCH_SIZE) do |relation| + relation_with_exists_query = relation.where('NOT EXISTS (?)', services_sub_query) + execute(<<~SQL) + WITH project_ids_to_update (id) AS ( + #{relation_with_exists_query.select(:id).to_sql} + ) + UPDATE projects SET has_external_wiki = false WHERE id IN (SELECT id FROM project_ids_to_update) + SQL + end + + # Drop the temporary index. + remove_concurrent_index_by_name(:projects, TMP_INDEX_NAME) + end +end diff --git a/db/schema_migrations/20210105025900 b/db/schema_migrations/20210105025900 new file mode 100644 index 00000000000..200ee5b7ff2 --- /dev/null +++ b/db/schema_migrations/20210105025900 @@ -0,0 +1 @@ +047dd77352eda8134e55047e2d3fab07bbcd6eb41600cefb9b581d32e441fb68
\ No newline at end of file diff --git a/db/schema_migrations/20210105025903 b/db/schema_migrations/20210105025903 new file mode 100644 index 00000000000..6680ba6bbac --- /dev/null +++ b/db/schema_migrations/20210105025903 @@ -0,0 +1 @@ +339d828635107f77116ffd856abcb8f8f64985cabb82c0c34ab76056f5756d2e
\ No newline at end of file diff --git a/db/schema_migrations/20210105030124 b/db/schema_migrations/20210105030124 new file mode 100644 index 00000000000..6fa3d1b1474 --- /dev/null +++ b/db/schema_migrations/20210105030124 @@ -0,0 +1 @@ +30f3cbc0f96848f72a188616503eb80d38c33769c8bebf86a5922b374750d066
\ No newline at end of file diff --git a/db/schema_migrations/20210129225244 b/db/schema_migrations/20210129225244 new file mode 100644 index 00000000000..1b05096b07f --- /dev/null +++ b/db/schema_migrations/20210129225244 @@ -0,0 +1 @@ +6cb54c71a9835ec1b3cf801a19c2cd385d224e0438c7924b6a29d298ecebe8a7
\ No newline at end of file diff --git a/db/structure.sql b/db/structure.sql index ce7b51d067c..ddf6105bcd6 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -16129,7 +16129,7 @@ CREATE TABLE projects ( repository_storage character varying DEFAULT 'default'::character varying NOT NULL, repository_read_only boolean, request_access_enabled boolean DEFAULT true NOT NULL, - has_external_wiki boolean, + has_external_wiki boolean DEFAULT false, ci_config_path character varying, lfs_enabled boolean, description_html text, @@ -19662,6 +19662,9 @@ ALTER TABLE ONLY chat_teams ALTER TABLE vulnerability_scanners ADD CONSTRAINT check_37608c9db5 CHECK ((char_length(vendor) <= 255)) NOT VALID; +ALTER TABLE projects + ADD CONSTRAINT check_421d399b70 CHECK ((has_external_wiki IS NOT NULL)) NOT VALID; + ALTER TABLE group_import_states ADD CONSTRAINT check_cda75c7c3f CHECK ((user_id IS NOT NULL)) NOT VALID; @@ -22127,8 +22130,6 @@ CREATE INDEX index_incident_management_oncall_schedules_on_project_id ON inciden CREATE INDEX index_incident_management_oncall_shifts_on_participant_id ON incident_management_oncall_shifts USING btree (participant_id); -CREATE INDEX index_incident_management_oncall_shifts_on_rotation_id ON incident_management_oncall_shifts USING btree (rotation_id); - CREATE UNIQUE INDEX index_index_statuses_on_project_id ON index_statuses USING btree (project_id); CREATE INDEX index_insights_on_namespace_id ON insights USING btree (namespace_id); @@ -22575,6 +22576,8 @@ CREATE INDEX index_onboarding_progresses_for_verify_track ON onboarding_progress CREATE UNIQUE INDEX index_onboarding_progresses_on_namespace_id ON onboarding_progresses USING btree (namespace_id); +CREATE INDEX index_oncall_shifts_on_rotation_id_and_starts_at_and_ends_at ON incident_management_oncall_shifts USING btree (rotation_id, starts_at, ends_at); + CREATE INDEX index_open_project_tracker_data_on_service_id ON open_project_tracker_data USING btree (service_id); CREATE INDEX index_operations_feature_flags_issues_on_issue_id ON operations_feature_flags_issues USING btree (issue_id); |