Class: Cassie::Schema::StructureDumper Deprecated

Inherits:
Object
  • Object
show all
Defined in:
lib/cassie/schema/structure_dumper.rb

Overview

Deprecated.

Use SchemaDumper instead

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ StructureDumper

Returns a new instance of StructureDumper.



8
9
10
# File 'lib/cassie/schema/structure_dumper.rb', line 8

def initialize(opts={})
  @destination_path = opts[:destination_path] || default_destination_path
end

Instance Attribute Details

#destination_pathObject (readonly)

Returns the value of attribute destination_path.



6
7
8
# File 'lib/cassie/schema/structure_dumper.rb', line 6

def destination_path
  @destination_path
end

Instance Method Details

#dumpObject

Dump the CQL for the current environment’s keyspace, the schema metadata keyspace, and the versions rows that are currently in the schema versions table.



59
60
61
62
63
64
65
66
67
# File 'lib/cassie/schema/structure_dumper.rb', line 59

def dump
  stream << keyspace_structure
  stream << schema_meta_structure
  stream << "\n\n"
  stream << versions_insert_cql
  stream << "\n"

  close_stream
end

#keyspace_structureString

Fetch the CQL that can be used to recreate the current environment’s keyspace

Returns:

  • (String)

    CQL commands

Raises:

  • (RuntimeError)

    if the :keyspace keyspace could not be described.



22
23
24
25
26
27
28
29
30
# File 'lib/cassie/schema/structure_dumper.rb', line 22

def keyspace_structure
  @keyspace_structure ||= begin
    args = ["-e", "'DESCRIBE KEYSPACE #{Cassie.configuration[:keyspace]}'"]
    runner = Cassie::Support::SystemCommand.new("cqlsh", args)
    runner.succeed

    runner.output
  end
end

#schema_meta_structureString

Fetch the CQL that can be used to recreat the schema metadata keyspace, if it has been defined. If it could not be fetched (likely because it doesn’t exist), an empty string is returned.

Returns:

  • (String)

    CQL commands



36
37
38
# File 'lib/cassie/schema/structure_dumper.rb', line 36

def schema_meta_structure
  CreateVersionsTableQuery.new.to_cql
end

#streamObject



12
13
14
15
16
17
# File 'lib/cassie/schema/structure_dumper.rb', line 12

def stream
  @stream ||= begin
    prepare_stream
    File.open(destination_path, "w+")
  end
end

#versionsObject



40
41
42
43
44
45
46
47
# File 'lib/cassie/schema/structure_dumper.rb', line 40

def versions
  @versions ||= begin
    versions_query.fetch
  rescue Cassandra::Errors::InvalidError => e
    log_versions_not_found(e)
    []
  end
end

#versions_insert_cqlObject



49
50
51
52
53
54
# File 'lib/cassie/schema/structure_dumper.rb', line 49

def versions_insert_cql
  inserts = versions.map do |v|
    InsertVersionQuery.new(version: v).to_cql
  end
  inserts.join("\n")
end

#versions_table_nameObject



69
70
71
# File 'lib/cassie/schema/structure_dumper.rb', line 69

def versions_table_name
  "#{Cassie::Schema.schema_keyspace}.#{Cassie::Schema.versions_table}"
end