Repository: rails/rails
File: activerecord/lib/active_record/migration.rb (Ruby)

Code before:
      end

      def load_schema_if_pending!
        any_schema_needs_update = false
        pending_migrations = []

        db_configs_in_current_env.each do |db_config|
          ActiveRecord::PendingMigrationConnection.with_temporary_pool(db_config) do |pool|
            any_schema_needs_update ||= schema_needs_update?(db_config, pool)

            if pending = pool.migration_context.open.pending_migrations
              pending_migrations << pending
            end
          end
        end

        if any_schema_needs_update
          load_schema!
        else
          check_pending_migrations(pending_migrations.flatten)
        end
      end

      def maintain_test_schema! # :nodoc:
        if ActiveRecord.maintain_test_schema
          suppress_messages { load_schema_if_pending! }
        end
      end

      def method_missing(name, ...) # :nodoc:
        nearest_delegate.send(name, ...)
      end

      def migrate(direction)
        new.migrate direction
      end

      # Disable the transaction wrapping this migration.
      # You can still create your own transactions even after calling #disable_ddl_transaction!
      #
      # For more details read the {"Transactional Migrations" section above}[rdoc-ref:Migration].
      def disable_ddl_transaction!
        @disable_ddl_transaction = true
      end

      def check_pending_migrations(migrations = nil) # :nodoc:
        migrations ||= pending_migrations

        if migrations.any?
          raise ActiveRecord::PendingMigrationError.new(pending_migrations: migrations)
        end

Review comment (suggestion):
```suggestion
        if any_schema_needs_update
          load_schema!
        end
        check_pending_migrations(pending_migrations.flatten)
```

You have a logic difference here. Before your patch `check_pending_migrations` was always called.

Code after:
      end

      def load_schema_if_pending!
        any_schema_needs_update = false
        pending_migrations = []

        db_configs_in_current_env.each do |db_config|
          ActiveRecord::PendingMigrationConnection.with_temporary_pool(db_config) do |pool|
            any_schema_needs_update ||= schema_needs_update?(db_config, pool)

            pending = pool.migration_context.open.pending_migrations
            pending_migrations.concat(pending)
          end
        end

        if any_schema_needs_update
          load_schema!

          pending_migrations = []
          db_configs_in_current_env.each do |db_config|
            ActiveRecord::PendingMigrationConnection.with_temporary_pool(db_config) do |pool|
              pending = pool.migration_context.open.pending_migrations
              pending_migrations.concat(pending)
            end
          end
        end

        check_pending_migrations(pending_migrations)
      end

      def maintain_test_schema! # :nodoc:
        if ActiveRecord.maintain_test_schema
          suppress_messages { load_schema_if_pending! }
        end
      end

      def method_missing(name, ...) # :nodoc:
        nearest_delegate.send(name, ...)
      end

      def migrate(direction)
        new.migrate direction
      end

      # Disable the transaction wrapping this migration.
      # You can still create your own transactions even after calling #disable_ddl_transaction!
      #
      # For more details read the {"Transactional Migrations" section above}[rdoc-ref:Migration].
      def disable_ddl_transaction!
        @disable_ddl_transaction = true
      end