debian-mirror-gitlab/spec/lib/gitlab/database/gitlab_schema_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

62 lines
2.4 KiB
Ruby
Raw Normal View History

2021-12-11 22:18:48 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::Database::GitlabSchema do
describe '.tables_to_schema' do
it 'all tables have assigned a known gitlab_schema' do
2022-08-13 15:12:31 +05:30
expect(described_class.tables_to_schema).to all(
match([be_a(String), be_in(Gitlab::Database.schemas_to_base_models.keys.map(&:to_sym))])
2021-12-11 22:18:48 +05:30
)
end
# This being run across different databases indirectly also tests
# a general consistency of structure across databases
2022-08-13 15:12:31 +05:30
Gitlab::Database.database_base_models.select { |k, _| k != 'geo' }.each do |db_config_name, db_class|
2021-12-11 22:18:48 +05:30
context "for #{db_config_name} using #{db_class}" do
2022-08-13 15:12:31 +05:30
let(:db_data_sources) { db_class.connection.data_sources }
# The Geo database does not share the same structure as all decomposed databases
subject { described_class.tables_to_schema.select { |_, v| v != :gitlab_geo } }
2021-12-11 22:18:48 +05:30
it 'new data sources are added' do
missing_tables = db_data_sources.to_set - subject.keys
expect(missing_tables).to be_empty, \
"Missing table(s) #{missing_tables.to_a} not found in #{described_class}.tables_to_schema. " \
2022-08-13 15:12:31 +05:30
"Any new tables must be added to #{described_class::GITLAB_SCHEMAS_FILE}."
2021-12-11 22:18:48 +05:30
end
it 'non-existing data sources are removed' do
extra_tables = subject.keys.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. " \
2022-08-13 15:12:31 +05:30
"Any removed or renamed tables must be removed from #{described_class::GITLAB_SCHEMAS_FILE}."
2021-12-11 22:18:48 +05:30
end
end
end
end
describe '.table_schema' do
using RSpec::Parameterized::TableSyntax
where(:name, :classification) do
'ci_builds' | :gitlab_ci
'my_schema.ci_builds' | :gitlab_ci
2022-07-23 23:45:48 +05:30
'information_schema.columns' | :gitlab_internal
2021-12-11 22:18:48 +05:30
'audit_events_part_5fc467ac26' | :gitlab_main
2022-04-04 11:22:00 +05:30
'_test_gitlab_main_table' | :gitlab_main
'_test_gitlab_ci_table' | :gitlab_ci
2021-12-11 22:18:48 +05:30
'_test_my_table' | :gitlab_shared
2022-07-23 23:45:48 +05:30
'pg_attribute' | :gitlab_internal
2021-12-11 22:18:48 +05:30
'my_other_table' | :undefined_my_other_table
end
with_them do
subject { described_class.table_schema(name) }
it { is_expected.to eq(classification) }
end
end
end