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 +4 -4
- data/.ruby-version +1 -1
- data/README.md +0 -3
- data/bin/switch_db +0 -3
- data/lib/switch_db/cli.rb +2 -1
- data/lib/switch_db/command/restore.rb +6 -9
- data/lib/switch_db/command/store.rb +2 -2
- data/lib/switch_db/configuration.rb +9 -1
- data/lib/switch_db/option_parser.rb +1 -3
- data/lib/switch_db/reference_set.rb +19 -15
- data/lib/switch_db/version.rb +1 -1
- metadata +3 -5
- data/bin/console +0 -14
- data/bin/setup +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 945496d9ebd771617bc253c3743cdbd675de078b
|
4
|
+
data.tar.gz: 97a4393635ea2f29830c01a11e3954481ec62b5f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8724eb15a5e842589e44cb431ceb6ac17cdfeda8daf21f762be5c82cba18c07958f1390cc5429945767102c299c731c0fe27045c7430c5df33a578c996e98f4
|
7
|
+
data.tar.gz: cc25b516a169b16253fe869b83be28588cf45f59245a80a6db50ec68aad8f54105ca6fade2d43213bbec5806be3b958b44b5aaef495e40826cdcfff064d3ad17
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.4.1
|
data/README.md
CHANGED
data/bin/switch_db
CHANGED
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.
|
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
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
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
|
-
|
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: []
|
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
|
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
|
-
}
|
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...]
|
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 :
|
6
|
+
attr_reader :configuration_path, :references
|
8
7
|
|
9
|
-
def initialize(
|
10
|
-
@
|
8
|
+
def initialize(configuration_path)
|
9
|
+
@configuration_path = configuration_path
|
11
10
|
@references = {}
|
12
11
|
end
|
13
12
|
|
14
|
-
def self.
|
15
|
-
new(
|
16
|
-
|
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:
|
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(
|
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
|
data/lib/switch_db/version.rb
CHANGED
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.
|
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:
|
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.
|
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__)
|