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
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-04-08 09:08:32 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-04-08 09:08:32 +0300
commitf9e55cc3c9ec3258051c60562b011bef22075f2a (patch)
tree67742b507188dcc8e9892f78477bb56bb4f1fa3b
parent0c8e6bebbb74c8b3f9acf1b685851621e386296c (diff)
Add latest changes from gitlab-org/gitlab@master
-rw-r--r--app/helpers/application_settings_helper.rb1
-rw-r--r--app/models/application_setting_implementation.rb1
-rw-r--r--app/views/admin/application_settings/_repository_check.html.haml7
-rw-r--r--app/workers/concerns/git_garbage_collect_methods.rb6
-rw-r--r--config/initializers/load_balancing.rb15
-rw-r--r--db/post_migrate/20220325155953_steal_background_job_for_fixing_conflicting_project_names_and_paths.rb11
-rw-r--r--db/post_migrate/20220325160153_create_unique_index_on_projects_name_and_namespace_id.rb15
-rw-r--r--db/schema_migrations/202203251559531
-rw-r--r--db/schema_migrations/202203251601531
-rw-r--r--db/structure.sql2
-rw-r--r--doc/administration/housekeeping.md2
-rw-r--r--doc/api/settings.md2
-rw-r--r--doc/development/code_review.md1
-rw-r--r--lib/api/entities/application_setting.rb3
-rw-r--r--lib/api/settings.rb1
-rw-r--r--lib/gitlab/database.rb17
-rw-r--r--lib/gitlab/database/load_balancing/setup.rb6
-rw-r--r--lib/gitlab/database/migration_helpers/restrict_gitlab_schema.rb14
-rw-r--r--lib/tasks/gitlab/db/validate_config.rake6
-rw-r--r--locale/gitlab.pot6
-rw-r--r--spec/factories/application_settings.rb1
-rw-r--r--spec/lib/api/entities/application_setting_spec.rb31
-rw-r--r--spec/lib/gitlab/background_migration/fix_duplicate_project_name_and_path_spec.rb2
-rw-r--r--spec/lib/gitlab/database/migration_helpers/restrict_gitlab_schema_spec.rb16
-rw-r--r--spec/lib/gitlab/database_spec.rb41
-rw-r--r--spec/tasks/gitlab/db/validate_config_rake_spec.rb13
26 files changed, 180 insertions, 42 deletions
diff --git a/app/helpers/application_settings_helper.rb b/app/helpers/application_settings_helper.rb
index a9c13b2fdeb..a9721766dc8 100644
--- a/app/helpers/application_settings_helper.rb
+++ b/app/helpers/application_settings_helper.rb
@@ -266,7 +266,6 @@ module ApplicationSettingsHelper
:help_page_text,
:hide_third_party_offers,
:home_page_url,
- :housekeeping_bitmaps_enabled,
:housekeeping_enabled,
:housekeeping_full_repack_period,
:housekeeping_gc_period,
diff --git a/app/models/application_setting_implementation.rb b/app/models/application_setting_implementation.rb
index 8914ecf033d..194356acc51 100644
--- a/app/models/application_setting_implementation.rb
+++ b/app/models/application_setting_implementation.rb
@@ -95,7 +95,6 @@ module ApplicationSettingImplementation
help_page_text: nil,
help_page_documentation_base_url: nil,
hide_third_party_offers: false,
- housekeeping_bitmaps_enabled: true,
housekeeping_enabled: true,
housekeeping_full_repack_period: 50,
housekeeping_gc_period: 200,
diff --git a/app/views/admin/application_settings/_repository_check.html.haml b/app/views/admin/application_settings/_repository_check.html.haml
index ce81f81c125..dd186058bd7 100644
--- a/app/views/admin/application_settings/_repository_check.html.haml
+++ b/app/views/admin/application_settings/_repository_check.html.haml
@@ -28,13 +28,6 @@
.form-text.text-muted
= _("Leaving this setting enabled is recommended.")
= link_to s_('Learn more.'), help_page_path('administration/housekeeping.md', anchor: 'housekeeping-options'), target: '_blank', rel: 'noopener noreferrer'
- .form-check
- = f.check_box :housekeeping_bitmaps_enabled, class: 'form-check-input'
- = f.label :housekeeping_bitmaps_enabled, class: 'form-check-label' do
- = _("Enable Git pack file bitmap creation")
- .form-text.text-muted
- = _("Improves Git cloning performance.")
- = link_to s_('Learn more.'), help_page_path('administration/housekeeping.md', anchor: 'housekeeping-options'), target: '_blank', rel: 'noopener noreferrer'
.form-group
= f.label :housekeeping_incremental_repack_period, 'Incremental repack period', class: 'label-bold'
= f.number_field :housekeeping_incremental_repack_period, class: 'form-control gl-form-input'
diff --git a/app/workers/concerns/git_garbage_collect_methods.rb b/app/workers/concerns/git_garbage_collect_methods.rb
index 13b7e7b5b1f..308ffacfc6b 100644
--- a/app/workers/concerns/git_garbage_collect_methods.rb
+++ b/app/workers/concerns/git_garbage_collect_methods.rb
@@ -121,8 +121,12 @@ module GitGarbageCollectMethods
end.new(repository)
end
+ # The option to enable/disable bitmaps has been removed in https://gitlab.com/gitlab-org/gitlab/-/issues/353777
+ # Now the options is always enabled
+ # This method and all the deprecated RPCs are going to be removed in
+ # https://gitlab.com/gitlab-org/gitlab/-/issues/353779
def bitmaps_enabled?
- Gitlab::CurrentSettings.housekeeping_bitmaps_enabled
+ true
end
def flush_ref_caches(resource)
diff --git a/config/initializers/load_balancing.rb b/config/initializers/load_balancing.rb
index df75178740b..290481f7296 100644
--- a/config/initializers/load_balancing.rb
+++ b/config/initializers/load_balancing.rb
@@ -2,6 +2,15 @@
Gitlab::Application.configure do |config|
config.middleware.use(Gitlab::Database::LoadBalancing::RackMiddleware)
+
+ # We need re-rerun the setup when code reloads in development
+ config.reloader.to_prepare do
+ if Rails.env.development? || Rails.env.test?
+ Gitlab::Database::LoadBalancing.base_models.each do |model|
+ Gitlab::Database::LoadBalancing::Setup.new(model).setup
+ end
+ end
+ end
end
Gitlab::Database::LoadBalancing.base_models.each do |model|
@@ -14,6 +23,12 @@ Gitlab::Database::LoadBalancing.base_models.each do |model|
# information.
Gitlab::Database::LoadBalancing::Setup.new(model).setup
+ Rails.application.reloader.to_prepare do
+ if Rails.env.development?
+ Gitlab::Database::LoadBalancing::Setup.new(model).setup
+ end
+ end
+
# Database queries may be run before we fork, so we must set up the load
# balancer as early as possible. When we do fork, we need to make sure all the
# hosts are disconnected.
diff --git a/db/post_migrate/20220325155953_steal_background_job_for_fixing_conflicting_project_names_and_paths.rb b/db/post_migrate/20220325155953_steal_background_job_for_fixing_conflicting_project_names_and_paths.rb
new file mode 100644
index 00000000000..4c4c29e2b7c
--- /dev/null
+++ b/db/post_migrate/20220325155953_steal_background_job_for_fixing_conflicting_project_names_and_paths.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+class StealBackgroundJobForFixingConflictingProjectNamesAndPaths < Gitlab::Database::Migration[1.0]
+ def up
+ Gitlab::BackgroundMigration.steal('FixDuplicateProjectNameAndPath')
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20220325160153_create_unique_index_on_projects_name_and_namespace_id.rb b/db/post_migrate/20220325160153_create_unique_index_on_projects_name_and_namespace_id.rb
new file mode 100644
index 00000000000..d1cefa76cec
--- /dev/null
+++ b/db/post_migrate/20220325160153_create_unique_index_on_projects_name_and_namespace_id.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class CreateUniqueIndexOnProjectsNameAndNamespaceId < Gitlab::Database::Migration[1.0]
+ INDEX_NAME = 'unique_projects_on_name_namespace_id'
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :projects, [:name, :namespace_id], unique: true, name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index_by_name :projects, INDEX_NAME
+ end
+end
diff --git a/db/schema_migrations/20220325155953 b/db/schema_migrations/20220325155953
new file mode 100644
index 00000000000..408f1230a38
--- /dev/null
+++ b/db/schema_migrations/20220325155953
@@ -0,0 +1 @@
+bbcd27340d9d684b6134292772dad6f523ce6e1af9853ce12284a0c138d6b7bd \ No newline at end of file
diff --git a/db/schema_migrations/20220325160153 b/db/schema_migrations/20220325160153
new file mode 100644
index 00000000000..f1894bb1cab
--- /dev/null
+++ b/db/schema_migrations/20220325160153
@@ -0,0 +1 @@
+7f33fc1c6b47e3ff732caa62d15f0d725c03d993eacb24bc603992fc2579e63c \ No newline at end of file
diff --git a/db/structure.sql b/db/structure.sql
index 25c71663c6c..fd17f1898e7 100644
--- a/db/structure.sql
+++ b/db/structure.sql
@@ -29685,6 +29685,8 @@ CREATE UNIQUE INDEX uniq_pkgs_debian_project_distributions_project_id_and_suite
CREATE UNIQUE INDEX unique_merge_request_metrics_by_merge_request_id ON merge_request_metrics USING btree (merge_request_id);
+CREATE UNIQUE INDEX unique_projects_on_name_namespace_id ON projects USING btree (name, namespace_id);
+
CREATE INDEX user_follow_users_followee_id_idx ON user_follow_users USING btree (followee_id);
CREATE INDEX users_forbidden_state_idx ON users USING btree (id) WHERE ((confirmed_at IS NOT NULL) AND ((state)::text <> ALL (ARRAY['blocked'::text, 'banned'::text, 'ldap_blocked'::text])));
diff --git a/doc/administration/housekeeping.md b/doc/administration/housekeeping.md
index 4de48aa3f14..71b8439f70a 100644
--- a/doc/administration/housekeeping.md
+++ b/doc/administration/housekeeping.md
@@ -40,8 +40,6 @@ The following housekeeping options are available:
- **Enable automatic repository housekeeping**: Regularly run `git repack` and `git gc`. If you
keep this setting disabled for a long time, Git repository access on your GitLab server becomes
slower and your repositories use more disk space.
-- **Enable Git pack file bitmap creation**: Create pack file bitmaps which accelerates `git clone`
- performance. Makes housekeeping take a little longer.
- **Incremental repack period**: Number of Git pushes after which an incremental `git repack` is
run.
- **Full repack period**: Number of Git pushes after which a full `git repack` is run.
diff --git a/doc/api/settings.md b/doc/api/settings.md
index 39de0d6b125..02c3f8b0d30 100644
--- a/doc/api/settings.md
+++ b/doc/api/settings.md
@@ -342,7 +342,7 @@ listed in the descriptions of the relevant settings.
| `help_text` **(PREMIUM)** | string | no | GitLab server administrator information. |
| `hide_third_party_offers` | boolean | no | Do not display offers from third parties in GitLab. |
| `home_page_url` | string | no | Redirect to this URL when not logged in. |
-| `housekeeping_bitmaps_enabled` | boolean | required by: `housekeeping_enabled` | Enable Git pack file bitmap creation. |
+| `housekeeping_bitmaps_enabled` | boolean | no | Git pack file bitmap creation is always enabled and cannot be changed via API and UI. This API field is deprecated and always returns `true`. |
| `housekeeping_enabled` | boolean | no | (**If enabled, requires:** `housekeeping_bitmaps_enabled`, `housekeeping_full_repack_period`, `housekeeping_gc_period`, and `housekeeping_incremental_repack_period`) Enable or disable Git housekeeping. |
| `housekeeping_full_repack_period` | integer | required by: `housekeeping_enabled` | Number of Git pushes after which an incremental `git repack` is run. |
| `housekeeping_gc_period` | integer | required by: `housekeeping_enabled` | Number of Git pushes after which `git gc` is run. |
diff --git a/doc/development/code_review.md b/doc/development/code_review.md
index bdfe8fefd30..99c01039f76 100644
--- a/doc/development/code_review.md
+++ b/doc/development/code_review.md
@@ -136,6 +136,7 @@ with [domain expertise](#domain-experts).
1. If your merge request includes Product Intelligence (telemetry or analytics) changes, it should be reviewed and approved by a [Product Intelligence engineer](https://gitlab.com/gitlab-org/growth/product-intelligence/engineers).
1. If your merge request includes an addition of, or changes to a [Feature spec](testing_guide/testing_levels.md#frontend-feature-tests), it must be **approved by a [Quality maintainer](https://about.gitlab.com/handbook/engineering/projects/#gitlab_maintainers_qa) or [Quality reviewer](https://about.gitlab.com/handbook/engineering/projects/#gitlab_reviewers_qa)**.
1. If your merge request introduces a new service to GitLab (Puma, Sidekiq, Gitaly are examples), it must be **approved by a [product manager](https://about.gitlab.com/company/team/)**. See the [process for adding a service component to GitLab](adding_service_component.md) for details.
+1. If your merge request includes changes related to authentication or authorization, it must be **approved by a [Manage:Authentication and Authorization team member](https://about.gitlab.com/company/team/)**. Check the [code review section on the group page](https://about.gitlab.com/handbook/engineering/development/dev/manage/authentication-and-authorization/#additional-considerations) for more details. Patterns for files known to require review from the team are listed in the in the `Authentication and Authorization` section of the [`CODEOWNERS`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/.gitlab/CODEOWNERS) file, and the team will be listed in the approvers section of all merge requests that modify these files.
- (*1*): Specs other than JavaScript specs are considered backend code.
- (*2*): We encourage you to seek guidance from a database maintainer if your merge
diff --git a/lib/api/entities/application_setting.rb b/lib/api/entities/application_setting.rb
index 465c5f4112b..db51d4380d0 100644
--- a/lib/api/entities/application_setting.rb
+++ b/lib/api/entities/application_setting.rb
@@ -40,6 +40,9 @@ module API
expose :password_authentication_enabled_for_web, as: :signin_enabled
expose :allow_local_requests_from_web_hooks_and_services, as: :allow_local_requests_from_hooks_and_services
expose :asset_proxy_allowlist, as: :asset_proxy_whitelist
+
+ # This field is deprecated and always returns true
+ expose(:housekeeping_bitmaps_enabled) { |_settings, _options| true }
end
end
end
diff --git a/lib/api/settings.rb b/lib/api/settings.rb
index 913ea2b34f6..774ab472f2d 100644
--- a/lib/api/settings.rb
+++ b/lib/api/settings.rb
@@ -83,7 +83,6 @@ module API
optional :home_page_url, type: String, desc: 'We will redirect non-logged in users to this page'
optional :housekeeping_enabled, type: Boolean, desc: 'Enable automatic repository housekeeping (git repack, git gc)'
given housekeeping_enabled: ->(val) { val } do
- requires :housekeeping_bitmaps_enabled, type: Boolean, desc: "Creating pack file bitmaps makes housekeeping take a little longer but bitmaps should accelerate 'git clone' performance."
requires :housekeeping_full_repack_period, type: Integer, desc: "Number of Git pushes after which a full 'git repack' is run."
requires :housekeeping_gc_period, type: Integer, desc: "Number of Git pushes after which 'git gc' is run."
requires :housekeeping_incremental_repack_period, type: Integer, desc: "Number of Git pushes after which an incremental 'git repack' is run."
diff --git a/lib/gitlab/database.rb b/lib/gitlab/database.rb
index 96962d015d2..b4edc363a59 100644
--- a/lib/gitlab/database.rb
+++ b/lib/gitlab/database.rb
@@ -236,13 +236,16 @@ module Gitlab
# This does not look at literal connection names, but rather compares
# models that are holders for a given db_config_name
def self.gitlab_schemas_for_connection(connection)
- connection_name = self.db_config_name(connection)
- primary_model = self.database_base_models.fetch(connection_name)
-
- self.schemas_to_base_models
- .select { |_, models| models.include?(primary_model) }
- .keys
- .map!(&:to_sym)
+ db_name = self.db_config_name(connection)
+ primary_model = self.database_base_models.fetch(db_name.to_sym)
+
+ self.schemas_to_base_models.select do |_, child_models|
+ child_models.any? do |child_model|
+ child_model == primary_model || \
+ # The model might indicate a child connection, ensure that this is enclosed in a `db_config`
+ self.database_base_models[self.db_config_share_with(child_model.connection_db_config)] == primary_model
+ end
+ end.keys.map!(&:to_sym)
end
def self.db_config_for_connection(connection)
diff --git a/lib/gitlab/database/load_balancing/setup.rb b/lib/gitlab/database/load_balancing/setup.rb
index b9723825337..eceea1d8d9c 100644
--- a/lib/gitlab/database/load_balancing/setup.rb
+++ b/lib/gitlab/database/load_balancing/setup.rb
@@ -17,6 +17,12 @@ module Gitlab
configure_connection
setup_connection_proxy
setup_service_discovery
+
+ ::Gitlab::Database::LoadBalancing::Logger.debug(
+ event: :setup,
+ model: model.name,
+ start_service_discovery: @start_service_discovery
+ )
end
def configure_connection
diff --git a/lib/gitlab/database/migration_helpers/restrict_gitlab_schema.rb b/lib/gitlab/database/migration_helpers/restrict_gitlab_schema.rb
index b4e31565c60..5a25128f3a9 100644
--- a/lib/gitlab/database/migration_helpers/restrict_gitlab_schema.rb
+++ b/lib/gitlab/database/migration_helpers/restrict_gitlab_schema.rb
@@ -6,8 +6,6 @@ module Gitlab
module RestrictGitlabSchema
extend ActiveSupport::Concern
- MigrationSkippedError = Class.new(StandardError)
-
included do
class_attribute :allowed_gitlab_schemas
end
@@ -25,11 +23,8 @@ module Gitlab
def migrate(direction)
if unmatched_schemas.any?
- # TODO: Today skipping migration would raise an exception.
- # Ideally, skipped migration should be ignored (not loaded), or softly ignored.
- # Read more in: https://gitlab.com/gitlab-org/gitlab/-/issues/355014
- raise MigrationSkippedError, "Current migration is skipped since it modifies "\
- "'#{self.class.allowed_gitlab_schemas}' which is outside of '#{allowed_schemas_for_connection}'"
+ migration_skipped
+ return
end
Gitlab::Database::QueryAnalyzer.instance.within([validator_class]) do
@@ -41,6 +36,11 @@ module Gitlab
private
+ def migration_skipped
+ say "Current migration is skipped since it modifies "\
+ "'#{self.class.allowed_gitlab_schemas}' which is outside of '#{allowed_schemas_for_connection}'"
+ end
+
def validator_class
Gitlab::Database::QueryAnalyzers::RestrictAllowedSchemas
end
diff --git a/lib/tasks/gitlab/db/validate_config.rake b/lib/tasks/gitlab/db/validate_config.rake
index 5ea5cc364b7..165a1107ec0 100644
--- a/lib/tasks/gitlab/db/validate_config.rake
+++ b/lib/tasks/gitlab/db/validate_config.rake
@@ -85,9 +85,13 @@ namespace :gitlab do
warnings.unshift("Database config validation failure:")
# Warn (for now) by default in production environment
- if Gitlab::Utils.to_boolean(ENV['GITLAB_VALIDATE_DATABASE_CONFIG'], default: Gitlab.dev_or_test_env?)
+ if Gitlab::Utils.to_boolean(ENV['GITLAB_VALIDATE_DATABASE_CONFIG'], default: true)
+ warnings << "Use `export GITLAB_VALIDATE_DATABASE_CONFIG=0` to ignore this validation."
+
raise warnings.join("\n")
else
+ warnings << "Use `export GITLAB_VALIDATE_DATABASE_CONFIG=1` to enforce this validation."
+
warn warnings.join("\n")
end
end
diff --git a/locale/gitlab.pot b/locale/gitlab.pot
index a9b96892322..e5390231a6d 100644
--- a/locale/gitlab.pot
+++ b/locale/gitlab.pot
@@ -13798,9 +13798,6 @@ msgstr ""
msgid "Enable Auto DevOps"
msgstr ""
-msgid "Enable Git pack file bitmap creation"
-msgstr ""
-
msgid "Enable Gitpod"
msgstr ""
@@ -19148,9 +19145,6 @@ msgstr ""
msgid "Improve customer support with Service Desk"
msgstr ""
-msgid "Improves Git cloning performance."
-msgstr ""
-
msgid "In case of pull mirroring, your user will be the author of all events in the activity feed that are the result of an update, like new branches being created or new commits being pushed to existing branches."
msgstr ""
diff --git a/spec/factories/application_settings.rb b/spec/factories/application_settings.rb
index 8ac003d0a98..c28d3c20a86 100644
--- a/spec/factories/application_settings.rb
+++ b/spec/factories/application_settings.rb
@@ -4,5 +4,6 @@ FactoryBot.define do
factory :application_setting do
default_projects_limit { 42 }
import_sources { [] }
+ restricted_visibility_levels { [] }
end
end
diff --git a/spec/lib/api/entities/application_setting_spec.rb b/spec/lib/api/entities/application_setting_spec.rb
new file mode 100644
index 00000000000..5adb825672c
--- /dev/null
+++ b/spec/lib/api/entities/application_setting_spec.rb
@@ -0,0 +1,31 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe API::Entities::ApplicationSetting do
+ let_it_be(:application_setting, reload: true) { create(:application_setting) }
+
+ subject(:output) { described_class.new(application_setting).as_json }
+
+ context 'housekeeping_bitmaps_enabled usage is deprecated and always enabled' do
+ before do
+ application_setting.housekeeping_bitmaps_enabled = housekeeping_bitmaps_enabled
+ end
+
+ context 'when housekeeping_bitmaps_enabled db column is false' do
+ let(:housekeeping_bitmaps_enabled) { false }
+
+ it 'returns true' do
+ expect(subject[:housekeeping_bitmaps_enabled]).to eq(true)
+ end
+ end
+
+ context 'when housekeeping_bitmaps_enabled db column is true' do
+ let(:housekeeping_bitmaps_enabled) { false }
+
+ it 'returns true' do
+ expect(subject[:housekeeping_bitmaps_enabled]).to eq(true)
+ end
+ end
+ end
+end
diff --git a/spec/lib/gitlab/background_migration/fix_duplicate_project_name_and_path_spec.rb b/spec/lib/gitlab/background_migration/fix_duplicate_project_name_and_path_spec.rb
index 00d47d8ecf8..65663d26f37 100644
--- a/spec/lib/gitlab/background_migration/fix_duplicate_project_name_and_path_spec.rb
+++ b/spec/lib/gitlab/background_migration/fix_duplicate_project_name_and_path_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe Gitlab::BackgroundMigration::FixDuplicateProjectNameAndPath, :migration do
+RSpec.describe Gitlab::BackgroundMigration::FixDuplicateProjectNameAndPath, :migration, schema: 20220325155953 do
let(:migration) { described_class.new }
let(:namespaces) { table(:namespaces) }
let(:projects) { table(:projects) }
diff --git a/spec/lib/gitlab/database/migration_helpers/restrict_gitlab_schema_spec.rb b/spec/lib/gitlab/database/migration_helpers/restrict_gitlab_schema_spec.rb
index ad9a3a6e257..d873f1b7c75 100644
--- a/spec/lib/gitlab/database/migration_helpers/restrict_gitlab_schema_spec.rb
+++ b/spec/lib/gitlab/database/migration_helpers/restrict_gitlab_schema_spec.rb
@@ -496,11 +496,16 @@ RSpec.describe Gitlab::Database::MigrationHelpers::RestrictGitlabSchema, query_a
Gitlab::Database.database_base_models.each do |db_config_name, model|
context "for db_config_name=#{db_config_name}" do
around do |example|
+ verbose_was = ActiveRecord::Migration.verbose
+ ActiveRecord::Migration.verbose = false
+
with_reestablished_active_record_base do
reconfigure_db_connection(model: ActiveRecord::Base, config_model: model)
example.run
end
+ ensure
+ ActiveRecord::Migration.verbose = verbose_was
end
before do
@@ -543,8 +548,15 @@ RSpec.describe Gitlab::Database::MigrationHelpers::RestrictGitlabSchema, query_a
expect { ignore_error(Gitlab::Database::QueryAnalyzers::RestrictAllowedSchemas::DDLNotAllowedError) { migration_class.migrate(:down) } }.not_to raise_error
when :skipped
- expect { migration_class.migrate(:up) }.to raise_error(Gitlab::Database::MigrationHelpers::RestrictGitlabSchema::MigrationSkippedError)
- expect { migration_class.migrate(:down) }.to raise_error(Gitlab::Database::MigrationHelpers::RestrictGitlabSchema::MigrationSkippedError)
+ expect_next_instance_of(migration_class) do |migration_object|
+ expect(migration_object).to receive(:migration_skipped).and_call_original
+ expect(migration_object).not_to receive(:up)
+ expect(migration_object).not_to receive(:down)
+ expect(migration_object).not_to receive(:change)
+ end
+
+ migration_class.migrate(:up)
+ migration_class.migrate(:down)
end
end
end
diff --git a/spec/lib/gitlab/database_spec.rb b/spec/lib/gitlab/database_spec.rb
index 83b71bc4b9d..f6745bbdac7 100644
--- a/spec/lib/gitlab/database_spec.rb
+++ b/spec/lib/gitlab/database_spec.rb
@@ -265,6 +265,47 @@ RSpec.describe Gitlab::Database do
expect(described_class.gitlab_schemas_for_connection(ActiveRecord::Base.connection)).to include(:gitlab_ci, :gitlab_shared)
end
end
+
+ context "when there's CI connection", :request_store do
+ before do
+ skip_if_multiple_databases_not_setup
+
+ # FF due to lib/gitlab/database/load_balancing/configuration.rb:92
+ # Requires usage of `:request_store`
+ stub_feature_flags(force_no_sharing_primary_model: true)
+ end
+
+ context 'when CI uses database_tasks: false does indicate that ci: is subset of main:' do
+ before do
+ allow(Ci::ApplicationRecord.connection_db_config).to receive(:database_tasks?).and_return(false)
+ end
+
+ it 'does return gitlab_ci when accessing via main: connection' do
+ expect(described_class.gitlab_schemas_for_connection(Project.connection)).to include(:gitlab_ci, :gitlab_main, :gitlab_shared)
+ end
+
+ it 'does not return gitlab_main when accessing via ci: connection' do
+ expect(described_class.gitlab_schemas_for_connection(Ci::Build.connection)).to include(:gitlab_ci, :gitlab_shared)
+ expect(described_class.gitlab_schemas_for_connection(Ci::Build.connection)).not_to include(:gitlab_main)
+ end
+ end
+
+ context 'when CI uses database_tasks: true does indicate that ci: has own database' do
+ before do
+ allow(Ci::ApplicationRecord.connection_db_config).to receive(:database_tasks?).and_return(true)
+ end
+
+ it 'does not return gitlab_ci when accessing via main: connection' do
+ expect(described_class.gitlab_schemas_for_connection(Project.connection)).to include(:gitlab_main, :gitlab_shared)
+ expect(described_class.gitlab_schemas_for_connection(Project.connection)).not_to include(:gitlab_ci)
+ end
+
+ it 'does not return gitlab_main when accessing via ci: connection' do
+ expect(described_class.gitlab_schemas_for_connection(Ci::Build.connection)).to include(:gitlab_ci, :gitlab_shared)
+ expect(described_class.gitlab_schemas_for_connection(Ci::Build.connection)).not_to include(:gitlab_main)
+ end
+ end
+ end
end
describe '#true_value' do
diff --git a/spec/tasks/gitlab/db/validate_config_rake_spec.rb b/spec/tasks/gitlab/db/validate_config_rake_spec.rb
index 7b2f37414a0..2201db51275 100644
--- a/spec/tasks/gitlab/db/validate_config_rake_spec.rb
+++ b/spec/tasks/gitlab/db/validate_config_rake_spec.rb
@@ -72,18 +72,23 @@ RSpec.describe 'gitlab:db:validate_config', :silence_stdout do
expect { run_rake_task('gitlab:db:validate_config') }.to raise_error(match)
end
- it 'to stderr instead of exception for production' do
+ it 'for production' do
allow(Gitlab).to receive(:dev_or_test_env?).and_return(false)
- expect { run_rake_task('gitlab:db:validate_config') }.to output(match).to_stderr
+ expect { run_rake_task('gitlab:db:validate_config') }.to raise_error(match)
end
- it 'if GITLAB_VALIDATE_DATABASE_CONFIG is set' do
+ it 'if GITLAB_VALIDATE_DATABASE_CONFIG=1' do
stub_env('GITLAB_VALIDATE_DATABASE_CONFIG', '1')
- allow(Gitlab).to receive(:dev_or_test_env?).and_return(false)
expect { run_rake_task('gitlab:db:validate_config') }.to raise_error(match)
end
+
+ it 'to stderr if GITLAB_VALIDATE_DATABASE_CONFIG=0' do
+ stub_env('GITLAB_VALIDATE_DATABASE_CONFIG', '0')
+
+ expect { run_rake_task('gitlab:db:validate_config') }.to output(match).to_stderr
+ end
end
context 'when only main: is specified' do