Module: PgSaurus::ConnectionAdapters::PostgreSQLAdapter::SchemaMethods
- Included in:
- PgSaurus::ConnectionAdapters::PostgreSQLAdapter
- Defined in:
- lib/pg_saurus/connection_adapters/postgresql_adapter/schema_methods.rb
Overview
Provides methods to extend ActiveRecord::ConnectionAdapters::PostgreSQLAdapter to support schemas feature.
Instance Method Summary collapse
-
#create_schema(schema_name) ⇒ Object
Creates new schema in DB.
-
#create_schema_if_not_exists(schema_name) ⇒ Object
Create schema if it does not exist yet.
-
#drop_schema(schema_name) ⇒ Object
Drops schema in DB.
-
#drop_schema_if_exists(schema_name) ⇒ Object
Drop schema if it exists.
-
#move_table_to_schema(table, schema) ⇒ Object
Move table to another schema.
-
#tables_with_non_public_schema_tables(*args) ⇒ Array<String>
Make method
tablesreturn tables not only from public schema.
Instance Method Details
#create_schema(schema_name) ⇒ Object
Creates new schema in DB.
6 7 8 |
# File 'lib/pg_saurus/connection_adapters/postgresql_adapter/schema_methods.rb', line 6 def create_schema(schema_name) ::PgSaurus::Tools.create_schema(schema_name) end |
#create_schema_if_not_exists(schema_name) ⇒ Object
Create schema if it does not exist yet.
26 27 28 |
# File 'lib/pg_saurus/connection_adapters/postgresql_adapter/schema_methods.rb', line 26 def create_schema_if_not_exists(schema_name) ::PgSaurus::Tools.create_schema_if_not_exists(schema_name) end |
#drop_schema(schema_name) ⇒ Object
Drops schema in DB.
12 13 14 |
# File 'lib/pg_saurus/connection_adapters/postgresql_adapter/schema_methods.rb', line 12 def drop_schema(schema_name) ::PgSaurus::Tools.drop_schema(schema_name) end |
#drop_schema_if_exists(schema_name) ⇒ Object
Drop schema if it exists.
33 34 35 |
# File 'lib/pg_saurus/connection_adapters/postgresql_adapter/schema_methods.rb', line 33 def drop_schema_if_exists(schema_name) ::PgSaurus::Tools.drop_schema_if_exists(schema_name) end |
#move_table_to_schema(table, schema) ⇒ Object
Move table to another schema
19 20 21 |
# File 'lib/pg_saurus/connection_adapters/postgresql_adapter/schema_methods.rb', line 19 def move_table_to_schema(table, schema) ::PgSaurus::Tools.move_table_to_schema(table, schema) end |
#tables_with_non_public_schema_tables(*args) ⇒ Array<String>
Note:
Tables from public schema have no “public.” prefix. It’s done for compatibility with other libraries that relies on a table name. Tables from other schemas has appropriate prefix with schema name. See: github.com/TMXCredit/pg_power/pull/42
Make method tables return tables not only from public schema.
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/pg_saurus/connection_adapters/postgresql_adapter/schema_methods.rb', line 46 def tables_with_non_public_schema_tables(*args) public_tables = tables_without_non_public_schema_tables(*args) non_public_tables = query(<<-SQL, 'SCHEMA').map { |row| row[0] } SELECT schemaname || '.' || tablename AS table FROM pg_tables WHERE schemaname NOT IN ('pg_catalog', 'information_schema', 'public') SQL public_tables + non_public_tables end |