Skip to content

Commit

Permalink
fix: Removed MySQL unused lock variable and broaden SQLite detection. (
Browse files Browse the repository at this point in the history
  • Loading branch information
seuros authored Feb 11, 2024
1 parent a3166e2 commit f818a18
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
name: CI Mysql
name: CI Mysql 5.7
on:
pull_request:
branches:
- master
concurrency:
group: ci-mysql5-${{ github.head_ref }}
cancel-in-progress: true

jobs:
minitest:
runs-on: ubuntu-latest
Expand Down
62 changes: 62 additions & 0 deletions .github/workflows/ci-mysql8.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: CI Mysql 8.0
on:
pull_request:
branches:
- master

concurrency:
group: ci-mysql8-${{ github.head_ref }}
cancel-in-progress: true

jobs:
minitest:
runs-on: ubuntu-latest
name: Ruby ${{ matrix.ruby }} / Rails ${{ matrix.rails }}
services:
mysql:
image: mysql/mysql-server
ports:
- "3306:3306"
env:
MYSQL_USER: with_advisory
MYSQL_PASSWORD: with_advisory_pass
MYSQL_DATABASE: with_advisory_lock_test
MYSQL_ROOT_HOST: '%'
strategy:
fail-fast: false
matrix:
ruby:
- '3.2'
- '3.1'
- '3.0'
- '2.7'
- '3.3'
- 'truffleruby'
rails:
- 7.1
- "7.0"
- 6.1
adapter:
- mysql2://with_advisory:with_advisory_pass@0/with_advisory_lock_test
# - trilogy://with_advisory:with_advisory_pass@0/with_advisory_lock_test Trilogy is not supported by mysql 8 with new encryption
include:
- ruby: jruby
rails: 6.1
adapter: jdbcmysql://with_advisory:with_advisory_pass@0/with_advisory_lock_test
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
rubygems: latest
env:
BUNDLE_GEMFILE: gemfiles/activerecord_${{ matrix.rails }}.gemfile
- name: Test
env:
BUNDLE_GEMFILE: gemfiles/activerecord_${{ matrix.rails }}.gemfile
DATABASE_URL: ${{ matrix.adapter }}
WITH_ADVISORY_LOCK_PREFIX: ${{ github.run_id }}
run: bundle exec rake
4 changes: 4 additions & 0 deletions .github/workflows/ci-postgresql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ on:
pull_request:
branches:
- master
concurrency:
group: ci-postgresql-${{ github.head_ref }}
cancel-in-progress: true

jobs:
minitest:
runs-on: ubuntu-latest
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
---
name: CI
name: CI Sqlite3

on:
pull_request:
branches:
- master

concurrency:
group: ci-sqlite3-${{ github.head_ref }}
cancel-in-progress: true

jobs:
minitest:
runs-on: ubuntu-latest
Expand Down
13 changes: 5 additions & 8 deletions lib/with_advisory_lock/database_adapter_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,22 @@

module WithAdvisoryLock
class DatabaseAdapterSupport
# Caches nested lock support by MySQL reported version
@@mysql_nl_cache = {}
@@mysql_nl_cache_mutex = Mutex.new

attr_reader :adapter_name
def initialize(connection)
@connection = connection
@sym_name = connection.adapter_name.downcase.to_sym
@adapter_name = connection.adapter_name.downcase.to_sym
end

def mysql?
%i[mysql2 trilogy].include? @sym_name
%i[mysql2 trilogy].include? adapter_name
end

def postgresql?
%i[postgresql empostgresql postgis].include? @sym_name
%i[postgresql empostgresql postgis].include? adapter_name
end

def sqlite?
@sym_name == :sqlite3
[:sqlite3, :sqlite].include? adapter_name
end
end
end
3 changes: 3 additions & 0 deletions lib/with_advisory_lock/mysql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

module WithAdvisoryLock
class MySQL < Base
# Caches nested lock support by MySQL reported version
@@mysql_nl_cache = {}
@@mysql_nl_cache_mutex = Mutex.new
# See https://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_get-lock
def try_lock
raise ArgumentError, 'shared locks are not supported on MySQL' if shared
Expand Down

0 comments on commit f818a18

Please sign in to comment.