Sha256: fc1af0091dfddaffdf84840a537a624a6c0d15b22e003463b64efc8b09555ec2

Contents?: true

Size: 960 Bytes

Versions: 3

Compression:

Stored size: 960 Bytes

Contents

module Storey
  class SqlDumper

    easy_class_to_instance

    def initialize(options={})
      @file = options[:file] || File.join(Rails.root, "db", "structure.sql")
    end

    def dump
      stdout_str, stderr_str, status = Open3.capture3(command)
      raise "Error dumping database: #{stderr_str}" if status.exitstatus != 0
    end

    private

    def abcs
      @abcs ||= ::ActiveRecord::Base.configurations.with_indifferent_access[Rails.env]
    end

    def search_path
      @search_path ||= abcs[:schema_search_path]
    end

    def database_name
      @database_name ||= Shellwords.escape(abcs[:database])
    end

    def command
      return @command if defined?(@command)
      args = Storey.database_config.slice(:host, :username, :password).merge(
        structure_only: true,
        file: @file,
        schemas: search_path,
        database: database_name,
      )
      @command = BuildsDumpCommand.execute(args)
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
storey-2.0.2 lib/storey/sql_dumper.rb
storey-2.0.1 lib/storey/sql_dumper.rb
storey-2.0.0 lib/storey/sql_dumper.rb