Skip to content
Snippets Groups Projects
Verified Commit 512f9e33 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre
Browse files

Introduce :gitlab_geo schema for Geo tracking DB

Changelog: added
EE: true
parent ba07dcba
No related branches found
No related tags found
No related merge requests found
This commit is part of merge request !85842. Comments created here will be created in the context of that merge request.
...@@ -23,6 +23,7 @@ Each table of GitLab needs to have a `gitlab_schema` assigned: ...@@ -23,6 +23,7 @@ Each table of GitLab needs to have a `gitlab_schema` assigned:
- `gitlab_main`: describes all tables that are being stored in the `main:` database (for example, like `projects`, `users`). - `gitlab_main`: describes all tables that are being stored in the `main:` database (for example, like `projects`, `users`).
- `gitlab_ci`: describes all CI tables that are being stored in the `ci:` database (for example, `ci_pipelines`, `ci_builds`). - `gitlab_ci`: describes all CI tables that are being stored in the `ci:` database (for example, `ci_pipelines`, `ci_builds`).
- `gitlab_geo`: describes all Geo tables that are being stored in the `geo:` database (for example, like `project_registry`, `secondary_usage_data`).
- `gitlab_shared`: describe all application tables that contain data across all decomposed databases (for example, `loose_foreign_keys_deleted_records`) for models that inherit from `Gitlab::Database::SharedModel`. - `gitlab_shared`: describe all application tables that contain data across all decomposed databases (for example, `loose_foreign_keys_deleted_records`) for models that inherit from `Gitlab::Database::SharedModel`.
- `gitlab_internal`: describe all internal tables of Rails and PostgreSQL (for example, `ar_internal_metadata`, `schema_migrations`, `pg_*`). - `gitlab_internal`: describe all internal tables of Rails and PostgreSQL (for example, `ar_internal_metadata`, `schema_migrations`, `pg_*`).
- `...`: more schemas to be introduced with additional decomposed databases - `...`: more schemas to be introduced with additional decomposed databases
...@@ -31,6 +32,7 @@ The usage of schema enforces the base class to be used: ...@@ -31,6 +32,7 @@ The usage of schema enforces the base class to be used:
- `ApplicationRecord` for `gitlab_main` - `ApplicationRecord` for `gitlab_main`
- `Ci::ApplicationRecord` for `gitlab_ci` - `Ci::ApplicationRecord` for `gitlab_ci`
- `Geo::TrackingBase` for `gitlab_geo`
- `Gitlab::Database::SharedModel` for `gitlab_shared` - `Gitlab::Database::SharedModel` for `gitlab_shared`
### The impact of `gitlab_schema` ### The impact of `gitlab_schema`
......
# frozen_string_literal: true
module EE
module Gitlab
module Database
module GitlabSchema
extend ActiveSupport::Concern
class_methods do
extend ::Gitlab::Utils::Override
override :tables_to_schema
def tables_to_schema
@tables_to_schema ||= super.merge(ee_tables_to_schema)
end
def ee_tables_to_schema
@ee_tables_to_schema ||= YAML.load_file(Rails.root.join('ee/lib/ee/gitlab/database/gitlab_schemas.yml'))
end
end
end
end
end
end
container_repository_registry: :gitlab_geo
design_registry: :gitlab_geo
event_log_states: :gitlab_geo
file_registry: :gitlab_geo
group_wiki_repository_registry: :gitlab_geo
job_artifact_registry: :gitlab_geo
lfs_object_registry: :gitlab_geo
merge_request_diff_registry: :gitlab_geo
package_file_registry: :gitlab_geo
pages_deployment_registry: :gitlab_geo
pipeline_artifact_registry: :gitlab_geo
project_registry: :gitlab_geo
secondary_usage_data: :gitlab_geo
snippet_repository_registry: :gitlab_geo
terraform_state_version_registry: :gitlab_geo
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::Database::GitlabSchema do
describe '.tables_to_schema' do
subject { described_class.tables_to_schema }
it 'all tables have assigned a known gitlab_schema' do
is_expected.to all(
match([be_a(String), be_in([:gitlab_internal, :gitlab_shared, :gitlab_main, :gitlab_ci, :gitlab_geo])])
)
end
context "for geo using Geo::TrackingBase" do
let(:db_class) { Geo::TrackingBase }
let(:db_data_sources) { db_class.connection.data_sources }
let(:geo_tables_to_schema) { subject.select { |_, schema| [:gitlab_internal, :gitlab_geo].include?(schema) }.keys }
it 'new data sources are added' do
missing_tables = db_data_sources.to_set - geo_tables_to_schema
expect(missing_tables).to be_empty, \
"Missing table(s) #{missing_tables.to_a} not found in #{described_class}.tables_to_schema. " \
"Any new tables must be added to ee/spec/lib/ee/gitlab/database/gitlab_schemas.yml."
end
it 'non-existing data sources are removed' do
# The Geo database does not share the same structure as all decomposed databases
extra_tables = geo_tables_to_schema.to_set - db_data_sources
expect(extra_tables).to be_empty, \
"Extra table(s) #{extra_tables.to_a} found in #{described_class}.tables_to_schema. " \
"Any removed or renamed tables must be removed from ee/spec/lib/ee/gitlab/database/gitlab_schemas.yml."
end
end
end
describe '.table_schema' do
using RSpec::Parameterized::TableSyntax
where(:name, :classification) do
'project_registry' | :gitlab_geo
'my_schema.project_registry' | :gitlab_geo
end
with_them do
subject { described_class.table_schema(name) }
it { is_expected.to eq(classification) }
end
end
end
...@@ -102,3 +102,5 @@ def self.schema_names ...@@ -102,3 +102,5 @@ def self.schema_names
end end
end end
end end
Gitlab::Database::GitlabSchema.prepend_mod
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
RSpec.describe Gitlab::Database::GitlabSchema do RSpec.describe Gitlab::Database::GitlabSchema do
describe '.tables_to_schema' do describe '.tables_to_schema' do
subject { described_class.tables_to_schema } # The Geo database does not share the same structure as all decomposed databases
subject { described_class.tables_to_schema.select { |_, v| v != :gitlab_geo } }
it 'all tables have assigned a known gitlab_schema' do it 'all tables have assigned a known gitlab_schema' do
is_expected.to all( is_expected.to all(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment