backhoe 0.12.0 → 0.12.1

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: 1c3388209c28de44224013396cb7014a6353f046f3571bbbe14c9583e29c43c6
4
- data.tar.gz: e19e932a0835eec574edd2d59b5c9b830a65f16acbab692aadad4fd2bea85c57
3
+ metadata.gz: 85cc0019ecac6ec2bc39a222be9d4e3459d7910175241236189dcc8079981fa7
4
+ data.tar.gz: '027798340dbaadcd755887ea6bb6aa59751bfeb4e8a6d6eb722bcc6b08abb525'
5
5
  SHA512:
6
- metadata.gz: 28348bb09ea2d40d4e2df95bb10f518602061b2be76b7301f9cfe43d67a4649259b0871dbd971243ab2887c56cc587498670d39fb4555b66744ad5ee32bc7532
7
- data.tar.gz: b495b45a9bdcecf5f8d99458b984355360f555ee01a380c0d7b230619e60cf29d56206dbace91141383fc4e2b1cd0aa33ca2b8530947cfe8604886b9b7b4a196
6
+ metadata.gz: ac23a06f8263fefea701dc7d45a388d17dd0d9d2c3a47c0ce4e66594e0c3bb56671c2fbc43127c027a178370f86023aad2be1420ec19ac2d3e30870614df56a7
7
+ data.tar.gz: 9ad43e90291a876e08be7703f8b577dc9e873e8570d3678dea28dbff0d086e3d0502298789dced02df62a4e7414aedb604a38fca8dc56cedb3d71efaa4657baa
data/CLAUDE.md CHANGED
@@ -16,6 +16,7 @@ bundle exec rspec spec/backhoe/dump_spec.rb:15 # Run a single example by line
16
16
  ```
17
17
 
18
18
  Tests require running MySQL and PostgreSQL services. Test database config is in `spec/support/database.yml`.
19
+ `spec/backhoe/mysql_password_spec.rb` creates a password-protected MySQL user through the admin account in `BACKHOE_TEST_MYSQL_USER` (default: the config's `root`).
19
20
 
20
21
  ## Architecture
21
22
 
@@ -1,3 +1,5 @@
1
+ require "tempfile"
2
+
1
3
  module Backhoe
2
4
  class Database
3
5
  def initialize config=load_config
@@ -15,8 +17,9 @@ module Backhoe
15
17
  end
16
18
 
17
19
  def to_mysql_options
18
- options = " -u #{config["username"]}"
19
- options += " -p'#{config["password"]}'" if config["password"]
20
+ options = ""
21
+ options += " --defaults-extra-file=#{password_file.path}" if config["password"]
22
+ options += " -u #{config["username"]}"
20
23
  options += " -h #{config["host"]}" if config["host"]
21
24
  options += " -S #{config["socket"]}" if config["socket"]
22
25
  options
@@ -49,6 +52,14 @@ module Backhoe
49
52
 
50
53
  private
51
54
 
55
+ # A password on the command line is visible to every user on the host and echoed into logs and errors.
56
+ def password_file
57
+ @password_file ||= Tempfile.new(["backhoe", ".cnf"]).tap do |file|
58
+ file.write(%([client]\npassword="#{config["password"].to_s.gsub(/[\\"]/) { "\\#{$&}" }}"\n))
59
+ file.flush
60
+ end
61
+ end
62
+
52
63
  def load_config
53
64
  configs = ActiveRecord::Base.configurations
54
65
  config = configs.configs_for(env_name: current_environment_name).first
data/lib/backhoe/dump.rb CHANGED
@@ -30,7 +30,7 @@ module Backhoe
30
30
  def dump skipped, trailer = nil
31
31
  if database.mysql?
32
32
  trailer = "; printf '\\n%s' #{Shellwords.escape(trailer)}" if trailer
33
- bash_sh "{ #{mysqldump} --no-create-db --single-transaction --quick -e #{skip_table_options(skipped)} #{database.to_mysql_options} #{database.name}#{trailer}; } | #{pipe} #{target}"
33
+ bash_sh "{ #{mysqldump}#{database.to_mysql_options} --no-create-db --single-transaction --quick -e #{skip_table_options(skipped)} #{database.name}#{trailer}; } | #{pipe} #{target}"
34
34
  elsif database.postgresql?
35
35
  bash_sh "#{pg_dump} --column-inserts #{database.name} | #{pipe} #{target}"
36
36
  elsif database.sqlite?
@@ -1,3 +1,3 @@
1
1
  module Backhoe
2
- VERSION = "0.12.0"
2
+ VERSION = "0.12.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: backhoe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.12.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Micah Geisel