aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-05-14 22:19:37 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-05-14 22:19:37 -0300
commit095c42efcb03dc11dd038a73daefe39d545e14a9 (patch)
tree14d44afc2f296b632de3fd86b57ccc9ff53a9043 /activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
parenta11e2fcff8cdc9691b977d8330abe63024f8c732 (diff)
parentc0bfc3f412834ffe8327a15ae3a46602cc28e425 (diff)
downloadrails-095c42efcb03dc11dd038a73daefe39d545e14a9.tar.gz
rails-095c42efcb03dc11dd038a73daefe39d545e14a9.tar.bz2
rails-095c42efcb03dc11dd038a73daefe39d545e14a9.zip
Merge pull request #15088 from kares/shareable-modules
[postgres] remove (outer) sub-class declarations with nested modules/classes
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb')
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb26
1 files changed, 20 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
index 5bf4c7afd6..ea35b16dcd 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
@@ -1,6 +1,6 @@
module ActiveRecord
module ConnectionAdapters
- class PostgreSQLAdapter < AbstractAdapter
+ module PostgreSQL
class SchemaCreation < AbstractAdapter::SchemaCreation
private
@@ -33,10 +33,6 @@ module ActiveRecord
end
end
- def schema_creation
- SchemaCreation.new self
- end
-
module SchemaStatements
# Drops the database specified on the +name+ attribute
# and creates it again using the provided +options+.
@@ -101,7 +97,7 @@ module ActiveRecord
# If the schema is not specified as part of +name+ then it will only find tables within
# the current schema search path (regardless of permissions to access tables in other schemas)
def table_exists?(name)
- schema, table = Utils.extract_schema_and_table(name.to_s)
+ schema, table = extract_schema_and_table(name.to_s)
return false unless table
exec_query(<<-SQL, 'SCHEMA').rows.first[0].to_i > 0
@@ -492,6 +488,24 @@ module ActiveRecord
[super, *order_columns].join(', ')
end
+
+ private
+
+ # Returns an array of <tt>[schema_name, table_name]</tt> extracted from +name+.
+ # +schema_name+ is nil if not specified in +name+.
+ # +schema_name+ and +table_name+ exclude surrounding quotes (regardless of whether provided in +name+)
+ # +name+ supports the range of schema/table references understood by PostgreSQL, for example:
+ #
+ # * <tt>table_name</tt>
+ # * <tt>"table.name"</tt>
+ # * <tt>schema_name.table_name</tt>
+ # * <tt>schema_name."table.name"</tt>
+ # * <tt>"schema.name"."table name"</tt>
+ def extract_schema_and_table(name)
+ table, schema = name.scan(/[^".\s]+|"[^"]*"/)[0..1].collect{|m| m.gsub(/(^"|"$)/,'') }.reverse
+ [schema, table]
+ end
+
end
end
end