Module: Cassie::Schema::Migration::DSL::ColumnOperations
- Defined in:
- lib/cassie/schema/migration/dsl/column_operations.rb
Overview
Module grouping methods used in migrations to make table operations like:
-
adding/removing columns
-
changing column types
-
renaming columns
Instance Method Summary collapse
-
#add_column(table_name, column_name, type, options = {}) ⇒ Object
Adds a column to a table.
-
#remove_column(table_name, column_name) ⇒ Object
Removes a column from the table.
Instance Method Details
#add_column(table_name, column_name, type, options = {}) ⇒ Object
Adds a column to a table.
options: same options you would pass to create a table with that column (i.e. :limit might be applicable)
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/cassie/schema/migration/dsl/column_operations.rb', line 14 def add_column(table_name, column_name, type, = {}) table_definition = TableDefinition.new if !table_definition.respond_to?(type) raise Errors::MigrationDefinitionError("Type '#{type}' is not valid for cassandra migration.") end table_definition.send(type, column_name, ) announce_operation "add_column(#{column_name}, #{type})" cql = "ALTER TABLE #{table_name} ADD " cql << table_definition.to_add_column_cql announce_suboperation cql execute cql end |
#remove_column(table_name, column_name) ⇒ Object
Removes a column from the table
33 34 35 36 37 38 39 40 |
# File 'lib/cassie/schema/migration/dsl/column_operations.rb', line 33 def remove_column(table_name, column_name) announce_operation "drop_table(#{table_name})" cql = "ALTER TABLE #{table_name} DROP #{column_name}" announce_suboperation cql execute cql end |