module CassandraMigrations::Migration::TableOperations
Module grouping methods used in migrations to make table operations like:
-
creating tables
-
dropping tables
Public Instance Methods
alter_table(table_name, options={}) { |table_definition| ... }
click to toggle source
# File lib/cassandra_migrations/migration/table_operations.rb, line 39 def alter_table(table_name, options={}) table_definition = TableDefinition.new table_definition.define_options(options[:options]) if options[:options] yield table_definition if block_given? announce_operation "alter_table #{table_name}" create_cql = "ALTER TABLE #{table_name}" create_cql << table_definition.options announce_suboperation create_cql execute create_cql end
create_index(table_name, column_name, options = {})
click to toggle source
# File lib/cassandra_migrations/migration/table_operations.rb, line 55 def create_index(table_name, column_name, options = {}) announce_operation "create_index(#{table_name})" create_index_cql = "CREATE INDEX #{options[:name]} ON #{table_name} (#{column_name})".squeeze(' ') announce_suboperation create_index_cql execute create_index_cql end
create_table(table_name, options = {}) { |table_definition| ... }
click to toggle source
Creates a new table in the keyspace
options:
-
:primary_keys: single value or array (for compound primary keys). If
not defined, some column must be chosen as primary key in the table definition.
# File lib/cassandra_migrations/migration/table_operations.rb, line 19 def create_table(table_name, options = {}) table_definition = TableDefinition.new table_definition.define_primary_keys(options[:primary_keys]) if options[:primary_keys] table_definition.define_partition_keys(options[:partition_keys]) if options[:partition_keys] table_definition.define_options(options[:options]) if options[:options] yield table_definition if block_given? announce_operation "create_table(#{table_name})" create_cql = "CREATE TABLE #{table_name} (" create_cql << table_definition.to_create_cql create_cql << ")" create_cql << table_definition.options announce_suboperation create_cql execute create_cql end
drop_index(table_or_index_name, column_name = nil, options = {})
click to toggle source
# File lib/cassandra_migrations/migration/table_operations.rb, line 72 def drop_index(table_or_index_name, column_name = nil, options = {}) if column_name index_name = "#{table_or_index_name}_#{column_name}_idx" else index_name = table_or_index_name end drop_index_cql = "DROP INDEX #{options[:if_exists] ? 'IF EXISTS' : ''}#{index_name}" announce_suboperation drop_index_cql execute drop_index_cql end
drop_table(table_name)
click to toggle source
Drops a table
# File lib/cassandra_migrations/migration/table_operations.rb, line 64 def drop_table(table_name) announce_operation "drop_table(#{table_name})" drop_cql = "DROP TABLE #{table_name}" announce_suboperation drop_cql execute drop_cql end