Class: ROM::Cassandra::Migrations::Migrator
- Inherits:
-
Object
- Object
- ROM::Cassandra::Migrations::Migrator
- Defined in:
- lib/rom/cassandra/migrations/migrator.rb
Overview
Class Migrator finds the migration files and migrates Cassandra cluster to the required version using method [#apply].
The class is responcible for searching files and deciding, which of them should be runned up and down. Every single migration is applied or rolled back using `RunnerUp` and `RunnerDown` classes.
Instance Attribute Summary collapse
-
#logger ⇒ ::Logger
readonly
The logger used by the migrator.
-
#paths ⇒ Array<String>
readonly
The list of paths to migration files.
-
#root ⇒ Array<String>
readonly
The root path for migrations.
-
#session ⇒ ROM::Cassandra::Session
readonly
The session to the Cassandra cluster.
Instance Method Summary collapse
-
#apply(options = {}) ⇒ undefined
Migrates the Cassandra cluster to selected version.
-
#initialize(session, options = {}) ⇒ Migrator
constructor
Initializes a migrator with Cassandra uri settings.
Constructor Details
#initialize(session, options = {}) ⇒ Migrator
Initializes a migrator with Cassandra uri settings.
Can specify logger and path as well.
See [ROM::Cassandra::Session] for other avaliable options for URI
62 63 64 65 66 67 |
# File 'lib/rom/cassandra/migrations/migrator.rb', line 62 def initialize(session, = {}) @session = session @logger = .fetch(:logger) { Logger.new } @root = .fetch(:path) { DEFAULT_PATH } @paths = Dir[File.join(root, "*.rb")].sort end |
Instance Attribute Details
#logger ⇒ ::Logger (readonly)
Returns The logger used by the migrator.
38 39 40 |
# File 'lib/rom/cassandra/migrations/migrator.rb', line 38 def logger @logger end |
#paths ⇒ Array<String> (readonly)
Returns The list of paths to migration files.
50 51 52 |
# File 'lib/rom/cassandra/migrations/migrator.rb', line 50 def paths @paths end |
#root ⇒ Array<String> (readonly)
Returns The root path for migrations.
44 45 46 |
# File 'lib/rom/cassandra/migrations/migrator.rb', line 44 def root @root end |
#session ⇒ ROM::Cassandra::Session (readonly)
Returns The session to the Cassandra cluster.
32 33 34 |
# File 'lib/rom/cassandra/migrations/migrator.rb', line 32 def session @session end |
Instance Method Details
#apply(options = {}) ⇒ undefined
Migrates the Cassandra cluster to selected version
Applies all migrations if a version is skipped. Rolls all migrations back if a version is set to 0.
78 79 80 81 82 83 |
# File 'lib/rom/cassandra/migrations/migrator.rb', line 78 def apply( = {}) version = .fetch(:version) { ALL_VERSIONS } migrate_to version rollback_to version end |