-
-
Notifications
You must be signed in to change notification settings - Fork 530
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
Schedule Heroku Backups and Capture backup of existing staging database for Review Apps #826
Conversation
When a PR Review environment is created, the latest backup is currently used. If no backups exist, or if the backup is old and outdated, recent data used for testing may not exist. This forcibly creates a backup right before migration -- leading to the most recent data. Another way to solve this would be to automatically add `pg:backups:schedule` on all staging environments on original app scaffolding, but that would be up to 24 hours difference.
This is what I normally do on my Rails projects. Regardless of how we merge this PR, I'd like production and staging to have daily backups by default (I thought this was already the case). I don't feel strongly either way, and we can merge as is or instead turn this PR into adding the daily backup instruction on app creation, and then keeping this script as is. What do you prefer? Thanks for sharing your work! |
lib/suspenders/adapters/heroku.rb
Outdated
) | ||
end | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing whitespace detected.
lib/suspenders/adapters/heroku.rb
Outdated
) | ||
end | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing whitespace detected.
spec/adapters/heroku_spec.rb
Outdated
|
||
def have_backup_schedule(remote_name) | ||
have_received(:run). | ||
with(/pg:backups:schedule DATABASE_URL --at '02:00 America\/Los_Angeles' --remote #{remote_name}/) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [108/80]
spec/adapters/heroku_spec.rb
Outdated
@@ -48,6 +58,11 @@ module Adapters | |||
def app_name | |||
SuspendersTestHelpers::APP_NAME | |||
end | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing whitespace detected.
spec/adapters/heroku_spec.rb
Outdated
expect(app_builder).to have_backup_schedule("staging") | ||
expect(app_builder).to have_backup_schedule("production") | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing whitespace detected.
This LGTM. Calling in @iwz for another review before I merge. Thank you! :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good overall, but that LA time zone feels a bit out of place
lib/suspenders/adapters/heroku.rb
Outdated
def set_heroku_backup_schedule | ||
%w(staging production).each do |environment| | ||
run_toolbelt_command( | ||
"pg:backups:schedule DATABASE_URL --at '02:00 America/Los_Angeles'", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps convert this to UTC?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the Heroku default recommended in their docs -- to convert it do you mean 2AM UTC or 10AM UTC?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I saw that in their docs. 10AM UTC would be fine.
spec/adapters/heroku_spec.rb
Outdated
@@ -49,6 +59,11 @@ def app_name | |||
SuspendersTestHelpers::APP_NAME | |||
end | |||
|
|||
def have_backup_schedule(remote_name) | |||
have_received(:run). | |||
with(/pg:backups:schedule DATABASE_URL --at '02:00 America\/Los_Angeles' --remote #{remote_name}/) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [108/80]
@@ -49,6 +59,11 @@ def app_name | |||
SuspendersTestHelpers::APP_NAME | |||
end | |||
|
|||
def have_backup_schedule(remote_name) | |||
have_received(:run). | |||
with(/pg:backups:schedule DATABASE_URL --at '10:00 UTC' --remote #{remote_name}/) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [91/80]
@toobulkeh this looks good to go. Do you want to clean up any commits before we merge? Also, do you think the README should mention anything about the scheduled backups? |
Added to the README @iwz. I'd appreciate a Squash and Merge. Is that something I can do? |
@toobulkeh done. thanks for implementing this! |
@croaky good idea. i'm not set up for that atm, are you? |
When a PR Review environment is created, the latest backup is currently used. If no backups exist, or if the backup is old and outdated, recent data used for testing may not exist.
This forcibly creates a backup right before migration -- leading to the most recent data.
Another way to solve this would be to automatically add
pg:backups:schedule
on all staging environments on original app scaffolding, but that would be up to 24 hours difference.