Class: Duple::CLI::Refresh
- Inherits:
-
Thor::Group
- Object
- Thor::Group
- Duple::CLI::Refresh
- 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
- #capture_snapshot ⇒ Object
- #download_snapshot ⇒ Object
- #dump_data ⇒ Object
- #fetch_snapshot_url ⇒ Object
- #reset_target ⇒ Object
- #restore_database ⇒ Object
Methods included from Helpers
Instance Method Details
#capture_snapshot ⇒ Object
44 45 46 47 48 |
# File 'lib/duple/cli/refresh.rb', line 44 def capture_snapshot return unless capture_snapshot? heroku.run(source_appname, 'pgbackups:capture') end |
#download_snapshot ⇒ Object
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/duple/cli/refresh.rb', line 56 def download_snapshot return unless download_snapshot? = fetch_latest_snapshot_time(source_appname) @snapshot_path = snapshot_file_path(.strftime('%Y-%m-%d-%H-%M-%S')) unless File.exists?(@snapshot_path) runner.run("curl -o #{@snapshot_path} #{@source_snapshot_url}") end end |
#dump_data ⇒ Object
67 68 69 70 71 |
# File 'lib/duple/cli/refresh.rb', line 67 def dump_data return unless dump_data? postgres.pg_dump(dump_flags, data_file_path, source_db_config) end |
#fetch_snapshot_url ⇒ Object
50 51 52 53 54 |
# File 'lib/duple/cli/refresh.rb', line 50 def fetch_snapshot_url return unless fetch_snapshot_url? @source_snapshot_url = heroku.capture(source_appname, 'pgbackups:url').strip end |
#reset_target ⇒ Object
73 74 75 |
# File 'lib/duple/cli/refresh.rb', line 73 def reset_target reset_database(config.target_environment) end |
#restore_database ⇒ Object
77 78 79 80 81 82 83 84 85 |
# File 'lib/duple/cli/refresh.rb', line 77 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 |