File tree Expand file tree Collapse file tree 3 files changed +15
-10
lines changed Expand file tree Collapse file tree 3 files changed +15
-10
lines changed Original file line number Diff line number Diff line change 1
- .PHONY : test-pg test-mysql
1
+ .PHONY : test-sqlite test-pg test-mysql
2
+
3
+ test-sqlite :
4
+ appraisal rake test
2
5
3
6
test-pg :
4
7
docker compose up -d pg
5
8
sleep 10 # give some time for the service to start
6
- DATABASE_URL=postgres://with_advisory:with_advisory_pass@localhost/with_advisory_lock_test appraisal activerecord-7.1 rake test
9
+ DATABASE_URL=postgres://with_advisory:with_advisory_pass@localhost/with_advisory_lock_test appraisal rake test
7
10
8
11
test-mysql :
9
12
docker compose up -d mysql
10
13
sleep 10 # give some time for the service to start
11
- DATABASE_URL=mysql2://with_advisory:
[email protected] :3306/with_advisory_lock_test appraisal
activerecord-7.1 rake
test
14
+ DATABASE_URL=mysql2://with_advisory:
[email protected] :3306/with_advisory_lock_test appraisal rake
test
12
15
13
16
14
- test : test-pg test-mysql
17
+ test : test-sqlite test- pg test-mysql
Original file line number Diff line number Diff line change 1
- # frozen_string_literal: true
1
+ c # frozen_string_literal: true
2
2
3
3
module WithAdvisoryLock
4
4
class DatabaseAdapterSupport
5
5
attr_reader :adapter_name
6
+
6
7
def initialize ( connection )
7
8
@connection = connection
8
- @adapter_name = connection . adapter_name . downcase . to_sym
9
+ @adapter_name = connection . adapter_name . downcase . to_sym
9
10
end
10
11
11
12
def mysql?
@@ -17,7 +18,7 @@ def postgresql?
17
18
end
18
19
19
20
def sqlite?
20
- [ : sqlite3, : sqlite] . include? adapter_name
21
+ %i[ sqlite3 sqlite ] . include? adapter_name
21
22
end
22
23
end
23
24
end
Original file line number Diff line number Diff line change @@ -5,7 +5,8 @@ class MySQL < Base
5
5
# Caches nested lock support by MySQL reported version
6
6
@@mysql_nl_cache = { }
7
7
@@mysql_nl_cache_mutex = Mutex . new
8
- # See https://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_get-lock
8
+ # See https://dev.mysql.com/doc/refman/5.7/en/locking-functions.html
9
+ # See https://dev.mysql.com/doc/refman/8.0/en/locking-functions.html
9
10
def try_lock
10
11
raise ArgumentError , 'shared locks are not supported on MySQL' if shared
11
12
raise ArgumentError , 'transaction level locks are not supported on MySQL' if transaction
@@ -18,8 +19,8 @@ def release_lock
18
19
end
19
20
20
21
def execute_successful? ( mysql_function )
21
- sql = "SELECT #{ mysql_function } AS #{ unique_column_name } "
22
- connection . select_value ( sql ) . to_i . positive?
22
+ sql = "SELECT #{ mysql_function } "
23
+ connection . query_value ( sql ) == 1
23
24
end
24
25
25
26
# MySQL wants a string as the lock key.
You can’t perform that action at this time.
0 commit comments