Sha256: a33a5af8d81c52b7e35a7aecc4a66719b3e96da0b75db4862d0271f00917dd89

Contents?: true

Size: 1 KB

Versions: 10

Compression:

Stored size: 1 KB

Contents

module Brillo
  # Responsible for fetching an existing SQL scrub from S3, cleaning the database,
  # and loading the SQL.
  class Loader
    include Helpers::ExecHelper
    include Logger
    attr_reader :config

    def initialize(config)
      raise "⚠️ DON'T LOAD IN PRODUCTION! ⚠️" if production?
      @config = config
    end

    def load!
      config.transferrer.download
      recreate_db
      import_sql
    end

    def recreate_db
      ["db:drop", "db:create"].each do |t|
        logger.info "Running\n\trake #{t}"
        Rake::Task[t].invoke
      end
    end

    def import_sql
      if config.compress
        execute!("gunzip -c #{config.compressed_dump_path} | #{sql_load_command}")
      else
        execute!("cat #{config.dump_path} | #{sql_load_command}")
      end
      logger.info "Import complete!"
    end

    private

    def production?
      (ENV['RAILS_ENV'] || ENV['RUBY_ENV']) == 'production'
    end

    def sql_load_command
      config.adapter.load_command
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
brillo-1.2.2 lib/brillo/loader.rb
brillo-1.2.1 lib/brillo/loader.rb
brillo-1.2.0 lib/brillo/loader.rb
brillo-1.1.4 lib/brillo/loader.rb
brillo-1.1.4.pre2 lib/brillo/loader.rb
brillo-1.1.4.pre1 lib/brillo/loader.rb
brillo-1.1.3 lib/brillo/loader.rb
brillo-1.1.2 lib/brillo/loader.rb
brillo-1.1.1 lib/brillo/loader.rb
brillo-1.1.0 lib/brillo/loader.rb