Module: DataMapper::Adapters::PostgresAdapter::Migration
- Includes:
- SQL
- Included in:
- DataMapper::Adapters::PostgresAdapter
- Defined in:
- lib/dm-core/adapters/postgres_adapter.rb
Overview
TODO: move to dm-more/dm-migrations (if possible)
Defined Under Namespace
Modules: ClassMethods, SQL
Instance Method Summary collapse
-
#create_model_storage(repository, model) ⇒ Object
TODO: move to dm-more/dm-migrations.
-
#destroy_model_storage(repository, model) ⇒ Object
TODO: move to dm-more/dm-migrations.
-
#field_exists?(storage_name, column_name) ⇒ Boolean
TODO: move to dm-more/dm-migrations (if possible).
-
#storage_exists?(storage_name) ⇒ Boolean
TODO: move to dm-more/dm-migrations (if possible).
-
#upgrade_model_storage(repository, model) ⇒ Object
TODO: move to dm-more/dm-migrations.
Instance Method Details
#create_model_storage(repository, model) ⇒ Object
TODO: move to dm-more/dm-migrations
52 53 54 55 |
# File 'lib/dm-core/adapters/postgres_adapter.rb', line 52 def create_model_storage(repository, model) add_sequences(repository, model) without_notices { super } end |
#destroy_model_storage(repository, model) ⇒ Object
TODO: move to dm-more/dm-migrations
58 59 60 61 62 63 64 65 |
# File 'lib/dm-core/adapters/postgres_adapter.rb', line 58 def destroy_model_storage(repository, model) return true unless storage_exists?(model.storage_name(repository.name)) success = without_notices { super } model.properties(repository.name).each do |property| drop_sequence(repository, property) if property.serial? end success end |
#field_exists?(storage_name, column_name) ⇒ Boolean
TODO: move to dm-more/dm-migrations (if possible)
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/dm-core/adapters/postgres_adapter.rb', line 33 def field_exists?(storage_name, column_name) statement = <<-SQL.compress_lines SELECT COUNT(*) FROM "information_schema"."columns" WHERE "table_schema" = current_schema() AND "table_name" = ? AND "column_name" = ? SQL query(statement, storage_name, column_name).first > 0 end |
#storage_exists?(storage_name) ⇒ Boolean
TODO: move to dm-more/dm-migrations (if possible)
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/dm-core/adapters/postgres_adapter.rb', line 20 def storage_exists?(storage_name) statement = <<-SQL.compress_lines SELECT COUNT(*) FROM "information_schema"."tables" WHERE "table_type" = 'BASE TABLE' AND "table_schema" = current_schema() AND "table_name" = ? SQL query(statement, storage_name).first > 0 end |
#upgrade_model_storage(repository, model) ⇒ Object
TODO: move to dm-more/dm-migrations
46 47 48 49 |
# File 'lib/dm-core/adapters/postgres_adapter.rb', line 46 def upgrade_model_storage(repository, model) add_sequences(repository, model) super end |