Skip to content

Commit f818a18

Browse files
authored
fix: Removed MySQL unused lock variable and broaden SQLite detection. (#94)
1 parent a3166e2 commit f818a18

6 files changed

Lines changed: 84 additions & 10 deletions

File tree

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
name: CI Mysql
1+
name: CI Mysql 5.7
22
on:
33
pull_request:
44
branches:
55
- master
6+
concurrency:
7+
group: ci-mysql5-${{ github.head_ref }}
8+
cancel-in-progress: true
9+
610
jobs:
711
minitest:
812
runs-on: ubuntu-latest

.github/workflows/ci-mysql8.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: CI Mysql 8.0
2+
on:
3+
pull_request:
4+
branches:
5+
- master
6+
7+
concurrency:
8+
group: ci-mysql8-${{ github.head_ref }}
9+
cancel-in-progress: true
10+
11+
jobs:
12+
minitest:
13+
runs-on: ubuntu-latest
14+
name: Ruby ${{ matrix.ruby }} / Rails ${{ matrix.rails }}
15+
services:
16+
mysql:
17+
image: mysql/mysql-server
18+
ports:
19+
- "3306:3306"
20+
env:
21+
MYSQL_USER: with_advisory
22+
MYSQL_PASSWORD: with_advisory_pass
23+
MYSQL_DATABASE: with_advisory_lock_test
24+
MYSQL_ROOT_HOST: '%'
25+
strategy:
26+
fail-fast: false
27+
matrix:
28+
ruby:
29+
- '3.2'
30+
- '3.1'
31+
- '3.0'
32+
- '2.7'
33+
- '3.3'
34+
- 'truffleruby'
35+
rails:
36+
- 7.1
37+
- "7.0"
38+
- 6.1
39+
adapter:
40+
- mysql2://with_advisory:with_advisory_pass@0/with_advisory_lock_test
41+
# - trilogy://with_advisory:with_advisory_pass@0/with_advisory_lock_test Trilogy is not supported by mysql 8 with new encryption
42+
include:
43+
- ruby: jruby
44+
rails: 6.1
45+
adapter: jdbcmysql://with_advisory:with_advisory_pass@0/with_advisory_lock_test
46+
steps:
47+
- name: Checkout
48+
uses: actions/checkout@v4
49+
- name: Setup Ruby
50+
uses: ruby/setup-ruby@v1
51+
with:
52+
ruby-version: ${{ matrix.ruby }}
53+
bundler-cache: true
54+
rubygems: latest
55+
env:
56+
BUNDLE_GEMFILE: gemfiles/activerecord_${{ matrix.rails }}.gemfile
57+
- name: Test
58+
env:
59+
BUNDLE_GEMFILE: gemfiles/activerecord_${{ matrix.rails }}.gemfile
60+
DATABASE_URL: ${{ matrix.adapter }}
61+
WITH_ADVISORY_LOCK_PREFIX: ${{ github.run_id }}
62+
run: bundle exec rake

.github/workflows/ci-postgresql.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ on:
33
pull_request:
44
branches:
55
- master
6+
concurrency:
7+
group: ci-postgresql-${{ github.head_ref }}
8+
cancel-in-progress: true
9+
610
jobs:
711
minitest:
812
runs-on: ubuntu-latest
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
---
2-
name: CI
2+
name: CI Sqlite3
33

44
on:
55
pull_request:
66
branches:
77
- master
88

9+
concurrency:
10+
group: ci-sqlite3-${{ github.head_ref }}
11+
cancel-in-progress: true
12+
913
jobs:
1014
minitest:
1115
runs-on: ubuntu-latest

lib/with_advisory_lock/database_adapter_support.rb

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,22 @@
22

33
module WithAdvisoryLock
44
class DatabaseAdapterSupport
5-
# Caches nested lock support by MySQL reported version
6-
@@mysql_nl_cache = {}
7-
@@mysql_nl_cache_mutex = Mutex.new
8-
5+
attr_reader :adapter_name
96
def initialize(connection)
107
@connection = connection
11-
@sym_name = connection.adapter_name.downcase.to_sym
8+
@adapter_name = connection.adapter_name.downcase.to_sym
129
end
1310

1411
def mysql?
15-
%i[mysql2 trilogy].include? @sym_name
12+
%i[mysql2 trilogy].include? adapter_name
1613
end
1714

1815
def postgresql?
19-
%i[postgresql empostgresql postgis].include? @sym_name
16+
%i[postgresql empostgresql postgis].include? adapter_name
2017
end
2118

2219
def sqlite?
23-
@sym_name == :sqlite3
20+
[:sqlite3, :sqlite].include? adapter_name
2421
end
2522
end
2623
end

lib/with_advisory_lock/mysql.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

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

0 commit comments

Comments
 (0)