backhoe 0.2.0 → 0.5.0

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
- SHA1:
3
- metadata.gz: d019d5b66f418151f88ebf3d897d0272a32d173e
4
- data.tar.gz: f6e7f9c5df280e9730f6d48da8b37d756d54165e
2
+ SHA256:
3
+ metadata.gz: 2eedc96f1b7466ebc166988dce01252aec90d14fcadd216cf926699e5d97b2e4
4
+ data.tar.gz: ac773a88ca48fa6f3d89228b6e3ea319bec0e64e4a5ab0ce2fbbd67e08a3127f
5
5
  SHA512:
6
- metadata.gz: 6750d9c40ce7993f43a5a14b183833d533a475adbab48d249f7f7ac6295ef81fac6e5f046c676166d4a75cb38a8c3f5eafe9895695525813131ee1081bdd51f5
7
- data.tar.gz: 14f0271c2c51661fd1822655bfb15c47c2eba52ac878cbd5b097be601876c86d470b79610cb3bddb0fc4737d9289b29cd8b9054de24230ce27c8f3b8e37ecfe7
6
+ metadata.gz: ad26930dc3f9f53b3fbc62909fcd0942f478dd97c496ca3cb5127d19d81fdedd24db74358d33c3c797084c75bef77f1402ec308159c59265642f2093eda982eb
7
+ data.tar.gz: eb1a3ddb18501571bc2cbd2d3fd9af921d75788f5fc9c43ec7cfac20437c834b470ed335ce38223212cdc7950e18e09c16148a134c486b5e6c138428c4a16be6
@@ -0,0 +1,34 @@
1
+ name: CI
2
+ on: [push, pull_request]
3
+ jobs:
4
+ test:
5
+ strategy:
6
+ fail-fast: false
7
+ matrix:
8
+ gemfile: [ activerecord_5.1, activerecord_5.2, activerecord_6.0, activerecord_6.1, activerecord_7.0 ]
9
+ ruby: [ 2.6, 2.7, 3.0 ]
10
+ exclude:
11
+ - gemfile: activerecord_5.1
12
+ ruby: 3.0
13
+ - gemfile: activerecord_5.2
14
+ ruby: 3.0
15
+ - gemfile: activerecord_7.0
16
+ ruby: 2.6
17
+
18
+ runs-on: ubuntu-18.04
19
+ env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps
20
+ BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile
21
+ steps:
22
+ - uses: actions/checkout@v2
23
+ - uses: shogo82148/actions-setup-mysql@v1
24
+ with:
25
+ mysql-version: 5.7
26
+ my-cnf: |
27
+ socket=/tmp/mysql.sock
28
+ - uses: ruby/setup-ruby@v1
29
+ with:
30
+ ruby-version: ${{ matrix.ruby }}
31
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
32
+ cache-version: 10
33
+ - run: bundle exec rake
34
+
data/Appraisals ADDED
@@ -0,0 +1,20 @@
1
+ appraise "activerecord-5.1" do
2
+ gem "activerecord", "~>5.1.0"
3
+ end
4
+
5
+ appraise "activerecord-5.2" do
6
+ gem "activerecord", "~>5.2.0"
7
+ end
8
+
9
+ appraise "activerecord-6.0" do
10
+ gem "activerecord", "~>6.0.0"
11
+ end
12
+
13
+ appraise "activerecord-6.1" do
14
+ gem "activerecord", "~>6.1.0"
15
+ end
16
+
17
+ appraise "activerecord-7.0" do
18
+ gem "activerecord", "~>7.0.0"
19
+ end
20
+
data/Gemfile CHANGED
@@ -4,3 +4,4 @@ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
5
  # Specify your gem's dependencies in backhoe.gemspec
6
6
  gemspec
7
+
data/README.md CHANGED
@@ -1,8 +1,7 @@
1
1
  # Backhoe
2
+ [![CI Status](https://github.com/botandrose/backhoe/workflows/CI/badge.svg?branch=master)](https://github.com/botandrose/backhoe/actions?query=workflow%3ACI+branch%3Amaster)
2
3
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/backhoe`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
4
+ Dump and load current ActiveRecord database to and from a file.
6
5
 
7
6
  ## Installation
8
7
 
@@ -32,7 +31,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
31
 
33
32
  ## Contributing
34
33
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/backhoe.
34
+ Bug reports and pull requests are welcome on GitHub at https://github.com/botandrose/backhoe.
36
35
 
37
36
  ## License
38
37
 
data/backhoe.gemspec CHANGED
@@ -21,7 +21,11 @@ Gem::Specification.new do |spec|
21
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
22
  spec.require_paths = ["lib"]
23
23
 
24
- spec.add_development_dependency "bundler", "~> 1.16"
24
+ spec.add_dependency "activerecord"
25
+
25
26
  spec.add_development_dependency "rake", "~> 10.0"
26
27
  spec.add_development_dependency "rspec", "~> 3.0"
28
+ spec.add_development_dependency "appraisal"
29
+ spec.add_development_dependency "mysql2"
30
+ spec.add_development_dependency "byebug"
27
31
  end
@@ -0,0 +1,2 @@
1
+ ---
2
+ BUNDLE_RETRY: "1"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~>5.1.0"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,65 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ backhoe (0.4.1)
5
+ activerecord
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activemodel (5.1.7)
11
+ activesupport (= 5.1.7)
12
+ activerecord (5.1.7)
13
+ activemodel (= 5.1.7)
14
+ activesupport (= 5.1.7)
15
+ arel (~> 8.0)
16
+ activesupport (5.1.7)
17
+ concurrent-ruby (~> 1.0, >= 1.0.2)
18
+ i18n (>= 0.7, < 2)
19
+ minitest (~> 5.1)
20
+ tzinfo (~> 1.1)
21
+ appraisal (2.3.0)
22
+ bundler
23
+ rake
24
+ thor (>= 0.14.0)
25
+ arel (8.0.0)
26
+ byebug (11.1.3)
27
+ concurrent-ruby (1.1.8)
28
+ diff-lcs (1.4.4)
29
+ i18n (1.8.7)
30
+ concurrent-ruby (~> 1.0)
31
+ minitest (5.14.3)
32
+ mysql2 (0.5.3)
33
+ rake (10.5.0)
34
+ rspec (3.10.0)
35
+ rspec-core (~> 3.10.0)
36
+ rspec-expectations (~> 3.10.0)
37
+ rspec-mocks (~> 3.10.0)
38
+ rspec-core (3.10.1)
39
+ rspec-support (~> 3.10.0)
40
+ rspec-expectations (3.10.1)
41
+ diff-lcs (>= 1.2.0, < 2.0)
42
+ rspec-support (~> 3.10.0)
43
+ rspec-mocks (3.10.2)
44
+ diff-lcs (>= 1.2.0, < 2.0)
45
+ rspec-support (~> 3.10.0)
46
+ rspec-support (3.10.2)
47
+ thor (1.1.0)
48
+ thread_safe (0.3.6)
49
+ tzinfo (1.2.9)
50
+ thread_safe (~> 0.1)
51
+
52
+ PLATFORMS
53
+ ruby
54
+
55
+ DEPENDENCIES
56
+ activerecord (~> 5.1.0)
57
+ appraisal
58
+ backhoe!
59
+ byebug
60
+ mysql2
61
+ rake (~> 10.0)
62
+ rspec (~> 3.0)
63
+
64
+ BUNDLED WITH
65
+ 2.2.32
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~>5.2.0"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,65 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ backhoe (0.4.1)
5
+ activerecord
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activemodel (5.2.4.4)
11
+ activesupport (= 5.2.4.4)
12
+ activerecord (5.2.4.4)
13
+ activemodel (= 5.2.4.4)
14
+ activesupport (= 5.2.4.4)
15
+ arel (>= 9.0)
16
+ activesupport (5.2.4.4)
17
+ concurrent-ruby (~> 1.0, >= 1.0.2)
18
+ i18n (>= 0.7, < 2)
19
+ minitest (~> 5.1)
20
+ tzinfo (~> 1.1)
21
+ appraisal (2.3.0)
22
+ bundler
23
+ rake
24
+ thor (>= 0.14.0)
25
+ arel (9.0.0)
26
+ byebug (11.1.3)
27
+ concurrent-ruby (1.1.8)
28
+ diff-lcs (1.4.4)
29
+ i18n (1.8.7)
30
+ concurrent-ruby (~> 1.0)
31
+ minitest (5.14.3)
32
+ mysql2 (0.5.3)
33
+ rake (10.5.0)
34
+ rspec (3.10.0)
35
+ rspec-core (~> 3.10.0)
36
+ rspec-expectations (~> 3.10.0)
37
+ rspec-mocks (~> 3.10.0)
38
+ rspec-core (3.10.1)
39
+ rspec-support (~> 3.10.0)
40
+ rspec-expectations (3.10.1)
41
+ diff-lcs (>= 1.2.0, < 2.0)
42
+ rspec-support (~> 3.10.0)
43
+ rspec-mocks (3.10.2)
44
+ diff-lcs (>= 1.2.0, < 2.0)
45
+ rspec-support (~> 3.10.0)
46
+ rspec-support (3.10.2)
47
+ thor (1.1.0)
48
+ thread_safe (0.3.6)
49
+ tzinfo (1.2.9)
50
+ thread_safe (~> 0.1)
51
+
52
+ PLATFORMS
53
+ ruby
54
+
55
+ DEPENDENCIES
56
+ activerecord (~> 5.2.0)
57
+ appraisal
58
+ backhoe!
59
+ byebug
60
+ mysql2
61
+ rake (~> 10.0)
62
+ rspec (~> 3.0)
63
+
64
+ BUNDLED WITH
65
+ 2.2.32
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~>6.0.0"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,65 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ backhoe (0.4.1)
5
+ activerecord
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activemodel (6.0.3.4)
11
+ activesupport (= 6.0.3.4)
12
+ activerecord (6.0.3.4)
13
+ activemodel (= 6.0.3.4)
14
+ activesupport (= 6.0.3.4)
15
+ activesupport (6.0.3.4)
16
+ concurrent-ruby (~> 1.0, >= 1.0.2)
17
+ i18n (>= 0.7, < 2)
18
+ minitest (~> 5.1)
19
+ tzinfo (~> 1.1)
20
+ zeitwerk (~> 2.2, >= 2.2.2)
21
+ appraisal (2.3.0)
22
+ bundler
23
+ rake
24
+ thor (>= 0.14.0)
25
+ byebug (11.1.3)
26
+ concurrent-ruby (1.1.8)
27
+ diff-lcs (1.4.4)
28
+ i18n (1.8.7)
29
+ concurrent-ruby (~> 1.0)
30
+ minitest (5.14.3)
31
+ mysql2 (0.5.3)
32
+ rake (10.5.0)
33
+ rspec (3.10.0)
34
+ rspec-core (~> 3.10.0)
35
+ rspec-expectations (~> 3.10.0)
36
+ rspec-mocks (~> 3.10.0)
37
+ rspec-core (3.10.1)
38
+ rspec-support (~> 3.10.0)
39
+ rspec-expectations (3.10.1)
40
+ diff-lcs (>= 1.2.0, < 2.0)
41
+ rspec-support (~> 3.10.0)
42
+ rspec-mocks (3.10.2)
43
+ diff-lcs (>= 1.2.0, < 2.0)
44
+ rspec-support (~> 3.10.0)
45
+ rspec-support (3.10.2)
46
+ thor (1.1.0)
47
+ thread_safe (0.3.6)
48
+ tzinfo (1.2.9)
49
+ thread_safe (~> 0.1)
50
+ zeitwerk (2.4.2)
51
+
52
+ PLATFORMS
53
+ ruby
54
+
55
+ DEPENDENCIES
56
+ activerecord (~> 6.0.0)
57
+ appraisal
58
+ backhoe!
59
+ byebug
60
+ mysql2
61
+ rake (~> 10.0)
62
+ rspec (~> 3.0)
63
+
64
+ BUNDLED WITH
65
+ 2.2.32
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~>6.1.0"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,64 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ backhoe (0.4.1)
5
+ activerecord
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activemodel (6.1.1)
11
+ activesupport (= 6.1.1)
12
+ activerecord (6.1.1)
13
+ activemodel (= 6.1.1)
14
+ activesupport (= 6.1.1)
15
+ activesupport (6.1.1)
16
+ concurrent-ruby (~> 1.0, >= 1.0.2)
17
+ i18n (>= 1.6, < 2)
18
+ minitest (>= 5.1)
19
+ tzinfo (~> 2.0)
20
+ zeitwerk (~> 2.3)
21
+ appraisal (2.3.0)
22
+ bundler
23
+ rake
24
+ thor (>= 0.14.0)
25
+ byebug (11.1.3)
26
+ concurrent-ruby (1.1.8)
27
+ diff-lcs (1.4.4)
28
+ i18n (1.8.7)
29
+ concurrent-ruby (~> 1.0)
30
+ minitest (5.14.3)
31
+ mysql2 (0.5.3)
32
+ rake (10.5.0)
33
+ rspec (3.10.0)
34
+ rspec-core (~> 3.10.0)
35
+ rspec-expectations (~> 3.10.0)
36
+ rspec-mocks (~> 3.10.0)
37
+ rspec-core (3.10.1)
38
+ rspec-support (~> 3.10.0)
39
+ rspec-expectations (3.10.1)
40
+ diff-lcs (>= 1.2.0, < 2.0)
41
+ rspec-support (~> 3.10.0)
42
+ rspec-mocks (3.10.2)
43
+ diff-lcs (>= 1.2.0, < 2.0)
44
+ rspec-support (~> 3.10.0)
45
+ rspec-support (3.10.2)
46
+ thor (1.1.0)
47
+ tzinfo (2.0.4)
48
+ concurrent-ruby (~> 1.0)
49
+ zeitwerk (2.4.2)
50
+
51
+ PLATFORMS
52
+ ruby
53
+
54
+ DEPENDENCIES
55
+ activerecord (~> 6.1.0)
56
+ appraisal
57
+ backhoe!
58
+ byebug
59
+ mysql2
60
+ rake (~> 10.0)
61
+ rspec (~> 3.0)
62
+
63
+ BUNDLED WITH
64
+ 2.2.32
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~>7.0.0"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,62 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ backhoe (0.4.1)
5
+ activerecord
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activemodel (7.0.1)
11
+ activesupport (= 7.0.1)
12
+ activerecord (7.0.1)
13
+ activemodel (= 7.0.1)
14
+ activesupport (= 7.0.1)
15
+ activesupport (7.0.1)
16
+ concurrent-ruby (~> 1.0, >= 1.0.2)
17
+ i18n (>= 1.6, < 2)
18
+ minitest (>= 5.1)
19
+ tzinfo (~> 2.0)
20
+ appraisal (2.4.1)
21
+ bundler
22
+ rake
23
+ thor (>= 0.14.0)
24
+ byebug (11.1.3)
25
+ concurrent-ruby (1.1.9)
26
+ diff-lcs (1.5.0)
27
+ i18n (1.8.11)
28
+ concurrent-ruby (~> 1.0)
29
+ minitest (5.15.0)
30
+ mysql2 (0.5.3)
31
+ rake (10.5.0)
32
+ rspec (3.10.0)
33
+ rspec-core (~> 3.10.0)
34
+ rspec-expectations (~> 3.10.0)
35
+ rspec-mocks (~> 3.10.0)
36
+ rspec-core (3.10.1)
37
+ rspec-support (~> 3.10.0)
38
+ rspec-expectations (3.10.2)
39
+ diff-lcs (>= 1.2.0, < 2.0)
40
+ rspec-support (~> 3.10.0)
41
+ rspec-mocks (3.10.2)
42
+ diff-lcs (>= 1.2.0, < 2.0)
43
+ rspec-support (~> 3.10.0)
44
+ rspec-support (3.10.3)
45
+ thor (1.2.1)
46
+ tzinfo (2.0.4)
47
+ concurrent-ruby (~> 1.0)
48
+
49
+ PLATFORMS
50
+ x86_64-linux
51
+
52
+ DEPENDENCIES
53
+ activerecord (~> 7.0.0)
54
+ appraisal
55
+ backhoe!
56
+ byebug
57
+ mysql2
58
+ rake (~> 10.0)
59
+ rspec (~> 3.0)
60
+
61
+ BUNDLED WITH
62
+ 2.2.32
@@ -0,0 +1,14 @@
1
+ require "rake"
2
+
3
+ module Backhoe
4
+ class Base < Struct.new(:config, :file_path)
5
+ include Rake::DSL
6
+
7
+ private
8
+
9
+ def database
10
+ config["database"]
11
+ end
12
+ end
13
+ end
14
+
@@ -0,0 +1,96 @@
1
+ require "backhoe/base"
2
+
3
+ module Backhoe
4
+ class Mysql < Base
5
+ def dump skip_tables: []
6
+ mysqldump = `which mysqldump`.strip
7
+ raise RuntimeError, "Cannot find mysqldump." if mysqldump.blank?
8
+ sh "#{mysqldump} --no-create-db --single-transaction --quick -e #{skip_table_options(skip_tables)} #{mysql_options} > #{file_path}"
9
+ end
10
+
11
+ def load
12
+ mysql = `which mysql`.strip
13
+ raise RuntimeError, "Cannot find mysql." if mysql.blank?
14
+ sh "#{mysql} #{mysql_options} < #{file_path}"
15
+ end
16
+
17
+ private
18
+
19
+ def skip_table_options skip_tables
20
+ skip_tables.map do |table|
21
+ "--ignore-table=#{config["database"]}.#{table}"
22
+ end.join(" ")
23
+ end
24
+
25
+ def mysql_options
26
+ options = " -u #{config["username"]}"
27
+ options += " -p'#{config["password"]}'" if config["password"]
28
+ options += " -h #{config["host"]}" if config["host"]
29
+ options += " -S #{config["socket"]}" if config["socket"]
30
+ options += " '#{config["database"]}'"
31
+ end
32
+ end
33
+
34
+ module MysqlSkipColumns
35
+ def dump **options
36
+ if skip_columns = options.delete(:skip_columns)
37
+ SanitizedDatabase.new(skip_columns, file_path).dump do |skip_tables|
38
+ options[:skip_tables] ||= []
39
+ options[:skip_tables] += skip_tables
40
+ super **options
41
+ end
42
+ else
43
+ super
44
+ end
45
+ end
46
+
47
+ private
48
+
49
+ class SanitizedDatabase < Struct.new(:config, :file_path)
50
+ def dump
51
+ with_sanitized_tables do
52
+ yield skip_tables
53
+ end
54
+ skip_tables.each do |table|
55
+ File.write file_path, "RENAME TABLE `sanitized_#{table}` TO `#{table}`;", mode: "a"
56
+ end
57
+ end
58
+
59
+ private
60
+
61
+ def skip_tables
62
+ config.keys
63
+ end
64
+
65
+ def with_sanitized_tables
66
+ ActiveRecord::Base.transaction do
67
+ config.each do |table, columns|
68
+ sanitized_table = "sanitized_#{table}"
69
+ sql <<-SQL
70
+ DROP TABLE IF EXISTS `#{sanitized_table}`;
71
+ CREATE TABLE `#{sanitized_table}` LIKE `#{table}`;
72
+ INSERT INTO `#{sanitized_table}` SELECT * FROM `#{table}`;
73
+ ALTER TABLE `#{sanitized_table}` #{columns.map { |column| "DROP `#{column}`" }.join(", ")};
74
+ SQL
75
+ end
76
+
77
+ yield
78
+
79
+ config.each do |table, _|
80
+ sql "DROP TABLE `sanitized_#{table}`"
81
+ end
82
+ end
83
+ end
84
+
85
+ def sql queries
86
+ queries.split(";").select(&:present?).each do |query|
87
+ ActiveRecord::Base.connection.execute query
88
+ end
89
+ end
90
+ end
91
+ end
92
+ Mysql.prepend MysqlSkipColumns
93
+
94
+ Mysql2 = Mysql
95
+ end
96
+
@@ -0,0 +1,18 @@
1
+ require "backhoe/base"
2
+
3
+ module Backhoe
4
+ class Postgresql < Base
5
+ def dump **_
6
+ pg_dump = `which pg_dump`.strip
7
+ raise RuntimeError, "Cannot find pg_dump." if pg_dump.blank?
8
+ sh "#{pg_dump} -c -f#{file_path} #{database}"
9
+ end
10
+
11
+ def load
12
+ psql = `which psql`.strip
13
+ raise RuntimeError, "Cannot find psql." if psql.blank?
14
+ sh "#{psql} -P pager=off -q -d#{database} -f#{file_path}"
15
+ end
16
+ end
17
+ end
18
+
@@ -0,0 +1,15 @@
1
+ require "backhoe/base"
2
+ require "fileutils"
3
+
4
+ module Backhoe
5
+ class Sqlite3 < Base
6
+ def dump **_
7
+ FileUtils.cp database, file_path
8
+ end
9
+
10
+ def load
11
+ FileUtils.cp file_path, database
12
+ end
13
+ end
14
+ end
15
+
@@ -1,3 +1,3 @@
1
1
  module Backhoe
2
- VERSION = "0.2.0"
2
+ VERSION = "0.5.0"
3
3
  end
data/lib/backhoe.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  require "backhoe/version"
2
- require "rake"
3
- require "fileutils"
2
+ require "backhoe/mysql"
3
+ require "backhoe/postgresql"
4
+ require "backhoe/sqlite"
5
+ require "active_record"
4
6
 
5
7
  module Backhoe
6
8
  mattr_accessor(:file_path) { "db/data.sql" }
@@ -21,73 +23,19 @@ module Backhoe
21
23
  end
22
24
 
23
25
  def database_config
24
- ActiveRecord::Base.configurations[Rails.env || "development"]
25
- end
26
- end
27
-
28
- class Base < Struct.new(:config, :file_path)
29
- include Rake::DSL
30
-
31
- private
32
-
33
- def database
34
- config["database"]
35
- end
36
- end
37
-
38
- class Mysql < Base
39
- def dump skip_tables: []
40
- mysqldump = `which mysqldump`.strip
41
- raise RuntimeError, "Cannot find mysqldump." if mysqldump.blank?
42
- sh "#{mysqldump} --no-create-db --single-transaction --quick -e #{skip_table_options(skip_tables)} #{mysql_options} > #{file_path}"
43
- end
44
-
45
- def load
46
- mysql = `which mysql`.strip
47
- raise RuntimeError, "Cannot find mysql." if mysql.blank?
48
- sh "#{mysql} #{mysql_options} < #{file_path}"
49
- end
50
-
51
- private
52
-
53
- def skip_table_options skip_tables
54
- skip_tables.map do |table|
55
- "--ignore-table=#{config["database"]}.#{table}"
56
- end.join(" ")
57
- end
58
-
59
- def mysql_options
60
- options = " -u #{config["username"]}"
61
- options += " -p'#{config["password"]}'" if config["password"]
62
- options += " -h #{config["host"]}" if config["host"]
63
- options += " -S #{config["socket"]}" if config["socket"]
64
- options += " '#{config["database"]}'"
65
- end
66
- end
67
-
68
- Mysql2 = Mysql
69
-
70
- class Sqlite3 < Base
71
- def dump **_
72
- FileUtils.cp database, file_path
73
- end
74
-
75
- def load
76
- FileUtils.cp file_path, database
77
- end
78
- end
79
-
80
- class Postgresql < Base
81
- def dump **_
82
- pg_dump = `which pg_dump`.strip
83
- raise RuntimeError, "Cannot find pg_dump." if pg_dump.blank?
84
- sh "#{pg_dump} -c -f#{file_path} #{database}"
85
- end
86
-
87
- def load
88
- psql = `which psql`.strip
89
- raise RuntimeError, "Cannot find psql." if psql.blank?
90
- sh "#{psql} -q -d#{database} -f#{file_path}"
26
+ env = Rails.env || "development"
27
+ configs = ActiveRecord::Base.configurations
28
+ hash = if configs.respond_to?(:configs_for)
29
+ config = configs.configs_for(env_name: env).first
30
+ if config.respond_to?(:configuration_hash)
31
+ config.configuration_hash # rails 7
32
+ else
33
+ config.config # rails 6
34
+ end
35
+ else
36
+ configs[env] # rails 5
37
+ end
38
+ HashWithIndifferentAccess.new(hash)
91
39
  end
92
40
  end
93
41
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: backhoe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Micah Geisel
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-05-12 00:00:00.000000000 Z
11
+ date: 2022-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bundler
14
+ name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.16'
20
- type: :development
19
+ version: '0'
20
+ type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.16'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +52,48 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: appraisal
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mysql2
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: byebug
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
55
97
  description: Dump and load current database to and from a file.
56
98
  email:
57
99
  - micah@botandrose.com
@@ -59,9 +101,10 @@ executables: []
59
101
  extensions: []
60
102
  extra_rdoc_files: []
61
103
  files:
104
+ - ".github/workflows/ci.yml"
62
105
  - ".gitignore"
63
106
  - ".rspec"
64
- - ".travis.yml"
107
+ - Appraisals
65
108
  - Gemfile
66
109
  - LICENSE.txt
67
110
  - README.md
@@ -69,7 +112,22 @@ files:
69
112
  - backhoe.gemspec
70
113
  - bin/console
71
114
  - bin/setup
115
+ - gemfiles/.bundle/config
116
+ - gemfiles/activerecord_5.1.gemfile
117
+ - gemfiles/activerecord_5.1.gemfile.lock
118
+ - gemfiles/activerecord_5.2.gemfile
119
+ - gemfiles/activerecord_5.2.gemfile.lock
120
+ - gemfiles/activerecord_6.0.gemfile
121
+ - gemfiles/activerecord_6.0.gemfile.lock
122
+ - gemfiles/activerecord_6.1.gemfile
123
+ - gemfiles/activerecord_6.1.gemfile.lock
124
+ - gemfiles/activerecord_7.0.gemfile
125
+ - gemfiles/activerecord_7.0.gemfile.lock
72
126
  - lib/backhoe.rb
127
+ - lib/backhoe/base.rb
128
+ - lib/backhoe/mysql.rb
129
+ - lib/backhoe/postgresql.rb
130
+ - lib/backhoe/sqlite.rb
73
131
  - lib/backhoe/version.rb
74
132
  homepage: https://github.com/botandrose/backhoe
75
133
  licenses:
@@ -90,8 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
148
  - !ruby/object:Gem::Version
91
149
  version: '0'
92
150
  requirements: []
93
- rubyforge_project:
94
- rubygems_version: 2.6.14
151
+ rubygems_version: 3.2.32
95
152
  signing_key:
96
153
  specification_version: 4
97
154
  summary: Dump and load current database to and from a file.
data/.travis.yml DELETED
@@ -1,5 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.2.1
5
- before_install: gem install bundler -v 1.16.1