Class: ROM::Cassandra::Migrations::Runner Private

Inherits:
Object
  • Object
show all
Defined in:
lib/rom/cassandra/migrations/runner.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Base class that loads and runs the migration, registers it in the Cassandra ‘rom.migrations’ table, and logs the result.

As a base class uses the Command pattern to define a sequence of actions, that should be implemented by the subclasses: ‘RunnerUp`, and `RunnderDown`.

Direct Known Subclasses

RunnerDown, RunnerUp

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(session, logger, path) ⇒ Runner

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initializes the runner for the session, logger and migration path

Parameters:



68
69
70
71
72
73
74
# File 'lib/rom/cassandra/migrations/runner.rb', line 68

def initialize(session, logger, path)
  @session   = session
  @logger    = logger
  @path      = path
  @version   = extract_version
  @migration = extract_migration if migrate? # defined in a subclass
end

Instance Attribute Details

#logger::Logger (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns The logger to report results.

Returns:

  • (::Logger)

    The logger to report results



31
32
33
# File 'lib/rom/cassandra/migrations/runner.rb', line 31

def logger
  @logger
end

#migrationROM::Cassandra::Migrations::Migration (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns The migration class.

Returns:



50
51
52
# File 'lib/rom/cassandra/migrations/runner.rb', line 50

def migration
  @migration
end

#pathString (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns The path to the migration file.

Returns:

  • (String)

    The path to the migration file



43
44
45
# File 'lib/rom/cassandra/migrations/runner.rb', line 43

def path
  @path
end

#sessionROM::Cassandra::Session (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns The session for sending requests to Cassandra.

Returns:



25
26
27
# File 'lib/rom/cassandra/migrations/runner.rb', line 25

def session
  @session
end

#versionInteger (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns The number of migration.

Returns:

  • (Integer)

    The number of migration



37
38
39
# File 'lib/rom/cassandra/migrations/runner.rb', line 37

def version
  @version
end

Class Method Details

.apply(session, logger, path) ⇒ undefined

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Applies the runner to session, logger and migration path

Parameters:

Returns:

  • (undefined)


58
59
60
# File 'lib/rom/cassandra/migrations/runner.rb', line 58

def self.apply(session, logger, path)
  new(session, logger, path).call
end

Instance Method Details

#callundefined

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Runs the sequence of commands to provide migration

Returns:

  • (undefined)


80
81
82
83
84
85
# File 'lib/rom/cassandra/migrations/runner.rb', line 80

def call
  return unless migration
  apply    # defined in a subclass
  register # defined in a subclass
  log      # defined in a subclass
end

#select_versionArray<Hash>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Prepares the table and selects version

Returns:

  • (Array<Hash>)

    list of rows with the selected version



91
92
93
94
95
96
97
98
# File 'lib/rom/cassandra/migrations/runner.rb', line 91

def select_version
  session.call "CREATE KEYSPACE IF NOT EXISTS rom WITH" \
    " REPLICATION = {'class': 'SimpleStrategy', 'replication_factor': 3};"
  session.call "CREATE TABLE IF NOT EXISTS rom.migrations" \
    " (version text, PRIMARY KEY (version));"
  session.call "SELECT * FROM rom.migrations WHERE" \
    " version = '#{version}';"
end