Module: DataMapper::Adapters::PostgresAdapter::Migration
- Includes:
- SQL
- Included in:
- DataMapper::Adapters::PostgresAdapter
- Defined in:
- lib/gems/dm-core-0.9.9/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/gems/dm-core-0.9.9/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/gems/dm-core-0.9.9/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)
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/gems/dm-core-0.9.9/lib/dm-core/adapters/postgres_adapter.rb', line 32 def field_exists?(storage_name, column_name) statement = " SELECT COUNT(*)\n FROM \"pg_class\"\n JOIN \"pg_attribute\" ON \"pg_class\".\"oid\" = \"pg_attribute\".\"attrelid\"\n WHERE \"pg_attribute\".\"attname\" = ?\n AND \"pg_class\".\"relname\" = ?\n AND \"pg_attribute\".\"attnum\" >= 0\n EOS\n\n query(statement, column_name, storage_name).first > 0\nend\n".compress_lines |
#storage_exists?(storage_name) ⇒ Boolean
TODO: move to dm-more/dm-migrations (if possible)
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/gems/dm-core-0.9.9/lib/dm-core/adapters/postgres_adapter.rb', line 20 def storage_exists?(storage_name) statement = " SELECT COUNT(*)\n FROM \"information_schema\".\"columns\"\n WHERE \"table_name\" = ?\n AND \"table_schema\" = current_schema()\n EOS\n\n query(statement, storage_name).first > 0\nend\n".compress_lines |
#upgrade_model_storage(repository, model) ⇒ Object
TODO: move to dm-more/dm-migrations
46 47 48 49 |
# File 'lib/gems/dm-core-0.9.9/lib/dm-core/adapters/postgres_adapter.rb', line 46 def upgrade_model_storage(repository, model) add_sequences(repository, model) super end |