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 +4 -4
- data/CLAUDE.md +1 -0
- data/lib/backhoe/database.rb +13 -2
- data/lib/backhoe/dump.rb +1 -1
- data/lib/backhoe/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 85cc0019ecac6ec2bc39a222be9d4e3459d7910175241236189dcc8079981fa7
|
|
4
|
+
data.tar.gz: '027798340dbaadcd755887ea6bb6aa59751bfeb4e8a6d6eb722bcc6b08abb525'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
|
data/lib/backhoe/database.rb
CHANGED
|
@@ -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 = "
|
|
19
|
-
options += " -
|
|
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.
|
|
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?
|
data/lib/backhoe/version.rb
CHANGED