Class: ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
- Inherits:
-
AbstractAdapter
- Object
- AbstractAdapter
- ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
- Defined in:
- lib/pg_schema/postgresql_adapter.rb
Instance Method Summary collapse
-
#all_schemas ⇒ Object
Returns an array of all schemas in the database.
-
#create_schema(schema_name, pg_username) ⇒ Object
Example: create_schema(‘products’, ‘postgres’).
-
#drop_schema(schema_name) ⇒ Object
Drops a schema.
Instance Method Details
#all_schemas ⇒ Object
Returns an array of all schemas in the database
17 18 19 |
# File 'lib/pg_schema/postgresql_adapter.rb', line 17 def all_schemas query('SELECT schema_name FROM information_schema.schemata').flatten end |
#create_schema(schema_name, pg_username) ⇒ Object
Example:
create_schema('products', 'postgres')
4 5 6 |
# File 'lib/pg_schema/postgresql_adapter.rb', line 4 def create_schema(schema_name, pg_username) execute("CREATE SCHEMA \"#{schema_name}\" AUTHORIZATION \"#{pg_username}\"") end |
#drop_schema(schema_name) ⇒ Object
Drops a schema
Example:
drop_schema('products', 'postgres')
12 13 14 |
# File 'lib/pg_schema/postgresql_adapter.rb', line 12 def drop_schema(schema_name) execute("DROP SCHEMA \"#{schema_name}\"") end |