From 6d65887587851f8be442c36b4354d8c790139628 Mon Sep 17 00:00:00 2001 From: Brian Schroer Date: Wed, 28 Jan 2026 19:27:58 -0800 Subject: [PATCH 1/2] Fix import staging script The import staging script was choking on the bookmarks table due to it having a column named "order", which is a reserved keyword in pgsql. This PR enhances our staging_importer#fast_insert method by quoting table name and column name and thus preventing this from happening with other reserved words. --- lib/sheltertech/db/staging_importer.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/sheltertech/db/staging_importer.rb b/lib/sheltertech/db/staging_importer.rb index 19cbe8f2..2530e92e 100644 --- a/lib/sheltertech/db/staging_importer.rb +++ b/lib/sheltertech/db/staging_importer.rb @@ -201,14 +201,17 @@ def self.compute_seconds_left(stats) # queries. def self.fast_insert!(table_name, record) keys = record.keys + conn = ActiveRecord::Base.connection values = keys.map { |k| record[k] } - question_marks = Array.new(values.size) { '?' } + quoted_table = conn.quote_table_name(table_name) + quoted_keys = keys.map { |k| conn.quote_column_name(k) } + question_marks = Array.new(values.size, '?') sql_query = [ - "INSERT INTO #{table_name} (#{keys.join(', ')}) VALUES (#{question_marks.join(', ')})" + "INSERT INTO #{quoted_table} (#{quoted_keys.join(', ')}) VALUES (#{question_marks.join(', ')})" ] sql_query += values sql_query = ActiveRecord::Base.send(:sanitize_sql_array, sql_query) - ActiveRecord::Base.connection.execute(sql_query) + conn.execute(sql_query) end def self.log_progress(msg) From 9073993e16dc29ab870a516b336ee641c2874223 Mon Sep 17 00:00:00 2001 From: Brian Schroer Date: Wed, 28 Jan 2026 19:53:23 -0800 Subject: [PATCH 2/2] Fix lint issue --- lib/sheltertech/db/staging_importer.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/sheltertech/db/staging_importer.rb b/lib/sheltertech/db/staging_importer.rb index 2530e92e..165ab739 100644 --- a/lib/sheltertech/db/staging_importer.rb +++ b/lib/sheltertech/db/staging_importer.rb @@ -206,9 +206,7 @@ def self.fast_insert!(table_name, record) quoted_table = conn.quote_table_name(table_name) quoted_keys = keys.map { |k| conn.quote_column_name(k) } question_marks = Array.new(values.size, '?') - sql_query = [ - "INSERT INTO #{quoted_table} (#{quoted_keys.join(', ')}) VALUES (#{question_marks.join(', ')})" - ] + sql_query = ["INSERT INTO #{quoted_table} (#{quoted_keys.join(', ')}) VALUES (#{question_marks.join(', ')})"] sql_query += values sql_query = ActiveRecord::Base.send(:sanitize_sql_array, sql_query) conn.execute(sql_query)