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

Code before:
          return false unless internal_metadata.enabled?
          return false unless internal_metadata.table_exists?

          internal_metadata[:schema_sha1] == schema_sha1(file)
        end
      end

      def reconstruct_from_schema(db_config, file = nil) # :nodoc:
        file ||= schema_dump_path(db_config, db_config.format)

        check_schema_file(file) if file

        with_temporary_pool(db_config, clobber: true) do
          if schema_up_to_date?(db_config, file)
            truncate_tables(db_config) unless ENV["SKIP_TEST_DATABASE_TRUNCATE"]
          else
            purge(db_config)
            load_schema(db_config, db_config.format, file)
          end
        rescue ActiveRecord::NoDatabaseError
          create(db_config)
          load_schema(db_config, db_config.format, file)
        end
      end

      def dump_schema(db_config, format) # :nodoc:
        return unless db_config.schema_dump
        format ||= db_config.schema_format

        require "active_record/schema_dumper"
        filename = schema_dump_path(db_config, format)
        return unless filename

        FileUtils.mkdir_p(db_dir)
        case format
        when :ruby
          File.open(filename, "w:utf-8") do |file|
            ActiveRecord::SchemaDumper.dump(migration_connection_pool, file)
          end
        when :sql
          structure_dump(db_config, filename)
          if migration_connection_pool.schema_migration.table_exists?
            File.open(filename, "a") do |f|
              f.puts migration_connection.dump_schema_information
              f.print "\n"
            end
          end
        end
      end

      def schema_dump_path(db_config, format = db_config.schema_format)

Review comment (bug):
Subtle, but this will break for any callers that omit the second parameter (there are a couple callers within Rails that do this). Especially since you want to default format to `db_config.schema_format` it's probably best to allow callers to just pass in the db_config without the format being required.

Code after:
          internal_metadata = pool.internal_metadata
          return false unless internal_metadata.enabled?
          return false unless internal_metadata.table_exists?

          internal_metadata[:schema_sha1] == schema_sha1(file)
        end
      end

      def reconstruct_from_schema(db_config, file = nil) # :nodoc:
        file ||= schema_dump_path(db_config, db_config.schema_format)

        check_schema_file(file) if file

        with_temporary_pool(db_config, clobber: true) do
          if schema_up_to_date?(db_config, nil, file)
            truncate_tables(db_config) unless ENV["SKIP_TEST_DATABASE_TRUNCATE"]
          else
            purge(db_config)
            load_schema(db_config, db_config.schema_format, file)
          end
        rescue ActiveRecord::NoDatabaseError
          create(db_config)
          load_schema(db_config, db_config.schema_format, file)
        end
      end

      def dump_all
        with_temporary_pool_for_each do |pool|
          db_config = pool.db_config
          ActiveRecord::Tasks::DatabaseTasks.dump_schema(db_config, ENV["SCHEMA_FORMAT"] || db_config.schema_format)
        end
      end

      def dump_schema(db_config, format = db_config.schema_format) # :nodoc:
        return unless db_config.schema_dump

        require "active_record/schema_dumper"
        filename = schema_dump_path(db_config, format)
        return unless filename

        FileUtils.mkdir_p(db_dir)
        case format.to_sym
        when :ruby
          File.open(filename, "w:utf-8") do |file|
            ActiveRecord::SchemaDumper.dump(migration_connection_pool, file)
          end
        when :sql
          structure_dump(db_config, filename)
          if migration_connection_pool.schema_migration.table_exists?
            File.open(filename, "a") do |f|
              f.puts migration_connection.dump_schema_versions