Class: Duple::CLI::Refresh

Inherits:
Thor::Group
  • Object
show all
Includes:
Helpers
Defined in:
lib/duple/cli/refresh.rb

Overview

Usage:

duple refresh

Options:

-c, [--config=CONFIG]         # The location of the config file.
-s, [--source=SOURCE]         # The name of the source environment.
-t, [--target=TARGET]         # The name of the target environment.
-g, [--group=GROUP]           # The group configuration to use when dumping source data.
    [--capture]               # Capture a new source snapshot before refreshing.
-t, [--tables=one two three]  # A list of tables to include when dumping source data.

Resets and copies schema and data from a source to a target database

Instance Method Summary collapse

Methods included from Helpers

included

Instance Method Details

#capture_snapshotObject



53
54
55
# File 'lib/duple/cli/refresh.rb', line 53

def capture_snapshot
  source.capture_snapshot if config.capture?
end

#download_snapshotObject



63
64
65
66
67
68
69
70
71
72
# File 'lib/duple/cli/refresh.rb', line 63

def download_snapshot
  return unless download_snapshot?

  timestamp = source.latest_snapshot_time

  @snapshot_path = snapshot_file_path(timestamp.strftime('%Y-%m-%d-%H-%M-%S'))
  unless File.exists?(@snapshot_path)
    runner.run("curl -o #{@snapshot_path} #{@source_snapshot_url}")
  end
end

#dump_dataObject



74
75
76
77
78
# File 'lib/duple/cli/refresh.rb', line 74

def dump_data
  return unless dump_data?

  postgres.pg_dump(dump_flags, data_file_path, source_db_config)
end

#fetch_snapshot_urlObject



57
58
59
60
61
# File 'lib/duple/cli/refresh.rb', line 57

def fetch_snapshot_url
  return unless fetch_snapshot_url?

  @source_snapshot_url = source.snapshot_url
end

#reset_targetObject



80
81
82
# File 'lib/duple/cli/refresh.rb', line 80

def reset_target
  reset_database(config.target_environment)
end

#restore_databaseObject



84
85
86
87
88
89
90
91
92
# File 'lib/duple/cli/refresh.rb', line 84

def restore_database
  if download_snapshot?
    postgres.pg_restore('-e -v --no-acl -O -a', @snapshot_path, target_db_config)
  elsif dump_data?
    postgres.pg_restore('-e -v --no-acl -O -a', data_file_path, target_db_config)
  else
    heroku.run(target_appname, "pgbackups:restore DATABASE #{@source_snapshot_url}")
  end
end

#run_postrefresh_tasksObject



94
95
96
# File 'lib/duple/cli/refresh.rb', line 94

def run_postrefresh_tasks
  run_tasks(config.post_refresh_tasks)
end

#run_prerefresh_tasksObject



49
50
51
# File 'lib/duple/cli/refresh.rb', line 49

def run_prerefresh_tasks
  run_tasks(config.pre_refresh_tasks)
end