Class: Cassie::Schema::SchemaDumper

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ SchemaDumper

Returns a new instance of SchemaDumper.



12
13
14
15
# File 'lib/cassie/schema/schema_dumper.rb', line 12

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

Instance Attribute Details

#destination_pathObject (readonly)

The location to dump the ruby file



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

def destination_path
  @destination_path
end

#keyspaceObject (readonly)

The keyspace that will be extracted and replaced with #{default_keyspace} upon dumping



10
11
12
# File 'lib/cassie/schema/schema_dumper.rb', line 10

def keyspace
  @keyspace
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.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/cassie/schema/schema_dumper.rb', line 28

def dump
  stream << "# This file describes the keyspace-agnostic schema\n# for this application's environments.\n#\n# It is the definitive source of the current state\n# of the schema and should not be modified directly.\n#\n# It is strongly recommened that this schema file be checked into source control.\n#\n# Use `cassie` commands to apply this schema to a particular environment:\n# * Load this schema with `cassie schema:load`\n# * Reset the schema to this definition with `cassie schema:reset`\nCassie::Schema.define do\n\n"
  stream << "  create_schema <<-EOS\n"
  stream << "#{keyspace_agnostic_cql}\n"
  stream << "EOS\n"
  stream << "\n\n"
  versions.each do |v|
    stream << "  record_version #{version_arg_str(v)}\n"
  end
  stream << "end\n"

  close_stream
end

#streamObject

The stream to dump the source to



18
19
20
21
22
23
# File 'lib/cassie/schema/schema_dumper.rb', line 18

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

#versions_table_nameObject



56
57
58
# File 'lib/cassie/schema/schema_dumper.rb', line 56

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