Module: CassandraMigrations::Cassandra::KeyspaceOperations

Included in:
CassandraMigrations::Cassandra
Defined in:
lib/cassandra_migrations/cassandra/keyspace_operations.rb

Instance Method Summary collapse

Instance Method Details

#create_keyspace!(env) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/cassandra_migrations/cassandra/keyspace_operations.rb', line 7

def create_keyspace!(env)
  config = Config.configurations[env]
  begin
    execute(
      "CREATE KEYSPACE #{config.keyspace} \
       WITH replication = { \ 
         'class':'#{config.replication['class']}', \
         'replication_factor': #{config.replication['replication_factor']} \
       }"
    )
    use(config.keyspace)
  rescue Exception => exception
    drop_keyspace!(env)
    raise exception
  end
end

#drop_keyspace!(env) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/cassandra_migrations/cassandra/keyspace_operations.rb', line 24

def drop_keyspace!(env)
  config = Config.configurations[env]
  begin
    execute("DROP KEYSPACE #{config.keyspace}")
  rescue Cql::QueryError
    raise Errors::UnexistingKeyspaceError, config.keyspace
  end
end