Sha256: cfcce6b5eded20a5ba4c5e6ade266d089636d1b0722e621026985ae85d766dda

Contents?: true

Size: 924 Bytes

Versions: 18

Compression:

Stored size: 924 Bytes

Contents

module Superstore
  module Tasks
    def dump(io)
      table_names.each do |column_family|
        io.puts run_command("DESCRIBE COLUMNFAMILY #{column_family}")
        io.puts
      end
    end

    def load(io)
      current_cql = ''

      io.each_line do |line|
        next if line.blank?

        current_cql << line.rstrip

        if current_cql =~ /;$/
          keyspace_execute current_cql
          current_cql = ''
        end
      end
    end

    def table_names
      run_command('DESCRIBE COLUMNFAMILIES').split.sort
    end

    private

      def run_command(command)
        `echo "#{command};" | #{cqlsh} -2 -k #{keyspace} #{server}`.sub(/^(.*)$/, '').strip
      end

      def cqlsh
        ENV['CQLSH'] || 'cqlsh'
      end

      def keyspace
        Superstore::Base.config[:keyspace]
      end

      def server
        Superstore::Base.adapter.servers.first.gsub(/:.*/, '')
      end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
superstore-1.2.0 lib/superstore/cassandra_schema/tasks.rb
superstore-1.1.4 lib/superstore/cassandra_schema/tasks.rb
superstore-1.1.3 lib/superstore/cassandra_schema/tasks.rb
superstore-1.1.2 lib/superstore/cassandra_schema/tasks.rb
superstore-1.1.1 lib/superstore/cassandra_schema/tasks.rb
superstore-1.1.0 lib/superstore/cassandra_schema/tasks.rb
superstore-1.0.12 lib/superstore/cassandra_schema/tasks.rb
superstore-1.0.11 lib/superstore/cassandra_schema/tasks.rb
superstore-1.0.10 lib/superstore/cassandra_schema/tasks.rb
superstore-1.0.9 lib/superstore/cassandra_schema/tasks.rb
superstore-1.0.8 lib/superstore/cassandra_schema/tasks.rb
superstore-1.0.7 lib/superstore/cassandra_schema/tasks.rb
superstore-1.0.6 lib/superstore/cassandra_schema/tasks.rb
superstore-1.0.5 lib/superstore/cassandra_schema/tasks.rb
superstore-1.0.4 lib/superstore/cassandra_schema/tasks.rb
superstore-1.0.3 lib/superstore/cassandra_schema/tasks.rb
superstore-1.0.2 lib/superstore/cassandra_schema/tasks.rb
superstore-1.0.0 lib/superstore/cassandra_schema/tasks.rb