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

Code before:
          connection_handler.clear_active_connections!(:all)
          connection_handler.flush_idle_connections!(:all)
        end
      end
    end

    initializer "active_record.set_filter_attributes" do
      ActiveSupport.on_load(:active_record) do
        self.filter_attributes += Rails.application.config.filter_parameters
      end
    end

    initializer "active_record.configure_message_verifiers" do
      config.before_initialize do |app|
        secret = ActiveRecord::Base.signed_id_verifier_secret
        secret_generator = if secret
          secret.respond_to?(:call) ? -> (_) { secret.call } : -> (_) { secret }
        else
          -> (_) { Rails.application.key_generator.generate_key("active_record/signed_id") }
        end
        legacy_options = { secret_generator: secret_generator, digest: "SHA256", serializer: JSON, url_safe: true }.compact

        if app.config.active_record.use_legacy_signed_id_verifier == :generate_and_verify
          app.message_verifiers.prepend { |salt| legacy_options if salt == "active_record/signed_id" }
        elsif app.config.active_record.use_legacy_signed_id_verifier == :verify
          app.message_verifiers.rotate { |salt| legacy_options if salt == "active_record/signed_id" }
        else
          raise ArgumentError, "Unknown value for ActiveRecord::Base.use_legacy_signed_id_verifier: #{app.config.active_record.use_legacy_signed_id_verifier}"
        end
      end
    end

    initializer "active_record.set_signed_id_verifier" do
      config.after_initialize do |app|
        ActiveSupport.on_load(:active_record) do
          self.message_verifiers = app.message_verifiers
        end
      end
    end

    initializer "active_record.generated_token_verifier" do
      config.after_initialize do |app|
        ActiveSupport.on_load(:active_record) do
          self.generated_token_verifier ||= app.message_verifier("active_record/token_for")
        end
      end
    end

    initializer "active_record_encryption.configuration" do |app|
      ActiveSupport.on_load(:active_record_encryption) do
        ActiveRecord::Encryption.configure(

Review comment (suggestion):
I think this can be simplified:

```suggestion
      ActiveRecord.message_verifiers = app.message_verifiers

      use_legacy_signed_id_verifier = app.config.active_record.use_legacy_signed_id_verifier
      legacy_options = { digest: "SHA256", serializer: JSON, url_safe: true }

      if use_legacy_signed_id_verifier == :generate_and_verify
        app.message_verifiers.prepend { |salt| legacy_options if salt == "active_record/signed_id" }
      elsif use_legacy_signed_id_verifier == :verify
        app.message_verifiers.rotate { |salt| legacy_options if salt == "active_record/signed_id" }
      elsif use_legacy_signed_id_verifier
        raise "Unrecognized value for config.active_record.use_legacy_signed_id_verifier: #{use_legacy_signed_id_verifier.inspect}"
      end
```


Code after:

          connection_handler.clear_active_connections!(:all)
          connection_handler.flush_idle_connections!(:all)
        end
      end
    end

    initializer "active_record.set_filter_attributes" do
      ActiveSupport.on_load(:active_record) do
        self.filter_attributes += Rails.application.config.filter_parameters
      end
    end

    initializer "active_record.configure_message_verifiers" do |app|
      ActiveRecord.message_verifiers = app.message_verifiers

      use_legacy_signed_id_verifier = app.config.active_record.use_legacy_signed_id_verifier
      legacy_options = { digest: "SHA256", serializer: JSON, url_safe: true }

      if use_legacy_signed_id_verifier == :generate_and_verify
        app.message_verifiers.prepend { |salt| legacy_options if salt == "active_record/signed_id" }
      elsif use_legacy_signed_id_verifier == :verify
        app.message_verifiers.rotate { |salt| legacy_options if salt == "active_record/signed_id" }
      elsif use_legacy_signed_id_verifier
        raise ArgumentError, "Unrecognized value for config.active_record.use_legacy_signed_id_verifier: #{use_legacy_signed_id_verifier.inspect}"
      end
    end

    initializer "active_record.generated_token_verifier" do
      config.after_initialize do |app|
        ActiveSupport.on_load(:active_record) do
          self.generated_token_verifier ||= app.message_verifier("active_record/token_for")
        end
      end
    end

    initializer "active_record_encryption.configuration" do |app|
      ActiveSupport.on_load(:active_record_encryption) do
        ActiveRecord::Encryption.configure(
          primary_key: app.credentials.dig(:active_record_encryption, :primary_key),
          deterministic_key: app.credentials.dig(:active_record_encryption, :deterministic_key),
          key_derivation_salt: app.credentials.dig(:active_record_encryption, :key_derivation_salt),
          **app.config.active_record.encryption
        )

        auto_filtered_parameters = ActiveRecord::Encryption::AutoFilteredParameters.new(app)
        auto_filtered_parameters.enable if ActiveRecord::Encryption.config.add_to_filter_parameters
      end

      ActiveSupport.on_load(:active_record) do
        # Support extended queries for deterministic attributes and validations