switch_db 0.1.1 → 0.2.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
  SHA1:
3
- metadata.gz: ec1149cc9d5c6d0bb34390a1503fe6048f780c17
4
- data.tar.gz: b10f6db84a00e097292099b8e7aaf0fa8a5d0248
3
+ metadata.gz: 945496d9ebd771617bc253c3743cdbd675de078b
4
+ data.tar.gz: 97a4393635ea2f29830c01a11e3954481ec62b5f
5
5
  SHA512:
6
- metadata.gz: 611341244196f13828eadd38516d203b65199993630f665fcbeccd8d113843c667ac6e55ee9d2d306c836fb9436f431299880f722001dbd933b2a53ca7561ca2
7
- data.tar.gz: fe39838ca4125c47dca1bfed4171e24fb49e74922cd16ea8e47cd9de935dcae0c2742c45c31afb56a461c7baa7f13e269331c756ae6e25085d71eab00becc695
6
+ metadata.gz: a8724eb15a5e842589e44cb431ceb6ac17cdfeda8daf21f762be5c82cba18c07958f1390cc5429945767102c299c731c0fe27045c7430c5df33a578c996e98f4
7
+ data.tar.gz: cc25b516a169b16253fe869b83be28588cf45f59245a80a6db50ec68aad8f54105ca6fade2d43213bbec5806be3b958b44b5aaef495e40826cdcfff064d3ad17
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.3.5
1
+ 2.4.1
data/README.md CHANGED
@@ -69,9 +69,6 @@ Restored database a 'application_test'
69
69
 
70
70
  # Set default username and password
71
71
  switch_db config user_name:root password:password
72
-
73
- # Remove config
74
- switch_db config user_name: password:
75
72
  ```
76
73
 
77
74
  ## Development
data/bin/switch_db CHANGED
@@ -1,8 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
4
- require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
5
-
6
3
  $LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
7
4
 
8
5
  require 'switch_db'
data/lib/switch_db/cli.rb CHANGED
@@ -3,8 +3,9 @@ module SwitchDb
3
3
  class << self
4
4
  def run!(command, arguments = {})
5
5
  command_class = command_for(command)
6
- reference_set = ReferenceSet.load_from_directory(SwitchDb.configuration.cache_dir)
6
+ reference_set = ReferenceSet.load_file(SwitchDb.configuration.reference_set_file_full_path)
7
7
  command_class.new(reference_set: reference_set).run(arguments)
8
+ reference_set.write_reference_set
8
9
  end
9
10
 
10
11
  private
@@ -13,16 +13,13 @@ module SwitchDb
13
13
 
14
14
  database = SwitchDb::Database.current_database
15
15
 
16
- threads = reference.database_paths.map do |database_name, database_path|
17
- Thread.new do
18
- database.drop_database(database_name)
19
- database.create_database(database_name)
20
- database.import_database(database_name, database_path)
21
- puts "Restored database a '#{database_name}'"
22
- end
23
- end
16
+ reference.database_paths.each do |database_name, database_path|
17
+ database.drop_database(database_name)
18
+ database.create_database(database_name)
19
+ database.import_database(database_name, database_path)
24
20
 
25
- threads.each(&:join)
21
+ puts "Restored database a '#{database_name}'"
22
+ end
26
23
  end
27
24
  end
28
25
  end
@@ -3,14 +3,14 @@ require 'fileutils'
3
3
  module SwitchDb
4
4
  module Command
5
5
  class Store < Base
6
- def run(name:, database_names: [], force: false)
6
+ def run(name:, database_names: [])
7
7
  reference = SwitchDb::Reference.new(name: name, database_names: database_names)
8
8
  duplicated = @reference_set.references.key?(reference.name)
9
9
 
10
10
  FileUtils.mkdir_p(reference.full_path)
11
11
 
12
12
  reference.database_paths.each do |database_name, database_path|
13
- next if !force && duplicated && !overwrite?(reference)
13
+ next if duplicated && !overwrite?(reference)
14
14
 
15
15
  SwitchDb::Database.current_database.dump_database(database_name, database_path)
16
16
  puts "Stored database a '#{database_name}'"
@@ -5,11 +5,13 @@ module SwitchDb
5
5
  class Configuration
6
6
  attr_reader :config_file
7
7
  attr_reader :cache_dir
8
+ attr_accessor :reference_set_file
8
9
  attr_accessor :user_name
9
10
  attr_accessor :password
10
11
 
11
12
  def initialize
12
13
  @config_file = 'config.yml'
14
+ @reference_set_file = 'reference_set.yml'
13
15
  @cache_dir = Pathname.new(File.expand_path('~/.cache/switch_db'))
14
16
  @user_name = 'root'
15
17
  @password = nil
@@ -17,11 +19,16 @@ module SwitchDb
17
19
  load_from_config_file(configuration_full_path)
18
20
  end
19
21
 
22
+ def reference_set_file_full_path
23
+ cache_dir.join(reference_set_file)
24
+ end
25
+
20
26
  def to_h
21
27
  {
28
+ reference_set_file: reference_set_file,
22
29
  user_name: user_name,
23
30
  password: password
24
- }.delete_if { |_, value| value.nil? || value.empty? }
31
+ }
25
32
  end
26
33
 
27
34
  def write_configuration_file
@@ -31,6 +38,7 @@ module SwitchDb
31
38
 
32
39
  def configuration_keys
33
40
  %i[
41
+ reference_set_file
34
42
  user_name
35
43
  password
36
44
  ]
@@ -79,8 +79,6 @@ module SwitchDb
79
79
  case option_name
80
80
  when 'database_names'
81
81
  @options[:database_names] = value.to_s.split(/(?:,|\s+)/)
82
- when 'force'
83
- @options[:force] = true
84
82
  when 'help'
85
83
  puts banner
86
84
  exit
@@ -103,7 +101,7 @@ module SwitchDb
103
101
  switch_db list
104
102
  switch_db config [key:value...]
105
103
  switch_db rm <name>
106
- switch_db store <name> --database_names [database_name,database_name...] [--force]
104
+ switch_db store <name> --database_names [database_name,database_name...]
107
105
  switch_db restore <name>
108
106
 
109
107
  Examples:
@@ -1,35 +1,30 @@
1
1
  require 'fileutils'
2
- require 'pathname'
3
2
  require 'yaml'
4
3
 
5
4
  module SwitchDb
6
5
  class ReferenceSet
7
- attr_reader :directory_path, :references
6
+ attr_reader :configuration_path, :references
8
7
 
9
- def initialize(directory_path)
10
- @directory_path = directory_path
8
+ def initialize(configuration_path)
9
+ @configuration_path = configuration_path
11
10
  @references = {}
12
11
  end
13
12
 
14
- def self.load_from_directory(directory_path)
15
- new(directory_path).tap do |instance|
16
- directories = Dir[File.join(directory_path, '*')].select { |path| File.directory?(path) }
17
-
18
- directories.each do |path|
19
- reference_name = File.basename(path)
20
- sql_file_paths = Dir[File.join(path, '*.sql')].select { |file_path| File.file?(file_path) }
21
- database_names = sql_file_paths.map { |file_path| File.basename(file_path).gsub(/\.sql$/, '') }
13
+ def self.load_file(configuration_path)
14
+ new(configuration_path).tap do |instance|
15
+ yaml = YAML.load_file(configuration_path)
22
16
 
17
+ (yaml[:references] || []).map do |reference|
23
18
  reference = Reference.new(
24
- name: reference_name,
25
- database_names: database_names
19
+ name: reference[:name],
20
+ database_names: reference[:database_names]
26
21
  )
27
22
 
28
23
  instance.add_reference(reference)
29
24
  end
30
25
  end
31
26
  rescue Errno::ENOENT
32
- new(directory_path)
27
+ new(configuration_path)
33
28
  end
34
29
 
35
30
  def add_reference(reference)
@@ -40,6 +35,11 @@ module SwitchDb
40
35
  @references.delete(reference.name)
41
36
  end
42
37
 
38
+ def write_reference_set
39
+ FileUtils.mkdir_p(configuration_directory)
40
+ File.write(@configuration_path, to_h.to_yaml)
41
+ end
42
+
43
43
  private
44
44
 
45
45
  def to_h
@@ -47,5 +47,9 @@ module SwitchDb
47
47
  references: references.values.map(&:to_h)
48
48
  }
49
49
  end
50
+
51
+ def configuration_directory
52
+ File.dirname(@configuration_path)
53
+ end
50
54
  end
51
55
  end
@@ -1,3 +1,3 @@
1
1
  module SwitchDb
2
- VERSION = '0.1.1'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: switch_db
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - alpaca-tc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-22 00:00:00.000000000 Z
11
+ date: 2018-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -70,8 +70,6 @@ files:
70
70
  - LICENSE.txt
71
71
  - README.md
72
72
  - Rakefile
73
- - bin/console
74
- - bin/setup
75
73
  - bin/switch_db
76
74
  - lib/switch_db.rb
77
75
  - lib/switch_db/cli.rb
@@ -114,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
112
  version: '0'
115
113
  requirements: []
116
114
  rubyforge_project:
117
- rubygems_version: 2.5.2.1
115
+ rubygems_version: 2.6.11
118
116
  signing_key:
119
117
  specification_version: 4
120
118
  summary: A command-line interface for a database dumpfile
data/bin/console DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "switch_db"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start(__FILE__)
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here