Permalink
Browse files

Add #schema_names to PostgreSQL Adapter.

  • Loading branch information...
1 parent b4ac72c commit 577971f05a838da3ba74ba49d776a83f6bfe1aee @travisjeffery travisjeffery committed Mar 7, 2012
View
11 activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -978,6 +978,17 @@ def encoding
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
+
# 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
View
4 activerecord/test/cases/adapters/postgresql/schema_test.rb
@@ -71,6 +71,10 @@ def teardown
@connection.execute "DROP SCHEMA #{SCHEMA_NAME} CASCADE"
end
+ def test_schema_names
+ assert_equal ["public", "test_schema", "test_schema2"], @connection.schema_names
+ end
+
def test_schema_change_with_prepared_stmt
altered = false
@connection.exec_query "select * from developers where id = $1", 'sql', [[nil, 1]]

0 comments on commit 577971f

Please sign in to comment.