-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix rake db:* tasks reference to production database; Add direct sync…
…hronisation task (#1059)
- Loading branch information
Showing
1 changed file
with
27 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -141,6 +141,32 @@ namespace :db do | |
DB_DUMP_SSH_URL = 'DB_DUMP_SSH_URL' | ||
DB_DUMP_STAGING_SSH_URL = 'DB_DUMP_STAGING_SSH_URL' | ||
|
||
desc "Synchronize staging with the production database in one fell swoop" | ||
task sync_prod_staging: :environment do | ||
|
||
prod_ssh_url = if ENV[DB_DUMP_SSH_URL] | ||
ENV[DB_DUMP_SSH_URL] | ||
else | ||
'[email protected] -p 666' | ||
end | ||
|
||
ssh_url = if ENV[DB_DUMP_STAGING_SSH_URL] | ||
ENV[DB_DUMP_STAGING_SSH_URL] | ||
else | ||
'[email protected] -p 666' | ||
end | ||
|
||
$stdout.puts "Backing up staging db (May take a while.) ..." | ||
puts `ssh #{ssh_url} dokku postgres:export placecal-db > $(date -Im)_placecal-staging.sql` | ||
$stdout.puts "Replicating production db to staging db (May take a while.) ..." | ||
puts `ssh #{prod_ssh_url} dokku postgres:export placecal-db2 | ssh #{ssh_url} dokku postgres:import placecal-db` | ||
if $?.success? | ||
$stdout.puts "Replicated production to staging (you might have to run rails db:migrate in dokku?)" | ||
else | ||
$stderr.puts "Failed to replicate production to staging!" | ||
end | ||
end | ||
|
||
desc "Download production DB dump" | ||
task dump_production: :environment do | ||
|
||
|
@@ -157,7 +183,7 @@ namespace :db do | |
end | ||
|
||
$stdout.puts "Downloading production db to #{filename} (May take a while.) ..." | ||
puts `ssh #{ssh_url} dokku postgres:export placecal-db > #{filename}` | ||
puts `ssh #{ssh_url} dokku postgres:export placecal-db2 > #{filename}` | ||
if $?.success? | ||
$stdout.puts "Downloaded production db to #{filename}" | ||
ENV[DB_DUMP_ENV_KEY] = filename | ||
|