Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Fix unscheduling backups for some config var configurations #1539

Merged
merged 4 commits into from May 15, 2015
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/heroku/command/pg_backups.rb
Expand Up @@ -513,12 +513,15 @@ def unschedule_backups
db = shift_argument
validate_arguments!

if db.nil?
abort("Must specify database to unschedule backups for")
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is only one schedule, should we accept no db here?

For this message, I'd add a hint:

Must specify a database. Run `heroku help pg:backups` for usage information.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it does make sense to require an argument. Maybe instead of pointing people to help, we should just list what's available to unschedule instead?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree we should require an argument. :)


attachment = generate_resolver.resolve(db, "DATABASE_URL")

schedule = hpg_client(attachment).schedules.find do |s|
# attachment.name is HEROKU_POSTGRESQL_COLOR
# s[:name] is HEROKU_POSTGRESQL_COLOR_URL
s[:name] =~ /#{attachment.name}/ || attachment.name =~ /#{s[:name]}/
s[:name] =~ /#{db}/i
end

if schedule.nil?
Expand Down
34 changes: 34 additions & 0 deletions spec/heroku/command/pg_backups_spec.rb
Expand Up @@ -122,6 +122,40 @@ module Heroku::Command
end
end

describe "heroku pg:backups unschedule" do
let(:schedules) do
[ { name: 'HEROKU_POSTGRESQL_GREEN_URL',
uuid: 'ffffffff-ffff-ffff-ffff-ffffffffffff' },
{ name: 'DATABASE_URL',
uuid: 'ffffffff-ffff-ffff-ffff-fffffffffffe' } ]
end

before do
stub_pg.schedules.returns(schedules)
allow_any_instance_of(Heroku::Helpers::HerokuPostgresql::Resolver)
.to receive(:app_attachments).and_return(example_attachments)
end

it "unschedules the specified backup" do
stub_pg.unschedule
stderr, stdout = execute("pg:backups unschedule green --confirm example")
expect(stderr).to be_empty
expect(stdout).to match(/Stopped automatic daily backups for/)
end

it "complains when called without an argument" do
stderr, stdout = execute("pg:backups unschedule --confirm example")
expect(stderr).to match(/Must specify database to unschedule/)
expect(stdout).to be_empty
end

it "indicates when no matching backup can be unscheduled" do
stderr, stdout = execute("pg:backups unschedule red --confirm example")
expect(stderr).to be_empty
expect(stdout).to match(/No automatic daily backups for/)
end
end

describe "heroku pg:backups" do
let(:logged_at) { Time.now }
let(:started_at) { Time.now }
Expand Down