cassie 1.0.0.beta.33 → 1.0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/cassie +8 -181
- data/lib/cassie/configuration/core.rb +26 -3
- data/lib/cassie/configuration/generator.rb +1 -0
- data/lib/cassie/configuration/loading.rb +5 -2
- data/lib/cassie/configuration.rb +1 -0
- data/lib/cassie/connection.rb +13 -7
- data/lib/cassie/connection_handler/README.md +13 -3
- data/lib/cassie/connection_handler/cluster.rb +11 -0
- data/lib/cassie/connection_handler/sessions.rb +9 -0
- data/lib/cassie/connection_handler.rb +8 -7
- data/lib/cassie/definition.rb +28 -0
- data/lib/cassie/extensions/object/color_methods.rb +21 -0
- data/lib/cassie/instrumentation.rb +4 -0
- data/lib/cassie/modification.rb +29 -0
- data/lib/cassie/query.rb +27 -0
- data/lib/cassie/schema/README.md +306 -0
- data/lib/cassie/schema/apply_command.rb +24 -0
- data/lib/cassie/schema/cassandra_migrations/importer.rb +91 -0
- data/lib/cassie/schema/cassandra_migrations/migration_file.rb +51 -0
- data/lib/cassie/schema/configuration.rb +35 -0
- data/lib/cassie/schema/migration/cassandra_support.rb +34 -0
- data/lib/cassie/schema/migration/dsl/announcing.rb +47 -0
- data/lib/cassie/schema/migration/dsl/column_operations.rb +42 -0
- data/lib/cassie/schema/migration/dsl/table_definition.rb +299 -0
- data/lib/cassie/schema/migration/dsl/table_operations.rb +64 -0
- data/lib/cassie/schema/migration/dsl.rb +17 -0
- data/lib/cassie/schema/migration.rb +12 -0
- data/lib/cassie/schema/migrator.rb +115 -0
- data/lib/cassie/schema/queries/create_keyspace_query.rb +26 -0
- data/lib/cassie/{migration → schema}/queries/create_versions_table_query.rb +6 -6
- data/lib/cassie/schema/queries/delete_version_query.rb +17 -0
- data/lib/cassie/schema/queries/drop_keyspace_query.rb +14 -0
- data/lib/cassie/schema/queries/insert_version_query.rb +22 -0
- data/lib/cassie/schema/queries/select_versions_query.rb +18 -0
- data/lib/cassie/{migration → schema}/queries.rb +4 -2
- data/lib/cassie/schema/rollback_command.rb +24 -0
- data/lib/cassie/schema/structure_dumper.rb +117 -0
- data/lib/cassie/{migration → schema}/structure_loader.rb +3 -3
- data/lib/cassie/schema/version.rb +143 -0
- data/lib/cassie/schema/version_file_loader.rb +34 -0
- data/lib/cassie/schema/version_loader.rb +31 -0
- data/lib/cassie/schema/version_object_loader.rb +19 -0
- data/lib/cassie/schema/version_writer.rb +108 -0
- data/lib/cassie/schema/versioning.rb +162 -0
- data/lib/cassie/schema.rb +24 -0
- data/lib/cassie/statements/README.md +61 -9
- data/lib/cassie/statements/core.rb +16 -5
- data/lib/cassie/statements/execution/results/core.rb +1 -1
- data/lib/cassie/statements/execution/results/modification_result.rb +1 -1
- data/lib/cassie/statements/execution/results/query_result.rb +1 -1
- data/lib/cassie/statements/execution.rb +40 -13
- data/lib/cassie/statements/statement/assignments.rb +33 -3
- data/lib/cassie/statements/statement/conditions.rb +3 -1
- data/lib/cassie/statements/statement/deleting.rb +27 -19
- data/lib/cassie/statements/statement/idempotency.rb +23 -4
- data/lib/cassie/statements/statement/inserting.rb +17 -10
- data/lib/cassie/statements/statement/limiting.rb +5 -2
- data/lib/cassie/statements/statement/mapping.rb +34 -6
- data/lib/cassie/statements/statement/preparation/cache.rb +1 -1
- data/lib/cassie/statements/statement/preparation.rb +37 -7
- data/lib/cassie/statements/statement/relations.rb +29 -8
- data/lib/cassie/statements/statement/selection.rb +51 -15
- data/lib/cassie/statements/statement/type_hinting.rb +12 -4
- data/lib/cassie/statements/statement/updating.rb +22 -8
- data/lib/cassie/statements/statement.rb +39 -14
- data/lib/cassie/statements.rb +12 -0
- data/lib/cassie/support/server_process.rb +117 -0
- data/lib/cassie/support/statement_parser.rb +3 -5
- data/lib/cassie/support/{command_runner.rb → system_command.rb} +22 -13
- data/lib/cassie/support.rb +3 -1
- data/lib/cassie/tasks/configuration/generate.rake +35 -0
- data/lib/cassie/tasks/io.rb +15 -0
- data/lib/cassie/tasks/migration/create.rake +49 -0
- data/lib/cassie/tasks/migration/import.rake +39 -0
- data/lib/cassie/tasks/migration/reset.rake +9 -0
- data/lib/cassie/tasks/restart.rake +5 -0
- data/lib/cassie/tasks/schema/drop.rake +28 -0
- data/lib/cassie/tasks/schema/dump.rake +21 -0
- data/lib/cassie/tasks/schema/history.rake +18 -0
- data/lib/cassie/tasks/schema/import.rake +40 -0
- data/lib/cassie/tasks/schema/init.rake +54 -0
- data/lib/cassie/tasks/schema/load.rake +19 -0
- data/lib/cassie/tasks/schema/migrate.rake +42 -0
- data/lib/cassie/tasks/schema/reset.rake +6 -0
- data/lib/cassie/tasks/schema/status.rake +19 -0
- data/lib/cassie/tasks/schema/version.rake +18 -0
- data/lib/cassie/tasks/schema/version_display.rb +50 -0
- data/lib/cassie/tasks/start.rake +17 -0
- data/lib/cassie/tasks/stop.rake +33 -0
- data/lib/cassie/tasks/tail.rake +14 -0
- data/lib/cassie/tasks/task_runner.rb +49 -0
- data/lib/cassie/tasks.rb +18 -0
- data/lib/cassie/testing/fake/execution_info.rb +1 -1
- data/lib/cassie/testing/fake/result.rb +3 -3
- data/lib/cassie/testing.rb +4 -0
- data/lib/cassie/version.rb +1 -1
- data/lib/cassie.rb +4 -1
- metadata +73 -17
- data/lib/cassie/migration/README.md +0 -141
- data/lib/cassie/migration/configuration.rb +0 -18
- data/lib/cassie/migration/initialization.rb +0 -70
- data/lib/cassie/migration/queries/create_schema_keyspace_query.rb +0 -17
- data/lib/cassie/migration/queries/insert_version_query.rb +0 -23
- data/lib/cassie/migration/queries/select_versions_query.rb +0 -14
- data/lib/cassie/migration/structure_dumper.rb +0 -94
- data/lib/cassie/migration/version.rb +0 -4
- data/lib/cassie/migration.rb +0 -30
@@ -1,6 +1,6 @@
|
|
1
1
|
module Cassie
|
2
2
|
module Support
|
3
|
-
class
|
3
|
+
class SystemCommand
|
4
4
|
attr_reader :binary, :args, :command, :status, :duration, :output
|
5
5
|
|
6
6
|
# When a block is given, the command runs before yielding
|
@@ -17,6 +17,7 @@ module Cassie
|
|
17
17
|
end
|
18
18
|
|
19
19
|
# Runs the command
|
20
|
+
# @return [Boolean] true if execution completed without crashing
|
20
21
|
def run
|
21
22
|
t1=Time.now
|
22
23
|
|
@@ -29,36 +30,38 @@ module Cassie
|
|
29
30
|
completed?
|
30
31
|
end
|
31
32
|
|
32
|
-
# Runs the command,
|
33
|
-
#
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
33
|
+
# Runs the command, expecting an exit status of 0
|
34
|
+
# @return [Boolean] true if execution completed without crashing
|
35
|
+
# @raise [RuntimeError] if program was not run successfully
|
36
|
+
def succeed
|
37
|
+
fail unless run && success?
|
38
|
+
|
38
39
|
true
|
39
40
|
end
|
40
41
|
|
41
|
-
#
|
42
|
+
# @return [Boolean] false if the command hasn't been run yet
|
42
43
|
def run?
|
43
44
|
!!@duration
|
44
45
|
end
|
45
46
|
|
46
|
-
#
|
47
|
+
# Runs the command if it hasn't been run yet.
|
48
|
+
# @return [Fixnum] the exit code for the command.
|
47
49
|
def exitcode
|
48
50
|
status.exitstatus
|
49
51
|
end
|
50
52
|
|
51
|
-
#
|
53
|
+
# @return [Boolean] true if command has been run, and exited with status of 0,
|
54
|
+
# otherwise returns false.
|
52
55
|
def success?
|
53
56
|
return false unless run?
|
54
57
|
exitcode == 0
|
55
58
|
end
|
56
59
|
|
57
|
-
#
|
58
|
-
#
|
60
|
+
# @return [Boolean] true if the command completed execution and success bits were set, regardless of the exit status code.
|
61
|
+
# false if the command hasn't been executed, failed to exit, or crashed.
|
59
62
|
def completed?
|
60
63
|
return false unless run?
|
61
|
-
status.exited? && @status.success?
|
64
|
+
status.exited? && @status.success? #status.success is NOT the exit code == 0!
|
62
65
|
end
|
63
66
|
|
64
67
|
def failure_message
|
@@ -72,6 +75,12 @@ module Cassie
|
|
72
75
|
|
73
76
|
protected
|
74
77
|
|
78
|
+
# raise a Runtime error with a failure message
|
79
|
+
# specific to the command
|
80
|
+
def fail
|
81
|
+
raise RuntimeError.new(failure_message)
|
82
|
+
end
|
83
|
+
|
75
84
|
def red(message)
|
76
85
|
"\e[1m\e[31m#{message}\e[0m\e[22m"
|
77
86
|
end
|
data/lib/cassie/support.rb
CHANGED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
namespace :cassie do
|
4
|
+
namespace :configuration do
|
5
|
+
desc "Generate a sample cassandra configuration file"
|
6
|
+
task :generate do
|
7
|
+
include Cassie::Tasks::IO
|
8
|
+
|
9
|
+
begin
|
10
|
+
opts = {}
|
11
|
+
OptionParser.new do |args|
|
12
|
+
args.on("-p", "--path", "Path to place configuration file. Defaults to './config/cassandra.yml'") do |p|
|
13
|
+
opts[:destination_path] = if path[0] == "/"
|
14
|
+
path
|
15
|
+
else
|
16
|
+
File.join(Dir.pwd, path)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
args.on("-n", "--name", "Application name. Used as prefix for keyspace names. Defaults to 'my_app'") do |n|
|
20
|
+
opts[:app_name] = n
|
21
|
+
end
|
22
|
+
end.parse!(argv)
|
23
|
+
|
24
|
+
puts "-- Generating sample cassie cluster configuration file"
|
25
|
+
generator = Cassie::Configuration::Generator.new(opts)
|
26
|
+
generator.save
|
27
|
+
puts " > #{green("created")} #{generator.destination_path}"
|
28
|
+
puts "-- done"
|
29
|
+
rescue => e
|
30
|
+
puts red("Error:\n #{e.message}")
|
31
|
+
abort
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
namespace :cassie do
|
4
|
+
namespace :migration do
|
5
|
+
desc "Generates an empty migration file prefixed with the next semantic version number"
|
6
|
+
task :create do
|
7
|
+
include Cassie::Tasks::IO
|
8
|
+
|
9
|
+
opts = {}
|
10
|
+
OptionParser.new do |args|
|
11
|
+
args.on("-b", "--build", "Bump build version number") do
|
12
|
+
opts[:bump_type] = :build
|
13
|
+
end
|
14
|
+
args.on("-p", "--patch", "Bump patch version number") do
|
15
|
+
opts[:bump_type] = :patch
|
16
|
+
end
|
17
|
+
args.on("-m", "--minor", "Bump minor version number") do
|
18
|
+
opts[:bump_type] = :minor
|
19
|
+
end
|
20
|
+
args.on("-M", "--major", "Bump major version number") do
|
21
|
+
opts[:bump_type] = :major
|
22
|
+
end
|
23
|
+
args.on("-v", "--version VERSION", "Explicitly set version") do |v|
|
24
|
+
opts[:version] = v
|
25
|
+
end
|
26
|
+
end.parse!(argv)
|
27
|
+
|
28
|
+
begin
|
29
|
+
raise("A migration description is required.\n\nUsage:\n cassie migration:create simple description") if argv.empty?
|
30
|
+
name = argv.join(" ")
|
31
|
+
|
32
|
+
version = Cassie::Schema::Version.new(opts[:version]) if opts[:version]
|
33
|
+
version ||= Cassie::Schema.next_version(opts[:bump_type])
|
34
|
+
version.description = name
|
35
|
+
puts("-- Creating migration file for version #{version.number}")
|
36
|
+
|
37
|
+
writer = Cassie::Schema::VersionWriter.new(version)
|
38
|
+
writer.write
|
39
|
+
rel_path = writer.filename.sub(Dir.pwd, "")
|
40
|
+
puts " > #{green('created')} #{rel_path}"
|
41
|
+
puts "-- done"
|
42
|
+
rescue => e
|
43
|
+
puts red("Error:\n #{e.message}")
|
44
|
+
abort
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'cassie/schema/cassandra_migrations/importer'
|
3
|
+
|
4
|
+
namespace :cassie do
|
5
|
+
namespace :migrations do
|
6
|
+
desc "Imports existing `cassandra_migrations` migration files and converts to semantic versioning"
|
7
|
+
task :import do
|
8
|
+
include Cassie::Tasks::IO
|
9
|
+
|
10
|
+
begin
|
11
|
+
puts "-- Importing `cassandra_migrations` migration files"
|
12
|
+
opts = {}
|
13
|
+
OptionParser.new do |args|
|
14
|
+
args.on("-p", "--path", "Directory containing existing migrations. Defaults to 'db/cassandra_migrate'.") do |p|
|
15
|
+
opts[:path] = p
|
16
|
+
end
|
17
|
+
end.parse!(argv)
|
18
|
+
|
19
|
+
importer = Cassie::Schema::CassandraMigrations::Importer.new(opts[:path])
|
20
|
+
importer.before_each = Proc.new do |migration_file|
|
21
|
+
rel_path = migration_file.filename.sub(Dir.pwd, "")
|
22
|
+
puts " - Importing #{rel_path}"
|
23
|
+
end
|
24
|
+
importer.after_each = Proc.new do |version|
|
25
|
+
rel_path = version.migration.path.sub(Dir.pwd, "")
|
26
|
+
puts " > #{green('created')} #{rel_path}"
|
27
|
+
puts " > #{white('recorded')} version #{version}"
|
28
|
+
puts " - done"
|
29
|
+
end
|
30
|
+
|
31
|
+
importer.import
|
32
|
+
puts "-- done"
|
33
|
+
rescue => e
|
34
|
+
puts red("Error:\n #{e.message}")
|
35
|
+
abort
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
namespace :cassie do
|
2
|
+
namespace :schema do
|
3
|
+
desc "drop default keyspace and schema versioning keyspace"
|
4
|
+
task :drop do
|
5
|
+
include Cassie::Tasks::IO
|
6
|
+
begin
|
7
|
+
query = Cassie::Schema::DropKeyspaceQuery.new
|
8
|
+
keyspaces = [Cassie.configuration[:keyspace], Cassie::Schema.schema_keyspace]
|
9
|
+
|
10
|
+
puts "-- Dropping #{keyspaces.count} keyspaces"
|
11
|
+
keyspaces.each do |keyspace|
|
12
|
+
query.keyspace = keyspace
|
13
|
+
puts " - Dropping '#{keyspace}'"
|
14
|
+
if Cassie.keyspace_exists?(keyspace)
|
15
|
+
query.execute
|
16
|
+
else
|
17
|
+
puts " > '#{keyspace}' does not exist"
|
18
|
+
end
|
19
|
+
puts " - done"
|
20
|
+
end
|
21
|
+
puts "-- done"
|
22
|
+
rescue => e
|
23
|
+
puts red("Error:\n #{e.message}")
|
24
|
+
abort
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
namespace :cassie do
|
2
|
+
namespace :schema do
|
3
|
+
desc "Dumps the schema for all non-system keyspaces in CQL format (`db/cassandra/schema.cql` by default)"
|
4
|
+
task :dump do
|
5
|
+
include Cassie::Tasks::IO
|
6
|
+
|
7
|
+
begin
|
8
|
+
puts "-- Dumping Cassandra schema (version #{Cassie::Schema.version})"
|
9
|
+
dumper = Cassie::Schema::StructureDumper.new
|
10
|
+
puts " - Writing to #{dumper.destination_path}"
|
11
|
+
dumper.dump
|
12
|
+
puts " - done"
|
13
|
+
puts "-- done"
|
14
|
+
|
15
|
+
rescue => e
|
16
|
+
puts red("Error: \n#{e.message}")
|
17
|
+
abort
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require_relative 'version_display'
|
2
|
+
|
3
|
+
namespace :cassie do
|
4
|
+
namespace :schema do
|
5
|
+
desc "Print the history of applied schema migrations"
|
6
|
+
task :history do
|
7
|
+
include Cassie::Tasks::IO
|
8
|
+
include Cassie::Tasks::Schema::VersionDisplay
|
9
|
+
|
10
|
+
begin
|
11
|
+
print_versions(Cassie::Schema.applied_versions)
|
12
|
+
rescue Cassie::Schema::UninitializedError => e
|
13
|
+
puts red("Error:\n #{e.message}")
|
14
|
+
abort
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
namespace :cassie do
|
2
|
+
namespace :schema do
|
3
|
+
desc "Create an initial schema version based on the current schema"
|
4
|
+
task :import => :init do
|
5
|
+
include Cassie::Tasks::IO
|
6
|
+
|
7
|
+
begin
|
8
|
+
version = Cassie::Schema.next_version
|
9
|
+
keyspace = Cassie.configuration[:keyspace]
|
10
|
+
|
11
|
+
puts "-- Importing Schema from Cassandra"
|
12
|
+
|
13
|
+
version.description = "import #{keyspace}"
|
14
|
+
dumper = Cassie::Schema::StructureDumper.new
|
15
|
+
writer = Cassie::Schema::VersionWriter.new(version)
|
16
|
+
contents = dumper.keyspace_structure.gsub(/\n\n/, "")
|
17
|
+
contents = contents.gsub(/(\A\n|\n\z)/, "")
|
18
|
+
writer.up_code = "cql = <<-EOS\n#{contents}\nEOS\n"
|
19
|
+
writer.up_code += " execute(cql)"
|
20
|
+
writer.down_code = "execute('DROP KEYSPACE #{Cassie.configuration[:keyspace]};')"
|
21
|
+
|
22
|
+
puts " - Creating initial version"
|
23
|
+
rel_path = writer.filename.sub(Dir.pwd, "")
|
24
|
+
writer.write
|
25
|
+
puts " > #{green("created")} #{rel_path}"
|
26
|
+
Cassie::Schema.record_version(version)
|
27
|
+
puts " > #{white('recorded')} version #{version}"
|
28
|
+
puts " - done"
|
29
|
+
puts "-- done"
|
30
|
+
rescue => e
|
31
|
+
puts red("Error:\n #{e.message}")
|
32
|
+
abort
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
Rake::Task["cassie:schema:import"].enhance do
|
39
|
+
Rake::Task["cassie:schema:dump"].invoke
|
40
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
namespace :cassie do
|
2
|
+
namespace :schema do
|
3
|
+
|
4
|
+
desc "Initialize versioning schema and the keyspace for this environment"
|
5
|
+
task :init => [:init_versioning, :init_keyspace]
|
6
|
+
|
7
|
+
desc "Initialize cassie schema versioning"
|
8
|
+
task :init_versioning do
|
9
|
+
include Cassie::Tasks::IO
|
10
|
+
|
11
|
+
begin
|
12
|
+
puts "-- Initializing Cassie Versioning"
|
13
|
+
Cassie::Schema.initialize_versioning
|
14
|
+
puts "-- done"
|
15
|
+
rescue Cassie::Schema::AlreadyInitiailizedError
|
16
|
+
puts " > Cassie Versioning already initialized "
|
17
|
+
puts " > Schema is at version #{Cassie::Schema.version}"
|
18
|
+
puts "-- done"
|
19
|
+
rescue => e
|
20
|
+
puts red("Error:\n #{e.message}")
|
21
|
+
abort
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
desc "Initialize the keyspace for the current environment"
|
26
|
+
task :init_keyspace do
|
27
|
+
include Cassie::Tasks::IO
|
28
|
+
Cassie.keyspace = nil
|
29
|
+
|
30
|
+
begin
|
31
|
+
name = Cassie.configuration[:keyspace]
|
32
|
+
puts "-- Initializing '#{name}' Keyspace"
|
33
|
+
query = Cassie::Schema::CreateKeyspaceQuery.new
|
34
|
+
query.name = name
|
35
|
+
if Cassie.configuration[:replication]
|
36
|
+
#@todo fill in
|
37
|
+
end
|
38
|
+
|
39
|
+
if Cassie.keyspace_exists?(query.name)
|
40
|
+
puts " > '#{name}' already exists"
|
41
|
+
else
|
42
|
+
query.execute
|
43
|
+
end
|
44
|
+
puts "-- done"
|
45
|
+
|
46
|
+
rescue => e
|
47
|
+
puts red("Couldn't create keyspace, check #{Cassie.paths[:cluster_configurations]}:\n#{query.to_cql}")
|
48
|
+
puts "\t"
|
49
|
+
puts red("Error:\n #{e.message}")
|
50
|
+
abort
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
namespace :cassie do
|
2
|
+
namespace :schema do
|
3
|
+
desc "Creates the schema by executing the CQL in the schema file (`db/cassandra/schema.cql` by default)"
|
4
|
+
task :load do
|
5
|
+
include Cassie::Tasks::IO
|
6
|
+
|
7
|
+
begin
|
8
|
+
loader = Cassie::Schema::StructureLoader.new
|
9
|
+
puts "-- Loading Schema from #{loader.source_path}"
|
10
|
+
loader.load
|
11
|
+
puts " > Schema is now at version #{Cassie::Schema.version}"
|
12
|
+
puts "-- done"
|
13
|
+
rescue => e
|
14
|
+
puts red("Error:\n #{e.message}")
|
15
|
+
abort
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
namespace :cassie do
|
2
|
+
namespace :schema do
|
3
|
+
desc "Migrates the schema by running the `up` methods for any migrations starting after the current schema version"
|
4
|
+
task :migrate do
|
5
|
+
include Cassie::Tasks::IO
|
6
|
+
|
7
|
+
begin
|
8
|
+
version = argv[0]
|
9
|
+
|
10
|
+
migrator = Cassie::Schema::Migrator.new(version)
|
11
|
+
puts "-- Migrating to version #{migrator.target_version}"
|
12
|
+
|
13
|
+
if migrator.commands.count == 0
|
14
|
+
if migrator.target_version == migrator.current_version
|
15
|
+
puts " > Already at #{migrator.target_version}, nothing to do..."
|
16
|
+
abort
|
17
|
+
else
|
18
|
+
raise "No migration files found to migrate to #{migrator.target_version}, staying at #{migrator.current_version}"
|
19
|
+
end
|
20
|
+
else
|
21
|
+
migrator.before_each = Proc.new do |v, direction|
|
22
|
+
puts " - Migragting version #{v} #{direction.upcase}"
|
23
|
+
end
|
24
|
+
migrator.after_each = Proc.new do |_migration, duration|
|
25
|
+
puts " - done (#{duration} ms)"
|
26
|
+
end
|
27
|
+
migrator.migrate
|
28
|
+
puts "-- done"
|
29
|
+
end
|
30
|
+
rescue => e
|
31
|
+
puts red("Error:\n #{e.message}")
|
32
|
+
abort
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
desc "alias for schema:migrate"
|
37
|
+
task :migrate => "schema:migrate"
|
38
|
+
end
|
39
|
+
|
40
|
+
Rake::Task["cassie:schema:migrate"].enhance do
|
41
|
+
Rake::Task["cassie:schema:dump"].invoke
|
42
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative 'version_display'
|
2
|
+
|
3
|
+
namespace :cassie do
|
4
|
+
namespace :schema do
|
5
|
+
desc "Prints the migration status of all schema migrations, local and applied"
|
6
|
+
task :status do
|
7
|
+
include Cassie::Tasks::IO
|
8
|
+
include Cassie::Tasks::Schema::VersionDisplay
|
9
|
+
|
10
|
+
begin
|
11
|
+
all_versions = Cassie::Schema.applied_versions.to_a | Cassie::Schema.local_versions.to_a
|
12
|
+
print_statuses(all_versions.sort.reverse)
|
13
|
+
rescue Cassie::Schema::UninitializedError => e
|
14
|
+
puts red("Error:\n #{e.message}")
|
15
|
+
abort
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require_relative 'version_display'
|
2
|
+
|
3
|
+
namespace :cassie do
|
4
|
+
namespace :schema do
|
5
|
+
desc "Print the history of applied schema migrations"
|
6
|
+
task :version do
|
7
|
+
include Cassie::Tasks::IO
|
8
|
+
include Cassie::Tasks::Schema::VersionDisplay
|
9
|
+
|
10
|
+
begin
|
11
|
+
print_versions([Cassie::Schema.version])
|
12
|
+
rescue Cassie::Schema::UninitializedError => e
|
13
|
+
puts red("Error:\n#{e.message}")
|
14
|
+
abort
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'terminal-table'
|
2
|
+
|
3
|
+
module Cassie::Tasks
|
4
|
+
module Schema
|
5
|
+
module VersionDisplay
|
6
|
+
# Prints an ASCII table represenation of the versions
|
7
|
+
# to STDOUT in the order given with column headers.
|
8
|
+
def print_versions(versions)
|
9
|
+
# Note: if we end up using this elsewhere, move to Version::VersionList
|
10
|
+
# or something simliar, and have version collection methods return that
|
11
|
+
members = [:number, :description, :executor, :executed_at]
|
12
|
+
titles = ['Number', 'Description', 'Migrated by', 'Migrated at']
|
13
|
+
table = Terminal::Table.new(headings: titles)
|
14
|
+
current_version = Cassie::Schema.version
|
15
|
+
|
16
|
+
versions.each.with_index do |v|
|
17
|
+
row = v.to_h.values_at(*members)
|
18
|
+
row[0] = "* #{row[0]}" if v == current_version
|
19
|
+
table.add_row(row)
|
20
|
+
end
|
21
|
+
|
22
|
+
table.align_column(0, :right)
|
23
|
+
puts table
|
24
|
+
end
|
25
|
+
|
26
|
+
def print_statuses(versions)
|
27
|
+
# Note: if we end up using this elsewhere, move to Version::VersionList
|
28
|
+
# or something simliar, and have version collection methods return that
|
29
|
+
members = [:number, :description]
|
30
|
+
titles = ['Number', 'Description', 'Status', 'Migration File']
|
31
|
+
table = Terminal::Table.new(headings: titles)
|
32
|
+
current_version = Cassie::Schema.version
|
33
|
+
|
34
|
+
versions.each.with_index do |v|
|
35
|
+
row = []
|
36
|
+
row << v.number
|
37
|
+
row[0] = "* #{row[0]}" if v == current_version
|
38
|
+
row << v.description
|
39
|
+
row << (v.recorded? ? "UP" : "DOWN")
|
40
|
+
row << (v.migration.try(:path) || red("File Not Found")).gsub("#{Dir.pwd}/", "")
|
41
|
+
table.add_row(row)
|
42
|
+
end
|
43
|
+
|
44
|
+
table.align_column(0, :right)
|
45
|
+
table.align_column(2, :center)
|
46
|
+
puts table
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
namespace :cassie do
|
2
|
+
desc "Start the cassandra server process in the background with reduced verbosity"
|
3
|
+
task :start do
|
4
|
+
include Cassie::Tasks::IO
|
5
|
+
|
6
|
+
puts("Starting Cassandra...")
|
7
|
+
process = Cassie::Support::ServerProcess.new
|
8
|
+
|
9
|
+
if process.running?
|
10
|
+
puts "[#{green('✓')}] Cassandra Running"
|
11
|
+
else
|
12
|
+
process.errors.each{|e| puts red(" " + e.gsub("; nested exception is:", "")) }
|
13
|
+
puts "[#{red('✘')}] Cassandra Failed to Start"
|
14
|
+
abort
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
namespace :cassie do
|
2
|
+
desc "Stop the cassandra server process."
|
3
|
+
task :stop do
|
4
|
+
include Cassie::Tasks::IO
|
5
|
+
|
6
|
+
opts = {}
|
7
|
+
OptionParser.new do |args|
|
8
|
+
args.on("-a", "--all", "Stop all cassandra processes, not just the server (e.g. cqlsh). Defaults to false.") do |a|
|
9
|
+
opts[:kill_all] = a || false
|
10
|
+
end
|
11
|
+
end.parse!(argv)
|
12
|
+
|
13
|
+
procs = Cassie::Support::ServerProcess.all
|
14
|
+
|
15
|
+
if procs.empty?
|
16
|
+
puts red("No Cassandra process was found. Is Cassandra running?")
|
17
|
+
abort
|
18
|
+
end
|
19
|
+
|
20
|
+
if procs.length > 1 && !opts[:kill_all]
|
21
|
+
puts red("Couldn't single out a Cassandra process.")
|
22
|
+
puts red(" - Is cqlsh running?")
|
23
|
+
puts red(" - Kill all cassandra processes with --all")
|
24
|
+
abort
|
25
|
+
else
|
26
|
+
puts("Stopping Cassandra...")
|
27
|
+
procs.each do |process|
|
28
|
+
process.stop
|
29
|
+
end
|
30
|
+
puts "[#{green('✓')}] Cassandra Stopped"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
namespace :cassie do
|
2
|
+
desc "Tail the cassandra server logs"
|
3
|
+
task :tail do
|
4
|
+
include Cassie::Tasks::IO
|
5
|
+
|
6
|
+
log_path = Cassie::Support::ServerProcess.log_path
|
7
|
+
puts white("Tailing Cassandra system log, Ctrl-C to stop...")
|
8
|
+
puts " #{log_path}:\n\n"
|
9
|
+
|
10
|
+
args = ['-f', log_path, '>', '/dev/tty']
|
11
|
+
tail = Cassie::Support::SystemCommand.new("tail", args)
|
12
|
+
tail.run
|
13
|
+
end
|
14
|
+
end
|