# 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