backhoe 0.9.0 → 0.10.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/.github/workflows/ci.yml +3 -3
- data/Appraisals +4 -8
- data/README.md +1 -1
- data/backhoe.gemspec +1 -0
- data/gemfiles/{activerecord_6.0.gemfile → activerecord_7.2.gemfile} +1 -1
- data/lib/backhoe/dump.rb +23 -7
- data/lib/backhoe/load.rb +4 -4
- data/lib/backhoe/version.rb +1 -1
- data/lib/backhoe.rb +4 -4
- metadata +17 -4
- data/gemfiles/activerecord_6.1.gemfile +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77326a186f91c5bf3d2f47475d05bb64922b1df6039a8ee3d151779fafde9c85
|
4
|
+
data.tar.gz: ce066cade2bb20be3d146ac30086116a7780619b8ecef4edb3a40f677b0f0857
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e8f17f5ce5699cc9d4c8fd6eab4ab93881cfb6d01e723a3f7383c7506a483a29b8b170f0ff23c528e25f4b9f21b5d0b547208c5390a35403cbf7e0c7901ce5a9
|
7
|
+
data.tar.gz: 6352b47008307ecd5f300c2f577a2ab1e92c4164af9f97ae9aefd7b03ab53f60161cc4c9c29b29bd8bef40fecf1f7ead833157838e3cf81f9532b83d2b837b7e
|
data/.github/workflows/ci.yml
CHANGED
@@ -5,10 +5,10 @@ jobs:
|
|
5
5
|
strategy:
|
6
6
|
fail-fast: false
|
7
7
|
matrix:
|
8
|
-
gemfile: [
|
9
|
-
ruby: [
|
8
|
+
gemfile: [ activerecord_7.0, activerecord_7.1, activerecore_7.2 ]
|
9
|
+
ruby: [ 3.1, 3.2, 3.3 ]
|
10
10
|
|
11
|
-
runs-on: ubuntu-
|
11
|
+
runs-on: ubuntu-22.04
|
12
12
|
env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps
|
13
13
|
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile
|
14
14
|
POSTGRES_HOST_AUTH_METHOD: trust
|
data/Appraisals
CHANGED
@@ -1,11 +1,3 @@
|
|
1
|
-
appraise "activerecord-6.0" do
|
2
|
-
gem "activerecord", "~>6.0.0"
|
3
|
-
end
|
4
|
-
|
5
|
-
appraise "activerecord-6.1" do
|
6
|
-
gem "activerecord", "~>6.1.0"
|
7
|
-
end
|
8
|
-
|
9
1
|
appraise "activerecord-7.0" do
|
10
2
|
gem "activerecord", "~>7.0.0"
|
11
3
|
end
|
@@ -14,3 +6,7 @@ appraise "activerecord-7.1" do
|
|
14
6
|
gem "activerecord", "~>7.1.0"
|
15
7
|
end
|
16
8
|
|
9
|
+
appraise "activerecord-7.2" do
|
10
|
+
gem "activerecord", "~>7.2.0"
|
11
|
+
end
|
12
|
+
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# Backhoe
|
2
|
-
[](https://github.com/botandrose/backhoe/actions/workflows/ci.yml)
|
3
3
|
|
4
4
|
Dump and load current ActiveRecord database to and from a file.
|
5
5
|
|
data/backhoe.gemspec
CHANGED
data/lib/backhoe/dump.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require "rake"
|
2
2
|
|
3
3
|
module Backhoe
|
4
|
-
class Dump < Struct.new(:database, :
|
4
|
+
class Dump < Struct.new(:database, :path, :skip_tables, :skip_columns)
|
5
5
|
include Rake::DSL
|
6
6
|
|
7
7
|
def initialize *args
|
@@ -16,7 +16,7 @@ module Backhoe
|
|
16
16
|
end
|
17
17
|
if skip_columns.any?
|
18
18
|
raise NotImplementedError if database.postgresql?
|
19
|
-
SanitizedDatabase.new(skip_columns,
|
19
|
+
SanitizedDatabase.new(skip_columns, path).dump do |tables|
|
20
20
|
self.skip_tables += tables
|
21
21
|
dump
|
22
22
|
end
|
@@ -29,16 +29,32 @@ module Backhoe
|
|
29
29
|
|
30
30
|
def dump
|
31
31
|
if database.mysql?
|
32
|
-
|
32
|
+
bash_sh "#{mysqldump} --no-create-db --single-transaction --quick -e #{skip_table_options} #{database.to_mysql_options} #{database.name} | #{pipe} #{target}"
|
33
33
|
elsif database.postgresql?
|
34
|
-
|
34
|
+
bash_sh "#{pg_dump} --column-inserts #{database.name} | #{pipe} #{target}"
|
35
35
|
else
|
36
36
|
raise "don't know how to dump #{database.adapter}"
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
+
def bash_sh(command)
|
41
|
+
sh <<~EOS
|
42
|
+
/bin/bash -xeu <<'BASH'
|
43
|
+
set -o pipefail && #{command}
|
44
|
+
BASH
|
45
|
+
EOS
|
46
|
+
end
|
47
|
+
|
40
48
|
private
|
41
49
|
|
50
|
+
def target
|
51
|
+
if path =~ /^https?:\/\//
|
52
|
+
"| curl -X PUT -H 'Content-Type: application/octet-stream' --data-binary @- '#{path}'"
|
53
|
+
else
|
54
|
+
"> #{path}"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
42
58
|
def mysqldump
|
43
59
|
cmd = `which mysqldump`.strip
|
44
60
|
raise RuntimeError, "Cannot find mysqldump." if cmd.blank?
|
@@ -52,7 +68,7 @@ module Backhoe
|
|
52
68
|
end
|
53
69
|
|
54
70
|
def pipe
|
55
|
-
|
71
|
+
path =~ /\.gz\b/ ? "gzip -9f" : "cat"
|
56
72
|
end
|
57
73
|
|
58
74
|
def skip_table_options
|
@@ -61,13 +77,13 @@ module Backhoe
|
|
61
77
|
end.join(" ")
|
62
78
|
end
|
63
79
|
|
64
|
-
class SanitizedDatabase < Struct.new(:config, :
|
80
|
+
class SanitizedDatabase < Struct.new(:config, :path)
|
65
81
|
def dump
|
66
82
|
with_sanitized_tables do
|
67
83
|
yield skip_tables
|
68
84
|
end
|
69
85
|
skip_tables.each do |table|
|
70
|
-
File.write
|
86
|
+
File.write path, "RENAME TABLE `sanitized_#{table}` TO `#{table}`;", mode: "a"
|
71
87
|
end
|
72
88
|
end
|
73
89
|
|
data/lib/backhoe/load.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require "rake"
|
2
2
|
|
3
3
|
module Backhoe
|
4
|
-
class Load < Struct.new(:database, :
|
4
|
+
class Load < Struct.new(:database, :path, :drop_and_create)
|
5
5
|
include Rake::DSL
|
6
6
|
|
7
7
|
def call
|
@@ -18,7 +18,7 @@ module Backhoe
|
|
18
18
|
private
|
19
19
|
|
20
20
|
def mysql_command
|
21
|
-
cmd = "#{cat} #{
|
21
|
+
cmd = "#{cat} #{path} | "
|
22
22
|
cmd += if drop_and_create
|
23
23
|
"#{pipe} | #{mysql} #{database.to_mysql_options}"
|
24
24
|
else
|
@@ -27,7 +27,7 @@ module Backhoe
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def psql_command
|
30
|
-
cmd = "#{cat} #{
|
30
|
+
cmd = "#{cat} #{path} | "
|
31
31
|
if drop_and_create
|
32
32
|
cmd = "dropdb -f #{database.name}; createdb #{database.name}; #{cmd}"
|
33
33
|
end
|
@@ -36,7 +36,7 @@ module Backhoe
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def cat
|
39
|
-
|
39
|
+
path =~ /\.gz$/ ? "zcat" : "cat"
|
40
40
|
end
|
41
41
|
|
42
42
|
def pipe
|
data/lib/backhoe/version.rb
CHANGED
data/lib/backhoe.rb
CHANGED
@@ -6,12 +6,12 @@ require "active_record"
|
|
6
6
|
|
7
7
|
module Backhoe
|
8
8
|
class << self
|
9
|
-
def dump
|
10
|
-
Dump.new(Database.new,
|
9
|
+
def dump path, skip_tables: [], skip_columns: {}
|
10
|
+
Dump.new(Database.new, path, skip_tables, skip_columns).call
|
11
11
|
end
|
12
12
|
|
13
|
-
def load
|
14
|
-
Load.new(Database.new,
|
13
|
+
def load path, drop_and_create: false
|
14
|
+
Load.new(Database.new, path, drop_and_create).call
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: backhoe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Micah Geisel
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-09-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -122,6 +122,20 @@ dependencies:
|
|
122
122
|
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: webrick
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
125
139
|
description: Dump and load current database to and from a file.
|
126
140
|
email:
|
127
141
|
- micah@botandrose.com
|
@@ -141,10 +155,9 @@ files:
|
|
141
155
|
- bin/console
|
142
156
|
- bin/setup
|
143
157
|
- gemfiles/.bundle/config
|
144
|
-
- gemfiles/activerecord_6.0.gemfile
|
145
|
-
- gemfiles/activerecord_6.1.gemfile
|
146
158
|
- gemfiles/activerecord_7.0.gemfile
|
147
159
|
- gemfiles/activerecord_7.1.gemfile
|
160
|
+
- gemfiles/activerecord_7.2.gemfile
|
148
161
|
- lib/backhoe.rb
|
149
162
|
- lib/backhoe/database.rb
|
150
163
|
- lib/backhoe/dump.rb
|