Permalink
Browse files

update for heroku gem 2.0

  • Loading branch information...
1 parent 187f3c5 commit 15aa347601eda0505ae693ab655e5deb6f56fb9a @will committed Apr 28, 2011
Showing with 54 additions and 6 deletions.
  1. +37 −0 pg.rb
  2. +17 −6 pgbackups.rb
View
37 pg.rb
@@ -2,28 +2,58 @@ module Heroku
module Command
class Pg
include PGResolver
+ # pg:ingress [DATABASE]
+ #
+ # allow direct connections to the database from this IP for one minute
+ #
+ # (dedicated only)
+ # defaults to DATABASE_URL databases if no DATABASE is specified
+ #
def ingress
uri = generate_ingress_uri("Granting ingress for 60s")
display "Connection info string:"
display " \"dbname=#{uri.path[1..-1]} host=#{uri.host} user=#{uri.user} password=#{uri.password} sslmode=required\""
end
+ # pg:psql [DATABASE]
+ #
+ # open a psql shell to the database
+ #
+ # (dedicated only)
+ # defaults to DATABASE_URL databases if no DATABASE is specified
+ #
def psql
uri = generate_ingress_uri("Connecting")
ENV["PGPASSWORD"] = uri.password
ENV["PGSSLMODE"] = 'require'
system "psql -U #{uri.user} -h #{uri.host} -p #{uri.port || 5432} #{uri.path[1..-1]}"
end
+ # pg:info [DATABASE]
+ #
+ # display database information
+ #
+ # defaults to all databases if no DATABASE is specified
+ #
def info
specified_db_or_all { |db| display_db_info db }
end
+ # pg:wait [DATABASE]
+ #
+ # monitor database creation, exit when complete
+ #
+ # defaults to all databases if no DATABASE is specified
+ #
def wait
display "Checking availablity of all databases" unless specified_db?
specified_db_or_all { |db| wait_for db }
end
+ # pg:promote <DATABASE>
+ #
+ # sets DATABASE as your DATABASE_URL
+ #
def promote
follower_db = resolve_db(:required => 'pg:promote')
abort( " ! DATABASE_URL is already set to #{follower_db[:name]}") if follower_db[:default]
@@ -36,6 +66,10 @@ def promote
display_info "DATABASE_URL (#{follower_db[:name]})", follower_db[:url]
end
+ # pg:untrack <DATABASE>
+ #
+ # diverge DATABASE from its leader
+ #
def untrack
follower_db = resolve_db(:required => 'pg:untrack')
@@ -50,6 +84,9 @@ def untrack
display_info "#{follower_db[:name]} stopped tracking", follower_db[:url]
end
+ # pg:reset <DATABASE>
+ #
+ # delete all data in DATABASE
def reset
db = resolve_db(:required => 'pg:reset')
View
23 pgbackups.rb
@@ -1,15 +1,18 @@
-require "heroku/commands/help"
require "heroku/pgutils"
require "pgbackups/client"
module Heroku::Command
class Pgbackups < BaseWithApp
include PGResolver
- Heroku::Command::Help.group("pgbackups") do |group|
- group.command "pgbackups:capture [<DB_ID>]", "capture a backup from database ID (default: DATABASE_URL)"
- end
-
+ # pgbackups:capture [DATABASE]
+ #
+ # capture a backup from a database id
+ #
+ # if no DATABASE is specified, defaults to DATABASE_URL
+ #
+ # -e, --expire # if no slots are available to capture, delete the oldest backup to make room
+ #
def capture
db = resolve_db(:allow_default => true)
@@ -33,9 +36,17 @@ def capture
message += "\n ! The database credentials are incorrect." if backup['log'] =~ /psql: FATAL:/
abort(message)
end
-
end
+ # pgbackups:restore [BACKUP_ID]
+ #
+ # restore a backup to a database id
+ #
+ # if no BACKUP_ID is specified, uses the most recent backup
+ #
+ # -d, --db DATABASE # the database id to target for the restore
+ #
+
def restore
db = resolve_db(:allow_default => true)
to_name = db[:name]

0 comments on commit 15aa347

Please sign in to comment.