class MonkeyButler::Targets::CassandraTarget
Public Instance Methods
drop()
click to toggle source
# File lib/monkey_butler/targets/cassandra/cassandra_target.rb, line 56 def drop say_status :drop, database_url, :yellow database.drop(keyspaces) end
dump()
click to toggle source
# File lib/monkey_butler/targets/cassandra/cassandra_target.rb, line 18 def dump database_url = (options[:database] && URI(options[:database])) || project.database_url @database = MonkeyButler::Databases::CassandraDatabase.new(database_url) fail Error, "Cannot dump database: the database at '#{database_url}' does not have a `schema_migrations` table." unless database.migrations_table? say "Dumping schema from database '#{database_url}'" say "Dumping keyspaces '#{keyspaces.join(', ')}'..." describe_statements = keyspaces.map { |keyspace| "describe keyspace #{keyspace};" } run "cqlsh -e '#{describe_statements.join(' ')}' #{database_url.host} > #{project.schema_path}" say "Dumping rows from 'schema_migrations'..." with_padding do File.open(project.schema_path, 'a') do |f| f.puts "USE #{keyspace};" database.all_versions.each do |version| f.puts "INSERT INTO schema_migrations(partition_key, version) VALUES (0, #{version});" say "wrote version: #{version}", :green end end end say say "Dump complete. Schema written to #{project.schema_path}." end
init()
click to toggle source
# File lib/monkey_butler/targets/cassandra/cassandra_target.rb, line 6 def init migration_path = "migrations/" + MonkeyButler::Util.migration_named('create_' + options[:name]) + '.cql' template('create_schema_migrations.cql.erb', migration_path) git_add migration_path end
load()
click to toggle source
# File lib/monkey_butler/targets/cassandra/cassandra_target.rb, line 43 def load project = MonkeyButler::Project.load unless File.size?(project.schema_path) raise Error, "Cannot load database: empty schema found at #{project.schema_path}. Maybe you need to `mb migrate`?" end @database = MonkeyButler::Databases::CassandraDatabase.new(database_url) drop run "cqlsh #{database_url.host} -f #{project.schema_path}" say "Loaded schema at version #{database.current_version}" end
new(name)
click to toggle source
# File lib/monkey_butler/targets/cassandra/cassandra_target.rb, line 12 def new(name) migration_path = "migrations/" + MonkeyButler::Util.migration_named(name) + '.cql' template('migration.cql.erb', migration_path) git_add migration_path end
Private Instance Methods
keyspace()
click to toggle source
# File lib/monkey_butler/targets/cassandra/cassandra_target.rb, line 62 def keyspace database_url.path[1..-1] end
keyspaces()
click to toggle source
# File lib/monkey_butler/targets/cassandra/cassandra_target.rb, line 66 def keyspaces keyspaces = (project.config['cassandra.keyspaces'] || []).dup keyspaces.unshift(keyspace) end