Sha256: 9348264b9234e08e0e22875cf92a26eb7b0b4c87fb4a33f47f97b30d80df880d

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

require "active_support/core_ext/numeric"

module MigrationTimeouts
  module TimeoutManager
    def migrate(direction)
      return super unless direction == :up && !disable_ddl_transaction

      issue_lock_timeout if lock_timeout_configured?
      issue_statement_timeout if statement_timeout_configured?

      super
    end

    private

    def issue_lock_timeout
      execute "SET LOCAL lock_timeout = #{lock_timeout.in_milliseconds}"
    end

    def issue_statement_timeout
      execute "SET LOCAL statement_timeout = #{statement_timeout.in_milliseconds}"
    end

    def lock_timeout_configured?
      !self.class.lock_timeout_disabled && lock_timeout&.try(:positive?)
    end

    def statement_timeout_configured?
      !self.class.statement_timeout_disabled && statement_timeout&.try(:positive?)
    end

    def lock_timeout
      self.class.lock_timeout_override || MigrationTimeouts.config.default_lock_timeout
    end

    def statement_timeout
      self.class.statement_timeout_override || MigrationTimeouts.config.default_statement_timeout
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
migration_timeouts-0.0.1 lib/migration_timeouts/timeout_manager.rb