-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
51 lines (38 loc) · 1.46 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
43
44
45
46
47
48
49
50
require "bundler/gem_tasks"
require "rspec/core/rake_task"
RSpec::Core::RakeTask.new(:spec)
task :default => :spec
namespace :db do
desc 'Init cassandra keyspace and model'
task :keyspace do
require 'colorize'
require 'highline'
require './lib/running_tracker_cassandra_database'
begin
cli = HighLine.new
convert = -> (str) { str =~ /^y$/i }
message = "Are you trying to create the keyspace for cassandra ? (y / n)"
agree = cli.ask(message, convert) { |q| q.validate = /^(y|n)$/i }
if agree
cluster = cli.ask('Cluster: ') { |q| q.default = "127.0.0.1" }
keyspace = cli.ask('keyspace: ') { |q| q.default = "running_tracker" }
cluster = { hosts: [cluster] }
puts 'Connecting...'.blue
session = RunningTrackerCassandraDatabase.connect({ 'cluster' => cluster })
puts 'Running keyspace construction...'.blue
RunningTrackerCassandraDatabase.construct_keyspace!(session)
puts 'Keyspace constructed successfully'.green
puts 'Connecting to keyspace...'.blue
session = RunningTrackerCassandraDatabase.connect({ 'cluster' => cluster, 'keyspace' => keyspace })
puts 'Running models construction...'.blue
RunningTrackerCassandraDatabase.construct_models!(session)
puts 'Done!!'.green
else
puts 'Bye'.green
end
rescue => e
puts "ERROR: #{e.inspect}".red
puts "In: #{e.backtrace.join("\n ")}"
end
end
end