Class: Brillo::Loader
- Inherits:
-
Object
- Object
- Brillo::Loader
- Includes:
- Helpers::ExecHelper, Logger
- Defined in:
- lib/brillo/loader.rb
Overview
Responsible for fetching an existing SQL scrub from S3, cleaning the database, and loading the SQL.
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #download_sql(keep_local) ⇒ Object
- #import_sql ⇒ Object
-
#initialize(config) ⇒ Loader
constructor
A new instance of Loader.
- #load!(keep_local) ⇒ Object
- #recreate_db ⇒ Object
Methods included from Logger
Methods included from Helpers::ExecHelper
Constructor Details
#initialize(config) ⇒ Loader
Returns a new instance of Loader.
9 10 11 12 |
# File 'lib/brillo/loader.rb', line 9 def initialize(config) raise "⚠️ DON'T LOAD IN PRODUCTION! ⚠️" if production? @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
7 8 9 |
# File 'lib/brillo/loader.rb', line 7 def config @config end |
Instance Method Details
#download_sql(keep_local) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/brillo/loader.rb', line 20 def download_sql(keep_local) if keep_local path = config.compress ? config.compressed_dump_path : config.dump_path return if File.exists? path end config.transferrer.download end |
#import_sql ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/brillo/loader.rb', line 34 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 |
#load!(keep_local) ⇒ Object
14 15 16 17 18 |
# File 'lib/brillo/loader.rb', line 14 def load!(keep_local) download_sql(keep_local) recreate_db import_sql end |
#recreate_db ⇒ Object
29 30 31 32 |
# File 'lib/brillo/loader.rb', line 29 def recreate_db return unless config.recreate_db config.adapter.recreate_db end |