heroku_tool 0.9.3 → 0.9.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5aff0c40aebac826f0c564531114ce61762c7e1fed7ad87b281160c7b27bccd0
4
- data.tar.gz: b8ff4953f2f385b49f7a25a8f276bdce0e5221f34db9a5207b3f60fb3ebe1c63
3
+ metadata.gz: 87a4838bb986b0cb1c7404a967443c0ad1015718a755733fb58b7bdfd78b4e1c
4
+ data.tar.gz: 5d8e1560f6211c8cee8006c74a7dc7f6b50994dbedd43d5dc0755d939ac0c1dd
5
5
  SHA512:
6
- metadata.gz: 7275494d3fbd74ac696cd30394b8a7969594c6c77e2ad9aac787a1562247956a3b28de99940a6f085da2b55d99337a3a207c66b441710c0f50c2328d92055783
7
- data.tar.gz: 8a49007bd74cd1b5cedf559e3d7ad0afaae2765eef98d9c25b2003e04afedb7c422052f168d2fc6e3fb4ec090beb28583fc05719c785703230a18764b9d2f9fe
6
+ metadata.gz: 6c5aac4e33eb719b8f2ccde8b8d6d7198323cbb42f92c7a711b020919b7b59ba022a7d9e92bfc41a8d0bf2ab41d348978fac25d48d84851494c7ef95b1c46312
7
+ data.tar.gz: ee4cfec74f3d1cf448eafb606d3ee9712c200bd17b86ba8a606e79a6bfb805d4b36e82bd2b220ca40039662dbadd2de535ca8b08eca3b03c424b203f6cbed0ba
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## v0.9.4
4
+
5
+ - `heroku:db:from_dump` restores with parallel jobs: `--jobs`, default 4 (use `--jobs 1` for the old behaviour)
6
+ - `Configuration#skip_table_data` lists tables whose data `from_dump` leaves out (the tables are still created, empty); `--all-data` restores them anyway
7
+
3
8
  ## v0.9.3
4
9
 
5
10
  record the app revision using git describe, at the beginning of the process (in case of accidental branch switches)
data/README.md CHANGED
@@ -93,6 +93,14 @@ Sync a database down from remote to local
93
93
 
94
94
  _FYI rake db:drop_all_tables is handy as it doesn't require you to disconnect any running processes from the database._
95
95
 
96
+ `from_dump` restores with 4 parallel jobs (`--jobs N` to change). To leave out the data of
97
+ large tables you don't need locally (an audit table, say), list them in your configuration;
98
+ the tables are still created, just empty, and `--all-data` restores everything:
99
+
100
+ def skip_table_data
101
+ %w[versions]
102
+ end
103
+
96
104
  Copy production db to staging
97
105
 
98
106
  thor heroku:sync:to staging -f production
@@ -36,6 +36,12 @@ module HerokuTool
36
36
  end
37
37
  end
38
38
 
39
+ # tables whose data heroku:db:from_dump leaves out (the tables are still created, empty),
40
+ # e.g. %w[versions] for a large audit table you don't need locally
41
+ def skip_table_data
42
+ []
43
+ end
44
+
39
45
  def after_sync_down(instance)
40
46
  # could add source ?
41
47
  instance.puts_and_system "rails db:migrate"
@@ -318,15 +318,35 @@ class Heroku < Thor
318
318
  desc "from_dump --from SOURCE_TARGET", "make the db the same as the last target dump from SOURCE_TARGET"
319
319
 
320
320
  method_option :just_restore, default: false, desc: "Just do restore without post-actions", type: :boolean
321
+ method_option :all_data, default: false, desc: "Also restore the data of the tables in Configuration#skip_table_data", type: :boolean
322
+ method_option :jobs, default: 4, desc: "Number of parallel pg_restore jobs", type: :numeric
321
323
 
322
324
  def from_dump
323
325
  invoke "warn", [], from: options[:from]
324
326
  source = lookup_heroku(options[:from])
325
327
  db_config = ::HerokuTool::DbConfiguration.new
326
- puts_and_system "pg_restore --verbose --clean --no-acl --no-owner -h localhost #{db_config.user_arg} -d #{db_config.database} #{source.dump_filename}"
328
+ puts_and_system "pg_restore --verbose --clean --no-acl --no-owner -j #{options[:jobs]} #{restore_list_arg(source)}-h localhost #{db_config.user_arg} -d #{db_config.database} #{source.dump_filename}"
327
329
  configuration.after_sync_down(self) unless options[:just_restore]
328
330
  end
329
331
 
332
+ no_commands do
333
+ # @return [String] "-L <list> " naming a copy of the dump's table of contents with the
334
+ # data of Configuration#skip_table_data commented out, or "" when nothing is skipped
335
+ def restore_list_arg(source)
336
+ tables = options[:all_data] ? [] : configuration.skip_table_data
337
+ return "" if tables.empty?
338
+
339
+ toc, status = Open3.capture2("pg_restore", "-l", source.dump_filename)
340
+ raise Thor::Error, "pg_restore -l #{source.dump_filename} failed" unless status.success?
341
+
342
+ patterns = tables.map { |table| / TABLE DATA public #{Regexp.escape(table)} / }
343
+ list = toc.lines.map { |line| (patterns.any? { |pattern| line.match?(pattern) }) ? ";#{line}" : line }
344
+ list_filename = "#{source.dump_filename}.list"
345
+ File.write(list_filename, list.join)
346
+ "-L #{list_filename} "
347
+ end
348
+ end
349
+
330
350
  desc "dump_to_tmp", "dump to tmp directory"
331
351
  method_option(:from, type: :string, default: "local", desc: "heroku target (defaults to local)", required: false, aliases: "f")
332
352
 
@@ -1,3 +1,3 @@
1
1
  module HerokuTool
2
- VERSION = "0.9.3"
2
+ VERSION = "0.9.4"
3
3
  end
@@ -37,6 +37,10 @@ class Heroku
37
37
  # instance.puts_and_system "rake dev:dev_data"
38
38
  # end
39
39
  #
40
+ # def skip_table_data
41
+ # %w[versions]
42
+ # end
43
+ #
40
44
  # def after_sync_to(instance, target)
41
45
  # super
42
46
  # instance.puts_and_system %(heroku run rake dev:staging_data -a #{target.heroku_app})
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: heroku_tool
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3
4
+ version: 0.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Diggins