Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #8 from ankane/master

Added --tables option
  • Loading branch information...
commit 5129c45befc60253782a66ca1b284352ff1d8460 2 parents 5a78093 + 42bb34e
David Dollar authored July 10, 2013

Showing 1 changed file with 7 additions and 5 deletions. Show diff stats Hide diff stats

  1. 12  init.rb
12  init.rb
@@ -6,12 +6,14 @@ class Heroku::Command::Pg < Heroku::Command::Base
6 6
   #
7 7
   # transfer data between databases
8 8
   #
9  
-  # -f, --from DATABASE  # source database, defaults to DATABASE_URL on the app
10  
-  # -t, --to   DATABASE  # target database, defaults to local $DATABASE_URL
  9
+  # -f, --from   DATABASE  # source database, defaults to DATABASE_URL on the app
  10
+  # -t, --to     DATABASE  # target database, defaults to local $DATABASE_URL
  11
+  # -b, --tables DATABASE  # tables to copy, defaults to all
11 12
   #
12 13
   def transfer
13 14
     from = options[:from] || "DATABASE"
14 15
     to   = options[:to]   || ENV["DATABASE_URL"] || env["DATABASE_URL"]
  16
+    tables = (options[:tables] || "").split(",")
15 17
 
16 18
     error <<-ERROR unless to
17 19
 No local DATABASE_URL detected and --to not specified.
@@ -32,7 +34,7 @@ def transfer
32 34
 
33 35
     return unless confirm_command
34 36
 
35  
-    system %{ #{pg_dump_command(from_url)} | #{pg_restore_command(to_url)} }
  37
+    system %{ #{pg_dump_command(from_url, tables)} | #{pg_restore_command(to_url)} }
36 38
   end
37 39
 
38 40
 private
@@ -53,13 +55,13 @@ def env
53 55
     end
54 56
   end
55 57
 
56  
-  def pg_dump_command(url)
  58
+  def pg_dump_command(url, tables)
57 59
     uri = URI.parse(url)
58 60
     database = uri.path[1..-1]
59 61
     host = uri.host || "localhost"
60 62
     port = uri.port || "5432"
61 63
     user = uri.user ? "-U #{uri.user}" : ""
62  
-    %{ env PGPASSWORD=#{uri.password} pg_dump --verbose -F c -h #{host} #{user} -p #{port} #{database} }
  64
+    %{ env PGPASSWORD=#{uri.password} pg_dump --verbose -F c -h #{host} #{user} -p #{port} #{tables.map{|name| "-t #{name}" }.join(" ")} #{database} }
63 65
   end
64 66
 
65 67
   def pg_restore_command(url)

0 notes on commit 5129c45

Please sign in to comment.
Something went wrong with that request. Please try again.