Skip to content
代码片段 群组 项目
提交 10e6b1d7 编辑于 作者: Rémy Coutable's avatar Rémy Coutable
浏览文件

Revert "Merge branch 'fix-ci-test-schema-diverge-from-main' into 'master'"

This reverts merge request !100455
上级 3612de75
No related branches found
No related tags found
无相关合并请求
...@@ -53,6 +53,8 @@ ...@@ -53,6 +53,8 @@
expect(shared_2.public_projects_minutes_cost_factor).to eq(0) expect(shared_2.public_projects_minutes_cost_factor).to eq(0)
expect(shared_3.public_projects_minutes_cost_factor).to eq(1) expect(shared_3.public_projects_minutes_cost_factor).to eq(1)
expect(group_1.public_projects_minutes_cost_factor).to eq(0) expect(group_1.public_projects_minutes_cost_factor).to eq(0)
schema_migrate_up!
end end
end end
end end
......
...@@ -2,15 +2,6 @@ ...@@ -2,15 +2,6 @@
module Database module Database
module MultipleDatabases module MultipleDatabases
def run_and_cleanup(example)
# Each example may call `migrate!`, so we must ensure we are migrated down every time
schema_migrate_down!
example.run
delete_from_all_tables!(except: deletion_except_tables)
end
def skip_if_multiple_databases_not_setup def skip_if_multiple_databases_not_setup
skip 'Skipping because multiple databases not set up' unless Gitlab::Database.has_config?(:ci) skip 'Skipping because multiple databases not set up' unless Gitlab::Database.has_config?(:ci)
end end
...@@ -31,21 +22,6 @@ def reconfigure_db_connection(name: nil, config_hash: {}, model: ActiveRecord::B ...@@ -31,21 +22,6 @@ def reconfigure_db_connection(name: nil, config_hash: {}, model: ActiveRecord::B
model.establish_connection(new_db_config) model.establish_connection(new_db_config)
end end
def ensure_schema_and_empty_tables
# Ensure all schemas for both databases are migrated back
Gitlab::Database.database_base_models.each do |_, base_model|
with_reestablished_active_record_base do
reconfigure_db_connection(
model: ActiveRecord::Base,
config_model: base_model
)
schema_migrate_up!
delete_from_all_tables!(except: deletion_except_tables)
end
end
end
# The usage of this method switches temporarily used `connection_handler` # The usage of this method switches temporarily used `connection_handler`
# allowing full manipulation of ActiveRecord::Base connections without # allowing full manipulation of ActiveRecord::Base connections without
# having side effects like: # having side effects like:
...@@ -133,15 +109,7 @@ def establish_connection(*args) ...@@ -133,15 +109,7 @@ def establish_connection(*args)
end end
end end
config.append_after(:context, :migration) do
break if recreate_databases_and_seed_if_needed
ensure_schema_and_empty_tables
end
config.around(:each, :migration) do |example| config.around(:each, :migration) do |example|
self.class.use_transactional_tests = false
migration_schema = example.metadata[:migration] migration_schema = example.metadata[:migration]
migration_schema = :gitlab_main if migration_schema == true migration_schema = :gitlab_main if migration_schema == true
base_model = Gitlab::Database.schemas_to_base_models.fetch(migration_schema).first base_model = Gitlab::Database.schemas_to_base_models.fetch(migration_schema).first
...@@ -154,13 +122,11 @@ def establish_connection(*args) ...@@ -154,13 +122,11 @@ def establish_connection(*args)
config_model: base_model config_model: base_model
) )
run_and_cleanup(example) example.run
end end
else else
run_and_cleanup(example) example.run
end end
self.class.use_transactional_tests = true
end end
end end
......
...@@ -13,6 +13,19 @@ ...@@ -13,6 +13,19 @@
DatabaseCleaner.clean_with(:deletion) DatabaseCleaner.clean_with(:deletion)
end end
config.append_after(:context, :migration) do
delete_from_all_tables!(except: ['work_item_types'])
# Postgres maximum number of columns in a table is 1600 (https://github.com/postgres/postgres/blob/de41869b64d57160f58852eab20a27f248188135/src/include/access/htup_details.h#L23-L47).
# We drop and recreate the database if any table has more than 1200 columns, just to be safe.
if any_connection_class_with_more_than_allowed_columns?
recreate_all_databases!
# Seed required data as recreating DBs will delete it
TestEnv.seed_db
end
end
config.around(:each, :delete) do |example| config.around(:each, :delete) do |example|
self.class.use_transactional_tests = false self.class.use_transactional_tests = false
...@@ -22,4 +35,14 @@ ...@@ -22,4 +35,14 @@
self.class.use_transactional_tests = true self.class.use_transactional_tests = true
end end
config.around(:each, :migration) do |example|
self.class.use_transactional_tests = false
example.run
delete_from_all_tables!(except: ['work_item_types'])
self.class.use_transactional_tests = true
end
end end
...@@ -78,19 +78,6 @@ def recreate_all_databases! ...@@ -78,19 +78,6 @@ def recreate_all_databases!
puts "Databases re-creation done in #{Gitlab::Metrics::System.monotonic_time - start}" puts "Databases re-creation done in #{Gitlab::Metrics::System.monotonic_time - start}"
end end
def recreate_databases_and_seed_if_needed
# Postgres maximum number of columns in a table is 1600 (https://github.com/postgres/postgres/blob/de41869b64d57160f58852eab20a27f248188135/src/include/access/htup_details.h#L23-L47).
# We drop and recreate the database if any table has more than 1200 columns, just to be safe.
return false unless any_connection_class_with_more_than_allowed_columns?
recreate_all_databases!
# Seed required data as recreating DBs will delete it
TestEnv.seed_db
true
end
def force_disconnect_all_connections! def force_disconnect_all_connections!
cmd = <<~SQL cmd = <<~SQL
SELECT pg_terminate_backend(pg_stat_activity.pid) SELECT pg_terminate_backend(pg_stat_activity.pid)
......
...@@ -19,9 +19,13 @@ ...@@ -19,9 +19,13 @@
# Each example may call `migrate!`, so we must ensure we are migrated down every time # Each example may call `migrate!`, so we must ensure we are migrated down every time
config.before(:each, :migration) do config.before(:each, :migration) do
use_fake_application_settings use_fake_application_settings
schema_migrate_down!
end end
config.after(:context, :migration) do config.after(:context, :migration) do
schema_migrate_up!
Gitlab::CurrentSettings.clear_in_memory_application_settings! Gitlab::CurrentSettings.clear_in_memory_application_settings!
end end
end end
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册