diff options
author | Yves Senn <yves.senn@gmail.com> | 2015-08-28 15:56:49 +0200 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2015-08-28 15:59:37 +0200 |
commit | 35df925b475f2f9fc593c4a1caf5009e5c970b0d (patch) | |
tree | 1b892c080c2e2041d741e1345fdd54ecd8066583 /activerecord/lib | |
parent | 7a27de2bb055ea35c4396ac818d20b0e5aa44ab4 (diff) | |
download | rails-35df925b475f2f9fc593c4a1caf5009e5c970b0d.tar.gz rails-35df925b475f2f9fc593c4a1caf5009e5c970b0d.tar.bz2 rails-35df925b475f2f9fc593c4a1caf5009e5c970b0d.zip |
pg, `create_schema`, `drop_schema` and `rename_table` quote schema name.
Closes #21418.
Previously schema names were not quoted. This leads to issues when a
schema names contains a ".". Methods in `schema_statements.rb` should
quote user input.
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb | 5 | ||||
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb | 6 |
2 files changed, 8 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb b/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb index f175730551..d5879ea7df 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb @@ -31,6 +31,11 @@ module ActiveRecord Utils.extract_schema_qualified_name(name.to_s).quoted end + # Quotes schema names for use in SQL queries. + def quote_schema_name(name) + PGconn.quote_ident(name) + end + def quote_table_name_for_assignment(table, attr) quote_column_name(attr) end 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 21268b63b1..a3fc8fbc51 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb @@ -210,12 +210,12 @@ module ActiveRecord # Creates a schema for the given schema name. def create_schema schema_name - execute "CREATE SCHEMA #{schema_name}" + execute "CREATE SCHEMA #{quote_schema_name(schema_name)}" end # Drops the schema for the given schema name. def drop_schema(schema_name, options = {}) - execute "DROP SCHEMA#{' IF EXISTS' if options[:if_exists]} #{schema_name} CASCADE" + execute "DROP SCHEMA#{' IF EXISTS' if options[:if_exists]} #{quote_schema_name(schema_name)} CASCADE" end # Sets the schema search path to a string of comma-separated schema names. @@ -376,7 +376,7 @@ module ActiveRecord new_seq = "#{new_name}_#{pk}_seq" idx = "#{table_name}_pkey" new_idx = "#{new_name}_pkey" - execute "ALTER TABLE #{quote_table_name(seq)} RENAME TO #{quote_table_name(new_seq)}" + execute "ALTER TABLE #{seq.quoted} RENAME TO #{quote_table_name(new_seq)}" execute "ALTER INDEX #{quote_table_name(idx)} RENAME TO #{quote_table_name(new_idx)}" end |