geordi 9.0.0 → 9.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1060f10e77e6173a1b8d63fd8c2d89579e5be0597a683f5358b01173e4c266de
4
- data.tar.gz: 8a44e3cd313e779b84ae9ecfa0f92283f4dd3f45f7525ec0bc298b11a719c389
3
+ metadata.gz: 337e7767788852ee10b537112f4151f4b12e267740fa20557b7786e12babd97d
4
+ data.tar.gz: 0dd146812562eb28fa115cbbdefa1bffcc8b172f1b509d44414bcca667ce3774
5
5
  SHA512:
6
- metadata.gz: c7793fda9e1494d3b1a2cf50dfa7b8c10ff61e8c7462596828fe6e44721f50dedbfe18ba2a2c2fb4e0b354500de9528f6e948e8716c9c1a31ceb42a49c8ea845
7
- data.tar.gz: fedd7f3106bc5283b25b5f4e20fe1eda099d76c7e4b01483362cebde5cca516d559241d976ad51486a3bc71e11df5a3c21d14288c10805ad9af8307f48d7dab3
6
+ metadata.gz: '07256569d49cf31224e4a69d5fc0e240d9c8df820e527fd615b1e5956f320fa01077572b4e79401bf7a5ee8b8d9bf135b94c369ef807a2bc40c36aa76eb7180a'
7
+ data.tar.gz: 18bf3b9d1026575a5c0c3d33281de6b211ffa38c8c0d316656c6aee90bcdc2b81e5cec2feae0f006f2ef3fb8458834c1813dcd8d2aff5adcdf17bed732a06217
data/CHANGELOG.md CHANGED
@@ -11,10 +11,18 @@ This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html
11
11
  ### Breaking changes
12
12
 
13
13
 
14
+ ## 9.1.0 2022-02-14
15
+
16
+ ### Compatible changes
17
+ * `geordi dump` and `dumple` now default to "primary" database or the first
18
+ entry in a multi-db setup
19
+ * Also added feature tests for `dumple` and structured the script
20
+
21
+
14
22
  ## 9.0.0 2021-12-02
15
23
 
16
24
  ### Breaking changes
17
- * Remove the `geordi docker` command.
25
+ * Remove the `geordi docker` command set.
18
26
 
19
27
 
20
28
  ## 8.0.0 2021-11-08
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- geordi (9.0.0)
4
+ geordi (9.1.0)
5
5
  thor (~> 1)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -194,7 +194,9 @@ specified target's database and downloads it to `tmp/`.
194
194
  `geordi dump staging -l` (with a Capistrano deploy target and the `--load`
195
195
  option) sources the dump into the development database after downloading it.
196
196
 
197
- If you are using multiple databases per environment, pass the database name like this:
197
+ If you are using multiple databases per environment, Geordi defaults to the
198
+ "primary" database, or the first entry in database.yml. To dump a specific
199
+ database, pass the database name like this:
198
200
 
199
201
  geordi dump -d primary
200
202
 
data/exe/dumple CHANGED
@@ -1,28 +1,33 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'erb'
4
-
5
- fail_gently = ARGV.include?("--fail-gently")
6
- compress = ARGV.include?("--compress")
7
-
8
3
  if ARGV.include?("-i")
9
4
  puts "*******************************************************"
10
5
  puts
11
6
  system("du -sh ~/dumps")
12
7
  puts
13
8
  puts "*******************************************************"
9
+
14
10
  exit
15
11
  end
16
12
 
17
- ###
18
-
13
+ require 'erb'
19
14
  require "yaml"
20
- config_path = 'config/database.yml'
21
15
 
22
- begin
23
- # go to project root
16
+ DB_CONFIG_PATH = 'config/database.yml'
17
+ DUMPS_DIR = "#{ENV['HOME']}/dumps"
18
+
19
+ def run(*args)
20
+ if !!ENV['GEORDI_TESTING']
21
+ puts "system #{args.join(', ')}"
22
+ true # "Command succeeded"
23
+ else
24
+ system *args
25
+ end
26
+ end
27
+
28
+ def cd_to_project_root(fail_gently)
24
29
  current = Dir.pwd
25
- until (File.exists? config_path)
30
+ until File.exists?(DB_CONFIG_PATH)
26
31
  Dir.chdir '..'
27
32
  if current == Dir.pwd
28
33
  if fail_gently
@@ -38,46 +43,24 @@ begin
38
43
  sleep 5
39
44
  exit
40
45
  else
41
- raise "Call me from inside a Rails project."
46
+ raise "x Call me from inside a Rails project."
42
47
  end
43
48
  end
44
49
  current = Dir.pwd
45
50
  end
51
+ end
46
52
 
47
- config = YAML::load(ERB.new(File.read(config_path)).result)
48
- environment, database = ARGV.reject{ |arg| arg[0].chr == '-' }
49
- environment ||= 'production'
50
- config = config[environment] or raise "No #{environment} database found.\nUsage: dumple ENVIRONMENT [DATABASE]"
51
-
52
- if database
53
- config = config[database] or raise %(Unknown #{environment} database "#{database}")
54
- end
55
-
56
- dump_dir = "#{ENV['HOME']}/dumps"
57
- unless File.directory?(dump_dir)
58
- Dir.mkdir(dump_dir)
59
- system("chmod 700 #{dump_dir}")
60
- end
61
-
62
- if ARGV.find{ |arg| arg == '--for_download'}
63
- dump_path = "#{dump_dir}/dump_for_download.dump"
64
- else
65
- dump_path = "#{dump_dir}/#{config['database']}_#{Time.now.strftime("%Y%m%d_%H%M%S")}.dump"
66
- end
67
-
68
- given_database = database ? %(#{database} ) : ""
69
- puts "> Dumping #{given_database}database for \"#{environment}\" environment ..."
70
-
53
+ def dump_command(dump_file, config)
71
54
  host = config['host']
72
55
  port = config['port']
73
56
 
74
- dump_command = case config['adapter']
57
+ case config['adapter']
75
58
  when /mysql/
76
59
  command = "mysqldump"
77
60
  command << " -u\"#{config['username']}\""
78
61
  command << " -p\"#{config['password']}\""
79
62
  command << " #{config['database']}"
80
- command << " -r #{dump_path}"
63
+ command << " -r #{dump_file}"
81
64
  # Using a transaction to allow concurrent request while creating a dump.
82
65
  # This works only reliable for InnoDB tables.
83
66
  # More details: https://dev.mysql.com/doc/refman/5.7/en/mysqldump.html#option_mysqldump_single-transaction
@@ -96,25 +79,75 @@ begin
96
79
  command << " pg_dump #{config['database']}"
97
80
  command << " --clean"
98
81
  command << " --format=custom"
99
- command << " --file=#{dump_path}"
82
+ command << " --file=#{dump_file}"
100
83
  command << " --username=\"#{config['username']}\""
101
84
  command << " --host=#{host}" if host
102
85
  command << " --port=#{port}" if port
103
86
  command
104
87
  else
105
- raise "Adapter \"#{config['adapter']}\" is not supported"
88
+ raise %(x Adapter "#{config['adapter']}" is not supported.)
89
+ end
90
+ end
91
+
92
+ def find_database_config(config_path, environment, database)
93
+ environment ||= 'production'
94
+ database_yml = ERB.new(File.read(config_path)).result
95
+ config = YAML::load(database_yml)
96
+ config = config[environment] or raise "x No #{environment} database found.\nUsage: dumple ENVIRONMENT [DATABASE]"
97
+
98
+ if config.values[0].is_a? Hash # Multi-db setup
99
+ if database # Explicitly requested
100
+ config = config[database] or raise %(x Unknown #{environment} database "#{database}".)
101
+ elsif config.key? 'primary'
102
+ puts '> Multiple databases detected. Defaulting to primary database.'
103
+ config = config['primary']
104
+ else
105
+ puts "> Multiple databases detected. Defaulting to first entry (#{config.keys[0]})."
106
+ config = config.values[0]
107
+ end
108
+ else # Single-db setup
109
+ if database
110
+ raise %(x Could not select "#{database}" database in a single-db environment.)
111
+ end
106
112
  end
107
- success = system(dump_command)
108
- success or raise "Creating the dump failed"
109
113
 
110
- system "chmod 600 #{dump_path}"
114
+ config
115
+ end
116
+
117
+ def prepare_dump_path(config)
118
+ unless File.directory?(DUMPS_DIR)
119
+ Dir.mkdir(DUMPS_DIR)
120
+ run "chmod 700 #{DUMPS_DIR}"
121
+ end
122
+
123
+ if ARGV.include? '--for_download'
124
+ "#{DUMPS_DIR}/dump_for_download.dump"
125
+ else
126
+ "#{DUMPS_DIR}/#{config['database']}_#{Time.now.strftime("%Y%m%d_%H%M%S")}.dump"
127
+ end
128
+ end
129
+
130
+ begin
131
+ fail_gently = ARGV.include?("--fail-gently")
132
+ compress = ARGV.include?("--compress")
133
+ environment, database = ARGV.reject { |arg| arg[0].chr == '-' }
134
+
135
+ cd_to_project_root(fail_gently)
136
+ config = find_database_config(DB_CONFIG_PATH, environment, database)
137
+ dump_path = prepare_dump_path(config)
138
+
139
+ # Dump!
140
+ given_database = database ? %(#{database} ) : ""
141
+ command = dump_command(dump_path, config)
142
+ puts "> Dumping #{given_database}database for \"#{environment}\" environment ..."
143
+ run command or raise "x Creating the dump failed."
144
+ run "chmod 600 #{dump_path}"
111
145
 
112
146
  if compress
113
147
  puts "> Compressing the dump ..."
114
-
115
148
  # gzip compresses in place
116
- compress_success = system("gzip #{dump_path}")
117
- compress_success or raise "Compressing the dump failed"
149
+ compress_success = run "gzip #{dump_path}"
150
+ compress_success or raise "x Compressing the dump failed."
118
151
  dump_path << ".gz"
119
152
  end
120
153
 
data/geordi.gemspec CHANGED
@@ -13,6 +13,7 @@ Gem::Specification.new do |spec|
13
13
  spec.description = spec.summary
14
14
  spec.homepage = 'https://makandra.com'
15
15
  spec.license = 'MIT'
16
+ spec.metadata = { 'rubygems_mfa_required' => 'true' }
16
17
 
17
18
  # Specify which files should be added to the gem when it is released.
18
19
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
@@ -11,7 +11,9 @@ specified target's database and downloads it to `tmp/`.
11
11
  `geordi dump staging -l` (with a Capistrano deploy target and the `--load`
12
12
  option) sources the dump into the development database after downloading it.
13
13
 
14
- If you are using multiple databases per environment, pass the database name like this:
14
+ If you are using multiple databases per environment, Geordi defaults to the
15
+ "primary" database, or the first entry in database.yml. To dump a specific
16
+ database, pass the database name like this:
15
17
 
16
18
  geordi dump -d primary
17
19
 
@@ -26,9 +28,8 @@ def dump(target = nil, *_args)
26
28
  require 'geordi/remote'
27
29
  database = options[:database] ? "#{options[:database]} " : ''
28
30
 
29
- if target.nil?
30
- if options.load
31
- # validate load option
31
+ if target.nil? # Local …
32
+ if options.load # … dump loading
32
33
  Interaction.fail 'Missing a dump file.' if options.load == 'load'
33
34
  File.exist?(options.load) || raise('Could not find the given dump file: ' + options.load)
34
35
 
@@ -39,19 +40,19 @@ def dump(target = nil, *_args)
39
40
 
40
41
  Interaction.success "Your #{loader.config['database']} database has now the data of #{options.load}."
41
42
 
42
- else
43
+ else # … dump creation
43
44
  Interaction.announce 'Dumping the development database'
44
45
  Util.run!("dumple development #{database}")
45
46
  Interaction.success "Successfully dumped the #{database}development database."
46
47
  end
47
48
 
48
- else
49
+ else # Remote dumping …
49
50
  database_label = options[:database] ? " (#{database}database)" : ""
50
51
 
51
52
  Interaction.announce "Dumping the database of #{target}#{database_label}"
52
53
  dump_path = Geordi::Remote.new(target).dump(options)
53
54
 
54
- if options.load
55
+ if options.load # … and dump loading
55
56
  loader = DumpLoader.new(dump_path)
56
57
 
57
58
  Interaction.announce "Sourcing dump into the #{loader.config['database']} db"
@@ -1,3 +1,3 @@
1
1
  module Geordi
2
- VERSION = '9.0.0'.freeze
2
+ VERSION = '9.1.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geordi
3
3
  version: !ruby/object:Gem::Version
4
- version: 9.0.0
4
+ version: 9.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henning Koch
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-12-02 00:00:00.000000000 Z
11
+ date: 2022-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -96,11 +96,12 @@ files:
96
96
  homepage: https://makandra.com
97
97
  licenses:
98
98
  - MIT
99
- metadata: {}
99
+ metadata:
100
+ rubygems_mfa_required: 'true'
100
101
  post_install_message: 'Support for sequential running of integration tests tagged
101
102
  with @solo has been dropped.
102
103
 
103
- '
104
+ '
104
105
  rdoc_options: []
105
106
  require_paths:
106
107
  - lib
@@ -115,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
116
  - !ruby/object:Gem::Version
116
117
  version: '0'
117
118
  requirements: []
118
- rubygems_version: 3.2.32
119
+ rubygems_version: 3.0.3
119
120
  signing_key:
120
121
  specification_version: 4
121
122
  summary: Collection of command line tools we use in our daily work with Ruby, Rails