Skip to content

feat: add support for MySQL #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [1.5.0]
### Added
- Support for MySQL/MariaDB

### Removed
- Dropped support for Rails 6.0 and earlier
- Dropped support for Ruby 3.0 and earlier
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

Migration Lock Timeout is a Ruby gem that adds a lock timeout to all Active
Record migrations in your Ruby on Rails project. A lock timeout sets a timeout
on how long PostgreSQL will wait to acquire a lock on tables being altered
on how long PostgreSQL/MySQL/MariaDB will wait to acquire a lock on tables being altered
before failing and rolling back. This prevents migrations from creating
additional lock contention that can take down your site when it's under heavy
load. Migration Lock Timeout currently only supports [PostgreSQL](https://www.postgresql.org/)
load. Migration Lock Timeout currently only supports [PostgreSQL](https://www.postgresql.org/), [MySQL](https://www.mysql.com/), [MariaDB](https://mariadb.org/)

## Installation

Expand Down
7 changes: 6 additions & 1 deletion lib/migration_lock_timeout/lock_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ def migrate(direction)
timeout_disabled = self.class.disable_lock_timeout
time = self.class.lock_timeout_override ||
MigrationLockTimeout.try(:config).try(:default_timeout)
adapter = ActiveRecord::Base.connection_db_config.adapter
if !timeout_disabled && direction == :up && time && !disable_ddl_transaction
safety_assured? do
execute "SET LOCAL lock_timeout = '#{time}s'"
if adapter.include?("mysql")
execute "SET SESSION lock_wait_timeout = #{time}"
else
execute "SET LOCAL lock_timeout = '#{time}s'"
end
end
end
super
Expand Down