diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 10:33:21 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 10:33:21 +0300 |
commit | 36a59d088eca61b834191dacea009677a96c052f (patch) | |
tree | e4f33972dab5d8ef79e3944a9f403035fceea43f /spec/support/helpers/migrations_helpers.rb | |
parent | a1761f15ec2cae7c7f7bbda39a75494add0dfd6f (diff) |
Add latest changes from gitlab-org/gitlab@15-0-stable-eev15.0.0-rc42
Diffstat (limited to 'spec/support/helpers/migrations_helpers.rb')
-rw-r--r-- | spec/support/helpers/migrations_helpers.rb | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/spec/support/helpers/migrations_helpers.rb b/spec/support/helpers/migrations_helpers.rb index afa7ee84bda..60097e301c4 100644 --- a/spec/support/helpers/migrations_helpers.rb +++ b/spec/support/helpers/migrations_helpers.rb @@ -1,12 +1,18 @@ # frozen_string_literal: true module MigrationsHelpers - def active_record_base - Gitlab::Database.database_base_models.fetch(self.class.metadata[:database] || :main) + def active_record_base(database: nil) + database_name = database || self.class.metadata[:database] || :main + + unless Gitlab::Database::DATABASE_NAMES.include?(database_name.to_s) + raise ArgumentError, "#{database_name} is not a valid argument" + end + + Gitlab::Database.database_base_models[database_name] || Gitlab::Database.database_base_models[:main] end - def table(name) - Class.new(active_record_base) do + def table(name, database: nil) + Class.new(active_record_base(database: database)) do self.table_name = name self.inheritance_column = :_type_disabled @@ -150,6 +156,13 @@ module MigrationsHelpers end def migrate! + open_transactions = ActiveRecord::Base.connection.open_transactions + allow_next_instance_of(described_class) do |migration| + allow(migration).to receive(:transaction_open?) do + ActiveRecord::Base.connection.open_transactions > open_transactions + end + end + migration_context.up do |migration| migration.name == described_class.name end |