diff --git a/.gitignore b/.gitignore index 320be80..ce1295a 100644 --- a/.gitignore +++ b/.gitignore @@ -7,7 +7,8 @@ /spec/reports/ /tmp/ /test/dummy_app/tmp/ -/test/dummy_app/db/migrate/*.rb -/test/dummy_app/db/schema.rb +/test/dummy_app/db/*/*.rb +/test/dummy_app/db/*.rb .ruby-version .ruby-gemset +/gemfiles/*.gemfile.lock diff --git a/test/support/test_utils.rb b/test/support/test_utils.rb index fd3fe1a..2586c3f 100644 --- a/test/support/test_utils.rb +++ b/test/support/test_utils.rb @@ -140,17 +140,26 @@ def migrated_files(db_config = nil) def cleanup_call(prefix_name = nil) delete_migrations_files(prefix_name) - if ActiveRecord::SchemaMigration.respond_to?(:create_table) - ActiveRecord::SchemaMigration.create_table - else - ActiveRecord::SchemaMigration.new(ActiveRecord::Base.connection).create_table - end + create_schema_migration_table run_sql("delete from schema_migrations") remove_app_dir(MIGRATED_PATHS.fetch(prefix_name&.to_sym, migrated_paths.first)) define_migrations(prefix_name) Rails.application.load_tasks end + def create_schema_migration_table + if ActiveRecord::SchemaMigration.respond_to?(:create_table) + ActiveRecord::SchemaMigration.create_table + else + ar_version = Gem::Version.new(ActiveRecord::VERSION::STRING) + if ar_version >= Gem::Version.new("7.2.0") || (ar_version >= Gem::Version.new("7.1.0") && ar_version.prerelease?) + ActiveRecord::SchemaMigration.new(ActiveRecord::Base.connection_pool).create_table + else + ActiveRecord::SchemaMigration.new(ActiveRecord::Base.connection).create_table + end + end + end + def delete_migrations_files_for(path) Dir.glob(app_file("#{path}/**/*.rb")).each do |file| remove_app_dir(file)