class ROM::Cassandra::Migrations::Migration
Base class for migrations, responcible for sending queries to the session
@example Migration
can be created in OOP-style
class CreateAuthUsers < ROM::Cassandra::Migration def up call keyspace(:auth).create.if_not_exists call keyspace(:auth) .table(:users) .create(:id, :int) .add(:name, :text) .primary_key(:id) .if_not_exists end def down call keyspace(:auth).drop.if_exists end end
@example The same migration in CQL style
class CreateAuthUsers < ROM::Cassandra::Migration def up call "CREATE KEYSPACE IF NOT EXISTS auth;" call( "CREATE TABLE auth.users (id int, name text, PRIMARY KEY (text));" ) end def down call "DROM KEYSPACE IF EXISTS auth;" end end
Attributes
session[R]
@!attribute [r] session
@return [ROM::Cassandra::Session] the session to send queries to
Public Class Methods
inherited(klass)
click to toggle source
Makes all helper methods private
@private
# File lib/rom/cassandra/migrations/migration.rb, line 46 def self.inherited(klass) klass.__send__(:private, :call, :keyspace, :up, :down) end
new(session)
click to toggle source
Initializes migration with session to the Cassandra
cluster
@param [ROM::Cassandra::Session] session
# File lib/rom/cassandra/migrations/migration.rb, line 54 def initialize(session) @session = session @builder = Query.new end
Public Instance Methods
call(query)
click to toggle source
Sends the query to Cassandra
cluster
@param [#to_s] query
@return [Array]
# File lib/rom/cassandra/migrations/migration.rb, line 89 def call(query) session.call query.to_s end
down()
click to toggle source
By default does nothing
@return [undefined]
@abstract
# File lib/rom/cassandra/migrations/migration.rb, line 80 def down end
keyspace(name)
click to toggle source
Starts building the CQL query in the context of some keyspace
@param [#to_s] name
@return [ROM::Cassandra::Query]
# File lib/rom/cassandra/migrations/migration.rb, line 99 def keyspace(name) @builder.keyspace(name) end
up()
click to toggle source
By default does nothing
@return [undefined]
@abstract
# File lib/rom/cassandra/migrations/migration.rb, line 71 def up end