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

Code before:
      def seeds?
        configuration_hash.fetch(:seeds, primary?)
      end

      # Determines whether to dump the schema/structure files and the filename that
      # should be used.
      #
      # If `configuration_hash[:schema_dump]` is set to `false` or `nil` the schema
      # will not be dumped.
      #
      # If the config option is set that will be used. Otherwise Rails will generate
      # the filename from the database config name.
      def schema_dump(format = schema_format)
        if configuration_hash.key?(:schema_dump)
          if config = configuration_hash[:schema_dump]
            config
          end
        elsif primary?
          schema_file_type(format)
        else
          "#{name}_#{schema_file_type(format)}"
        end
      end

      def schema_format(check_env: false)
        return ENV["SCHEMA_FORMAT"] if check_env && ENV["SCHEMA_FORMAT"].present?

        configuration_hash[:schema_format]&.to_sym || ActiveRecord.schema_format
      end

      def database_tasks? # :nodoc:
        !replica? && !!configuration_hash.fetch(:database_tasks, true)
      end

      def use_metadata_table? # :nodoc:
        configuration_hash.fetch(:use_metadata_table, true)
      end

      private
        def schema_file_type(format)
          case format
          when :ruby
            "schema.rb"
          when :sql
            "structure.sql"
          end
        end
    end
  end
end


Review comment (performance):
Reference to the `SCHEMA_FORMAT` environment variable is limited to the database tasks today. It feels like it's an unnecessary complexity here. Do we really need to move it here?

Code after:
      def seeds?
        configuration_hash.fetch(:seeds, primary?)
      end

      # Determines whether to dump the schema/structure files and the filename that
      # should be used.
      #
      # If `configuration_hash[:schema_dump]` is set to `false` or `nil` the schema
      # will not be dumped.
      #
      # If the config option is set that will be used. Otherwise Rails will generate
      # the filename from the database config name.
      def schema_dump(format = schema_format)
        if configuration_hash.key?(:schema_dump)
          if config = configuration_hash[:schema_dump]
            config
          end
        elsif primary?
          schema_file_type(format)
        else
          "#{name}_#{schema_file_type(format)}"
        end
      end

      def schema_format # :nodoc:
        format = configuration_hash[:schema_format]&.to_sym || ActiveRecord.schema_format
        raise "Invalid schema format" unless [ :ruby, :sql ].include? format
        format
      end

      def database_tasks? # :nodoc:
        !replica? && !!configuration_hash.fetch(:database_tasks, true)
      end

      def use_metadata_table? # :nodoc:
        configuration_hash.fetch(:use_metadata_table, true)
      end

      private
        def schema_file_type(format)
          case format.to_sym
          when :ruby
            "schema.rb"
          when :sql
            "structure.sql"
          end
        end
    end
  end
end