From ecdc7ebc1b8aa52126dcb1ad22e787e114cfe14f Mon Sep 17 00:00:00 2001 From: Colton Jenkins Date: Thu, 11 Jul 2024 22:57:52 -0400 Subject: [PATCH] Fetch last value from sequence given currval may not be defined for the session (#103) --- lib/database_cleaner/active_record/truncation.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/database_cleaner/active_record/truncation.rb b/lib/database_cleaner/active_record/truncation.rb index bbdd64f..a3758e6 100644 --- a/lib/database_cleaner/active_record/truncation.rb +++ b/lib/database_cleaner/active_record/truncation.rb @@ -224,7 +224,7 @@ def database_cleaner_table_cache def has_been_used?(table) return has_rows?(table) unless has_sequence?(table) - cur_val = select_value("SELECT currval('#{table}_id_seq');").to_i rescue 0 + cur_val = select_value("SELECT last_value from #{table}_id_seq;").to_i cur_val > 0 end