From 85914939fc029c061dffbc8698fce897e08a9abc Mon Sep 17 00:00:00 2001 From: Dan Kubb Date: Tue, 20 Jan 2009 23:53:27 -0800 Subject: [PATCH] Fixed bug due to incorrect information_schema query for postgres --- lib/dm-core/adapters/postgres_adapter.rb | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/dm-core/adapters/postgres_adapter.rb b/lib/dm-core/adapters/postgres_adapter.rb index f4c51726..96f318bb 100644 --- a/lib/dm-core/adapters/postgres_adapter.rb +++ b/lib/dm-core/adapters/postgres_adapter.rb @@ -18,27 +18,28 @@ def supports_returning? module Migration # TODO: move to dm-more/dm-migrations (if possible) def storage_exists?(storage_name) - statement = <<-EOS.compress_lines + statement = <<-SQL.compress_lines SELECT COUNT(*) - FROM "information_schema"."columns" - WHERE "table_name" = ? + FROM "information_schema"."tables" + WHERE "table_type" = 'BASE TABLE' AND "table_schema" = current_schema() - EOS + AND "table_name" = ? + SQL query(statement, storage_name).first > 0 end # TODO: move to dm-more/dm-migrations (if possible) def field_exists?(storage_name, column_name) - statement = <<-EOS.compress_lines + statement = <<-SQL.compress_lines SELECT COUNT(*) FROM "information_schema"."columns" - WHERE "table_name" = ? + WHERE "table_schema" = current_schema() + AND "table_name" = ? AND "column_name" = ? - AND "table_schema" = current_schema() - EOS + SQL - query(statement, column_name, storage_name).first > 0 + query(statement, storage_name, column_name).first > 0 end # TODO: move to dm-more/dm-migrations