Class: Cassie::Schema::StructureDumper Deprecated
- Defined in:
- lib/cassie/schema/structure_dumper.rb
Overview
Use SchemaDumper instead
Instance Attribute Summary collapse
-
#destination_path ⇒ Object
readonly
Returns the value of attribute destination_path.
Instance Method Summary collapse
-
#dump ⇒ Object
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.
-
#initialize(opts = {}) ⇒ StructureDumper
constructor
A new instance of StructureDumper.
-
#keyspace_structure ⇒ String
Fetch the CQL that can be used to recreate the current environment’s keyspace.
-
#schema_meta_structure ⇒ String
Fetch the CQL that can be used to recreat the schema metadata keyspace, if it has been defined.
- #stream ⇒ Object
- #versions ⇒ Object
- #versions_insert_cql ⇒ Object
- #versions_table_name ⇒ Object
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_path ⇒ Object (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
#dump ⇒ Object
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 << stream << "\n\n" stream << versions_insert_cql stream << "\n" close_stream end |
#keyspace_structure ⇒ String
Fetch the CQL that can be used to recreate the current environment’s keyspace
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_structure ⇒ String
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.
36 37 38 |
# File 'lib/cassie/schema/structure_dumper.rb', line 36 def CreateVersionsTableQuery.new.to_cql end |
#stream ⇒ Object
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 |
#versions ⇒ Object
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_cql ⇒ Object
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_name ⇒ Object
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 |