Skip to content

A platform for community discussion. Free, open, simple.

DEV: Small API changes for interacting with PG during migrations (#32976)

Gerhard Schlager233c54b7fc1b
diff --git a/migrations/lib/database/adapter/postgres.rb b/migrations/lib/database/adapter/postgres.rb
index 314cd037c64..b1e64b41c2f 100644
--- a/migrations/lib/database/adapter/postgres.rb
+++ b/migrations/lib/database/adapter/postgres.rb
@@ -27,16 +27,20 @@ module Migrations::Database::Adapter
end
end
- def query_first(sql)
+ def query_first_row(sql)
@connection.exec(sql).first
end
- def query_value(sql, column)
- query_first(sql)[column]
+ def query_value(sql, column = nil)
+ if (row = query_first_row(sql))
+ column ? row[column.to_sym] : row.values.first
+ else
+ nil
+ end
end
def count(sql)
- query_first(sql).values.first.to_i
+ query_value(sql).to_i
end
def close