Class: MigrationBundler::Targets::CassandraTarget
- Inherits:
-
Base
- Object
- Thor
- Base
- MigrationBundler::Targets::CassandraTarget
show all
- Defined in:
- lib/migration_bundler/targets/cassandra/cassandra_target.rb
Instance Method Summary
collapse
Methods inherited from Base
#generate, name, #push, register_with_cli, source_root, #validate
Methods included from Actions
#bundle, #git, #git_add, #truncate_database, #unique_tag_for_version
Instance Method Details
#drop ⇒ Object
57
58
59
60
|
# File 'lib/migration_bundler/targets/cassandra/cassandra_target.rb', line 57
def drop
say_status :drop, database_url, :yellow
database.drop(keyspaces)
end
|
#dump ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/migration_bundler/targets/cassandra/cassandra_target.rb', line 18
def dump
database_url = (options[:database] && URI(options[:database])) || project.database_url
@database = MigrationBundler::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}"
File.open(project.schema_path, 'a') do |f|
f.puts "USE #{keyspace};"
project.config['db.dump_tables'].each do |table_name|
say "Dumping rows from '#{table_name}'..."
with_padding do
row_statements = database.dump_rows(table_name)
f.puts row_statements.join("\n")
say "wrote #{row_statements.size} rows.", :green
end
end
say
end
say "Dump complete. Schema written to #{project.schema_path}."
end
|
#init ⇒ Object
6
7
8
9
10
|
# File 'lib/migration_bundler/targets/cassandra/cassandra_target.rb', line 6
def init
migration_path = "migrations/" + MigrationBundler::Util.migration_named('create_' + options[:name]) + '.cql'
template('create_schema_migrations.cql.erb', migration_path)
git_add migration_path
end
|
#load ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/migration_bundler/targets/cassandra/cassandra_target.rb', line 44
def load
project = MigrationBundler::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 = MigrationBundler::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) ⇒ Object
12
13
14
15
16
|
# File 'lib/migration_bundler/targets/cassandra/cassandra_target.rb', line 12
def new(name)
migration_path = "migrations/" + MigrationBundler::Util.migration_named(name) + '.cql'
template('migration.cql.erb', migration_path)
git_add migration_path
end
|