class CassSchema::Runner

Attributes

cluster_builder[R]
datastores[R]
disallow_drops[R]
logger[R]
schema_base_path[R]

Public Class Methods

new(options = {}) click to toggle source

Create a new Runner @option options [Array<CassSchema::Datastore>] :datastores - The list of datastore objects for which schemas

will be managed.

@option options [String] :schema_bath_path - The directory where schema definitions live. In a rails env,

this defaults to <rails root>/cass_schema.

@option options [#info|#error] :logger optional logger to use when creating schemas @option options [Boolean] :disallow_drops Defaults to false. If set to true, drop commands will raise an exception instead of executing the command.

# File lib/cass_schema/runner.rb, line 20
def initialize(options = {})
  options[:schema_base_path] ||= defined?(::Rails) ? File.join(::Rails.root, 'cass_schema') : nil

  @datastores = options[:datastores]
  @schema_base_path = options[:schema_base_path]
  @logger = options[:logger]
  @disallow_drops = options[:disallow_drops]

  raise ":datastores is a required argument!" unless @datastores

  @datastores.each { |ds| ds._setup(options) }
end
setup(options = {}) click to toggle source

(see Runner#initialize)

# File lib/cass_schema/runner.rb, line 76
def setup(options = {})
  @runner = Runner.new(options)
end

Public Instance Methods

create(datastore_name) click to toggle source

Create the schema for a particular datastore @param [String] datastore_name

# File lib/cass_schema/runner.rb, line 46
def create(datastore_name)
  datastore_lookup(datastore_name).create
end
create_all() click to toggle source

Create all schemas for all datastores

# File lib/cass_schema/runner.rb, line 34
def create_all
  datastores.each { |d| d.create }
end
datastore_lookup(datastore_name) click to toggle source

Find a datastore based on the datastore name @param datastore_name [String|Symbol] The datastore name @return [CassSchema::Datastore]

# File lib/cass_schema/runner.rb, line 67
def datastore_lookup(datastore_name)
  @datastore_lookup ||= Hash[datastores.map { |ds| [ds.name, ds] }]
  @datastore_lookup[datastore_name.to_s] || (raise ArgumentError.new("CassSchema datastore #{datastore_name} not found"))
end
drop(datastore_name) click to toggle source

Drop the schema for a particular datastore @param [String] datastore_name

# File lib/cass_schema/runner.rb, line 52
def drop(datastore_name)
  raise DropCommandsNotAllowed if disallow_drops
  datastore_lookup(datastore_name).drop
end
drop_all() click to toggle source

Drop all schemas for all datastores

# File lib/cass_schema/runner.rb, line 39
def drop_all
  raise DropCommandsNotAllowed if disallow_drops
  datastores.each { |d| d.drop }
end
migrate(datastore_name, migration_name) click to toggle source

Run a particular named migration for a datastore @param [String] datastore_name @param [String] migration_name

# File lib/cass_schema/runner.rb, line 60
def migrate(datastore_name, migration_name)
  datastore_lookup(datastore_name).migrate(migration_name)
end