Class: CassandraMigrations::Migration
- Inherits:
-
Object
- Object
- CassandraMigrations::Migration
- Includes:
- ColumnOperations, TableOperations
- Defined in:
- lib/cassandra_migrations/migration.rb,
lib/cassandra_migrations/migration/table_definition.rb,
lib/cassandra_migrations/migration/table_operations.rb,
lib/cassandra_migrations/migration/column_operations.rb
Overview
Base class for all cassandra migration
Defined Under Namespace
Modules: ColumnOperations, TableOperations Classes: TableDefinition
Class Method Summary collapse
-
.method_missing(name, *args, &block) ⇒ Object
Delegate missing method calls to an instance.
Instance Method Summary collapse
-
#down ⇒ Object
Makes
downwork if the method in the migration is defined with self.down. -
#migrate(direction) ⇒ Object
Execute this migration in the named direction.
-
#up ⇒ Object
Makes
upwork if the method in the migration is defined with self.up.
Methods included from ColumnOperations
Methods included from TableOperations
#create_index, #create_table, #drop_index, #drop_table
Class Method Details
.method_missing(name, *args, &block) ⇒ Object
Delegate missing method calls to an instance. That’s what enables the writing of migrations using both def up and def self.up sintax.
38 39 40 41 42 43 44 |
# File 'lib/cassandra_migrations/migration.rb', line 38 def self.method_missing(name, *args, &block) if instance_to_delegate instance_to_delegate.send(name, *args, &block) else super end end |
Instance Method Details
#down ⇒ Object
Makes down work if the method in the migration is defined with self.down
25 26 27 28 29 |
# File 'lib/cassandra_migrations/migration.rb', line 25 def down return unless self.class.respond_to?(:down) self.class.instance_to_delegate = self self.class.down end |
#migrate(direction) ⇒ Object
Execute this migration in the named direction.
The advantage of using this instead of directly calling up or down is that this method gives informative output and benchmarks the time taken.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/cassandra_migrations/migration.rb', line 50 def migrate(direction) return unless respond_to?(direction) case direction when :up then announce_migration "migrating" when :down then announce_migration "reverting" end time = Benchmark.measure { send(direction) } case direction when :up then announce_migration "migrated (%.4fs)" % time.real; puts when :down then announce_migration "reverted (%.4fs)" % time.real; puts end end |
#up ⇒ Object
Makes up work if the method in the migration is defined with self.up
18 19 20 21 22 |
# File 'lib/cassandra_migrations/migration.rb', line 18 def up return unless self.class.respond_to?(:up) self.class.instance_to_delegate = self self.class.up end |