Module: Cassie::Schema::Migration::DSL::TableOperations
- Defined in:
- lib/cassie/schema/migration/dsl/table_operations.rb
Overview
Module grouping methods used in migrations to make table operations like:
-
creating tables
-
dropping tables
Instance Method Summary collapse
- #create_index(table_name, column_name, options = {}) ⇒ Object
-
#create_table(table_name, options = {}) {|table_definition| ... } ⇒ Object
Creates a new table in the keyspace.
- #drop_index(table_or_index_name, column_name = nil, options = {}) ⇒ Object
-
#drop_table(table_name) ⇒ Object
Drops a table.
Instance Method Details
#create_index(table_name, column_name, options = {}) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/cassie/schema/migration/dsl/table_operations.rb', line 35 def create_index(table_name, column_name, = {}) 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| ... } ⇒ Object
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.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/cassie/schema/migration/dsl/table_operations.rb', line 15 def create_table(table_name, = {}) table_definition = TableDefinition.new table_definition.define_primary_keys([:primary_keys]) if [:primary_keys] table_definition.define_partition_keys([:partition_keys]) if [:partition_keys] table_definition.([:options]) if [: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. announce_suboperation create_cql execute create_cql end |
#drop_index(table_or_index_name, column_name = nil, options = {}) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/cassie/schema/migration/dsl/table_operations.rb', line 52 def drop_index(table_or_index_name, column_name = nil, = {}) 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) ⇒ Object
Drops a table
44 45 46 47 48 49 50 |
# File 'lib/cassie/schema/migration/dsl/table_operations.rb', line 44 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 |