@@ -10,17 +10,50 @@ def self.included(base)
10
10
unless method_defined? ( :tables_with_views_included )
11
11
base . alias_method_chain :tables , :views_included
12
12
else
13
- alias_method :tables , :tables_with_views_included
13
+ alias_method :tables , :tables_with_views_included # still doesn't run the right one, grump
14
14
end
15
-
15
+ base . alias_method_chain :table_exists? , :views_included
16
+
16
17
puts method_defined? ( :tables_without_views_included )
17
18
puts base . method_defined? ( :tables_without_views_included )
19
+ puts method_defined? ( :table_exists_without_views_included? )
20
+ puts base . method_defined? ( :table_exists_without_views_included? )
18
21
end
22
+
23
+
19
24
# Returns true as this adapter supports views.
20
25
def supports_views?
21
26
true
22
27
end
23
28
29
+ def table_exists_with_views_included? ( name )
30
+ puts "\n my postgres table_exists?" , "name #{ name } "
31
+ name = name . to_s
32
+ schema , table = name . split ( '.' , 2 )
33
+ unless table # A table was provided without a schema
34
+ table = schema
35
+ schema = nil
36
+ end
37
+ if name =~ /^"/ # Handle quoted table names
38
+ table = name
39
+ schema = nil
40
+ end
41
+ puts "schema #{ schema } " , "table #{ table } "
42
+
43
+ query ( <<-SQL ) . first [ 0 ] . to_i > 0
44
+ SELECT COUNT(*)
45
+ FROM (
46
+ select schemaname, tablename as itemname
47
+ from pg_tables
48
+ union
49
+ select schemaname, viewname
50
+ from pg_views
51
+ ) combo
52
+ WHERE itemname = '#{ table . gsub ( /(^"|"$)/ , '' ) } '
53
+ #{ schema ? "AND schemaname = '#{ schema } '" : '' }
54
+ SQL
55
+ end
56
+
24
57
def tables_with_views_included ( name = nil )
25
58
puts "\n my postgres tables"
26
59
q = <<-SQL
0 commit comments