Class: Shearwater::CassandraCqlBackend

Inherits:
Object
  • Object
show all
Defined in:
lib/shearwater/cassandra_cql_backend.rb

Instance Method Summary collapse

Constructor Details

#initialize(connection, column_family = 'schema_migrations') ⇒ CassandraCqlBackend

Returns a new instance of CassandraCqlBackend.



5
6
7
# File 'lib/shearwater/cassandra_cql_backend.rb', line 5

def initialize(connection, column_family = 'schema_migrations')
  @connection, @column_family = connection, column_family
end

Instance Method Details

#last_migrationObject



26
27
28
29
30
31
32
33
# File 'lib/shearwater/cassandra_cql_backend.rb', line 26

def last_migration
  rows = []
  execute(
    "SELECT version, migrated_at FROM #{@column_family}"
  ).fetch { |row| rows << row.to_hash }
  row = rows.reject { |row| row['migrated_at'].nil? }.sort { |row1, row2| row1['version'].to_i <=> row2['version'].to_i }.last
  row['version'].to_i if row
end

#migrated!(id) ⇒ Object



9
10
11
12
13
14
# File 'lib/shearwater/cassandra_cql_backend.rb', line 9

def migrated!(id)
  execute(
    "INSERT INTO #{@column_family} (version, migrated_at) VALUES (?, ?)",
    id.to_i, Time.now
  )
end

#migrated?(id) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
# File 'lib/shearwater/cassandra_cql_backend.rb', line 20

def migrated?(id)
  !!execute(
    "SELECT migrated_at FROM #{@column_family} WHERE version = ?", id.to_i
  ).fetch_row.to_hash['migrated_at']
end

#rolled_back!(id) ⇒ Object



16
17
18
# File 'lib/shearwater/cassandra_cql_backend.rb', line 16

def rolled_back!(id)
  execute("DELETE FROM #{@column_family} WHERE version = ?", id.to_i)
end