Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rake db:* tasks reference to production database; Add direct synchronisation task #1059

Merged
merged 2 commits into from
Mar 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion lib/tasks/db.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
Loading