Class: ROM::Cassandra::Migrations::Runner Private
- Inherits:
-
Object
- Object
- ROM::Cassandra::Migrations::Runner
- 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
Instance Attribute Summary collapse
-
#logger ⇒ ::Logger
readonly
private
The logger to report results.
-
#migration ⇒ ROM::Cassandra::Migrations::Migration
readonly
private
The migration class.
-
#path ⇒ String
readonly
private
The path to the migration file.
-
#session ⇒ ROM::Cassandra::Session
readonly
private
The session for sending requests to Cassandra.
-
#version ⇒ Integer
readonly
private
The number of migration.
Class Method Summary collapse
-
.apply(session, logger, path) ⇒ undefined
private
Applies the runner to session, logger and migration path.
Instance Method Summary collapse
-
#call ⇒ undefined
private
Runs the sequence of commands to provide migration.
-
#initialize(session, logger, path) ⇒ Runner
constructor
private
Initializes the runner for the session, logger and migration path.
-
#select_version ⇒ Array<Hash>
private
Prepares the table and selects version.
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
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.
31 32 33 |
# File 'lib/rom/cassandra/migrations/runner.rb', line 31 def logger @logger end |
#migration ⇒ ROM::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.
50 51 52 |
# File 'lib/rom/cassandra/migrations/runner.rb', line 50 def migration @migration end |
#path ⇒ String (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.
43 44 45 |
# File 'lib/rom/cassandra/migrations/runner.rb', line 43 def path @path end |
#session ⇒ ROM::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.
25 26 27 |
# File 'lib/rom/cassandra/migrations/runner.rb', line 25 def session @session end |
#version ⇒ Integer (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.
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
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
#call ⇒ 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.
Runs the sequence of commands to provide migration
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_version ⇒ Array<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
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 |