summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/database/loose_foreign_keys_spec.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-12-20 13:37:47 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-12-20 13:37:47 +0000
commitaee0a117a889461ce8ced6fcf73207fe017f1d99 (patch)
tree891d9ef189227a8445d83f35c1b0fc99573f4380 /spec/lib/gitlab/database/loose_foreign_keys_spec.rb
parent8d46af3258650d305f53b819eabf7ab18d22f59e (diff)
downloadgitlab-ce-aee0a117a889461ce8ced6fcf73207fe017f1d99.tar.gz
Add latest changes from gitlab-org/gitlab@14-6-stable-eev14.6.0-rc42
Diffstat (limited to 'spec/lib/gitlab/database/loose_foreign_keys_spec.rb')
-rw-r--r--spec/lib/gitlab/database/loose_foreign_keys_spec.rb45
1 files changed, 45 insertions, 0 deletions
diff --git a/spec/lib/gitlab/database/loose_foreign_keys_spec.rb b/spec/lib/gitlab/database/loose_foreign_keys_spec.rb
new file mode 100644
index 00000000000..13f2d31bc32
--- /dev/null
+++ b/spec/lib/gitlab/database/loose_foreign_keys_spec.rb
@@ -0,0 +1,45 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::Database::LooseForeignKeys do
+ describe 'verify all definitions' do
+ subject(:definitions) { described_class.definitions }
+
+ it 'all definitions have assigned a known gitlab_schema and on_delete' do
+ is_expected.to all(have_attributes(
+ options: a_hash_including(
+ column: be_a(String),
+ gitlab_schema: be_in(Gitlab::Database.schemas_to_base_models.symbolize_keys.keys),
+ on_delete: be_in([:async_delete, :async_nullify])
+ ),
+ from_table: be_a(String),
+ to_table: be_a(String)
+ ))
+ end
+
+ describe 'ensuring database integrity' do
+ def base_models_for(table)
+ parent_table_schema = Gitlab::Database::GitlabSchema.table_schema(table)
+ Gitlab::Database.schemas_to_base_models.fetch(parent_table_schema)
+ end
+
+ it 'all `to_table` tables are present' do
+ definitions.each do |definition|
+ base_models_for(definition.to_table).each do |model|
+ expect(model.connection).to be_table_exist(definition.to_table)
+ end
+ end
+ end
+
+ it 'all `from_table` tables are present' do
+ definitions.each do |definition|
+ base_models_for(definition.from_table).each do |model|
+ expect(model.connection).to be_table_exist(definition.from_table)
+ expect(model.connection).to be_column_exist(definition.from_table, definition.column)
+ end
+ end
+ end
+ end
+ end
+end