diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2012-03-07 10:58:55 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2012-03-07 10:58:55 -0800 |
commit | 89cef0757aee00e2b7dc742f155a18c82e3fa915 (patch) | |
tree | 0496f35d1794f170ec804b5f230aa6e8b2b239e4 /activerecord/lib/active_record | |
parent | 3da31b948f0e9af07e503d955f27ffd5d91c84cb (diff) | |
parent | 8dc1a625c87950f4b258b7f6fc1036e08b192daa (diff) | |
download | rails-89cef0757aee00e2b7dc742f155a18c82e3fa915.tar.gz rails-89cef0757aee00e2b7dc742f155a18c82e3fa915.tar.bz2 rails-89cef0757aee00e2b7dc742f155a18c82e3fa915.zip |
Merge pull request #5315 from travisjeffery/enhance_postgresql_adapter_schema_support
Enhance PostgreSQL Adapter schema support
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index d2126a3e19..5b7fa029da 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -978,6 +978,27 @@ module ActiveRecord end_sql end + # Returns an array of schema names. + def schema_names + query(<<-SQL).flatten + SELECT nspname + FROM pg_namespace + WHERE nspname !~ '^pg_.*' + AND nspname NOT IN ('information_schema') + ORDER by nspname; + SQL + end + + # Creates a schema for the given schema name. + def create_schema schema_name + execute "CREATE SCHEMA #{schema_name}" + end + + # Drops the schema for the given schema name. + def drop_schema schema_name + execute "DROP SCHEMA #{schema_name} CASCADE" + end + # Sets the schema search path to a string of comma-separated schema names. # Names beginning with $ have to be quoted (e.g. $user => '$user'). # See: http://www.postgresql.org/docs/current/static/ddl-schemas.html |