From 672f6a5a88db52803df4618aacbb9149e5b35172 Mon Sep 17 00:00:00 2001 From: Sahil Gadimbayli Date: Tue, 1 Sep 2020 13:07:35 +0200 Subject: [PATCH] Use quoted table/primary key names in Lockable - Adds quoted_table_name and quoted_primary_key in joins_advisory_lock scope to enable queries in multi schema setups when table name contains "schema"."table_name" format --- lib/good_job/lockable.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/good_job/lockable.rb b/lib/good_job/lockable.rb index 45269d6c9..f4fd1aced 100644 --- a/lib/good_job/lockable.rb +++ b/lib/good_job/lockable.rb @@ -25,8 +25,8 @@ module Lockable join_sql = <<~SQL LEFT JOIN pg_locks ON pg_locks.locktype = 'advisory' AND pg_locks.objsubid = 1 - AND pg_locks.classid = ('x'||substr(md5(:table_name || "#{table_name}"."#{primary_key}"::text), 1, 16))::bit(32)::int - AND pg_locks.objid = (('x'||substr(md5(:table_name || "#{table_name}"."#{primary_key}"::text), 1, 16))::bit(64) << 32)::bit(32)::int + AND pg_locks.classid = ('x'||substr(md5(:table_name || #{quoted_table_name}.#{quoted_primary_key}::text), 1, 16))::bit(32)::int + AND pg_locks.objid = (('x'||substr(md5(:table_name || #{quoted_table_name}.#{quoted_primary_key}::text), 1, 16))::bit(64) << 32)::bit(32)::int SQL joins(sanitize_sql_for_conditions([join_sql, { table_name: table_name }]))