diff options
author | Rizwan Reza <rizwanreza@gmail.com> | 2010-03-28 11:01:15 +0430 |
---|---|---|
committer | Rizwan Reza <rizwanreza@gmail.com> | 2010-03-28 11:01:15 +0430 |
commit | 6c2a0675f11a9b5b8e88ed7dbccd65cb51be8029 (patch) | |
tree | ed5ab51c378a43303e8e7f07ed01345857d0df7d /activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb | |
parent | 8398f21880a952769ccd6437a4344922fe596dab (diff) | |
download | rails-6c2a0675f11a9b5b8e88ed7dbccd65cb51be8029.tar.gz rails-6c2a0675f11a9b5b8e88ed7dbccd65cb51be8029.tar.bz2 rails-6c2a0675f11a9b5b8e88ed7dbccd65cb51be8029.zip |
When creating database with rake, create schemas in schema_search_path if it doesn't exist.
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb')
-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 c9a5f00dfd..8f71c7e144 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -651,6 +651,27 @@ module ActiveRecord end end + # Creates a schema for the given user + # + # Example: + # create_schema('products', 'postgres') + def create_schema(schema_name, pg_username) + execute("CREATE SCHEMA \"#{schema_name}\" AUTHORIZATION \"#{pg_username}\"") + end + + # Drops a schema + # + # Example: + # drop_schema('products', 'postgres') + def drop_schema(schema_name) + execute("DROP SCHEMA \"#{schema_name}\"") + end + + # Returns an array of all schemas in the database + def all_schemas + query('SELECT schema_name FROM information_schema.schemata').flatten + end + # Returns the list of all tables in the schema search path or a specified schema. def tables(name = nil) query(<<-SQL, name).map { |row| row[0] } |