mysql-inspector 0.0.1 → 0.0.2
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.
- data/README +6 -6
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/bin/mysql-inspector +48 -35
- data/lib/mysql-inspector.rb +9 -3
- data/mysql-inspector.gemspec +2 -2
- metadata +3 -3
data/README
CHANGED
@@ -12,7 +12,7 @@ master, which adds a new column metal_grade.
|
|
12
12
|
|
13
13
|
Start by storing the new state of your database.
|
14
14
|
|
15
|
-
% mysql-inspector --target
|
15
|
+
% mysql-inspector --target --write zippers_development
|
16
16
|
|
17
17
|
This command says "store the state of the zippers_development database as my
|
18
18
|
target version".
|
@@ -20,7 +20,7 @@ target version".
|
|
20
20
|
Now, go back to your master branch and load its database into
|
21
21
|
zippers_development, then dump the contents.
|
22
22
|
|
23
|
-
% mysql-inspector --current
|
23
|
+
% mysql-inspector --current --write zippers_development
|
24
24
|
|
25
25
|
Now, in order to write database migrations for master to smoother let's see
|
26
26
|
what changes occurred.
|
@@ -35,11 +35,11 @@ information is right here.
|
|
35
35
|
|
36
36
|
mysql% alter table zippers add column metal_grade int(11) NOT NULL DEFAULT '0';
|
37
37
|
|
38
|
-
Now we can compare the two again. This time we need to add the --force
|
39
|
-
to say that it's ok to overwrite the previous dump.
|
38
|
+
Now we can compare the two again. This time we need to add the --force
|
39
|
+
argument to say that it's ok to overwrite the previous dump. We'll also go
|
40
|
+
ahead and run the diff.
|
40
41
|
|
41
|
-
% mysql-inspector --current zippers_development --
|
42
|
-
% mysql-inspector --diff
|
42
|
+
% mysql-inspector --current --write zippers_development --force --diff
|
43
43
|
|
44
44
|
No differences!
|
45
45
|
|
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/bin/mysql-inspector
CHANGED
@@ -4,73 +4,86 @@ require 'optparse'
|
|
4
4
|
require "lib/mysql-inspector"
|
5
5
|
|
6
6
|
options = {
|
7
|
-
:databases => [],
|
8
7
|
:versions => [],
|
9
8
|
:base_dir => ".",
|
10
9
|
:diff => false,
|
11
10
|
:grep => false,
|
12
|
-
:
|
11
|
+
:write => false,
|
13
12
|
:clean => false
|
14
13
|
}
|
15
14
|
|
16
15
|
OptionParser.new do |opts|
|
17
|
-
opts.banner = "Usage:
|
16
|
+
opts.banner = "Usage: #{File.basename $0} [options]"
|
18
17
|
|
19
|
-
opts.on("-c", "--current
|
18
|
+
opts.on("-c", "--current", "Perform the given action(s) with the current version.") do
|
20
19
|
options[:versions] << "current"
|
21
|
-
options[:databases] << db_name
|
22
20
|
end
|
23
21
|
|
24
|
-
opts.on("-t", "--target
|
22
|
+
opts.on("-t", "--target", "Perform the given action(s) with the target version.") do
|
25
23
|
options[:versions] << "target"
|
26
|
-
options[:databases] << db_name
|
27
24
|
end
|
28
25
|
|
29
|
-
opts.on("-w", "--write") do |
|
30
|
-
options[:
|
26
|
+
opts.on("-w", "--write DB", "Store a schema for the database") do |db_name|
|
27
|
+
options[:write] = db_name
|
31
28
|
end
|
32
29
|
|
33
|
-
opts.on("-f", "--force") do |ok|
|
30
|
+
opts.on("-f", "--force", "Overwrite a previously stored schema") do |ok|
|
34
31
|
options[:clean] = true
|
35
32
|
end
|
36
33
|
|
37
|
-
opts.on("-
|
34
|
+
opts.on("-d", "--diff", "Output a comparison between the current and target schemas") do |info|
|
35
|
+
options[:diff] = true
|
36
|
+
end
|
37
|
+
|
38
|
+
opts.on("-g", "--grep foo_id,bar_id", "Find columns and/or indices matching the pattern") do |columns|
|
38
39
|
options[:grep] = columns.split(",").collect { |c| c.strip }
|
39
40
|
end
|
40
41
|
|
41
|
-
opts.on("-
|
42
|
-
|
42
|
+
opts.on("-h", "--help", "What you're looking at") do
|
43
|
+
puts opts
|
43
44
|
end
|
44
45
|
|
45
|
-
|
46
|
+
puts opts if ARGV.empty?
|
46
47
|
|
47
|
-
|
48
|
-
options[:databases].compact!
|
48
|
+
end.parse!
|
49
49
|
|
50
|
-
|
51
|
-
|
50
|
+
def how_to_write_version(input)
|
51
|
+
"#{File.basename $0} --#{input.version} --write DB_NAME"
|
52
52
|
end
|
53
53
|
|
54
|
-
|
55
|
-
options[:versions].each { |v| v.clean! }
|
56
|
-
end
|
54
|
+
begin
|
57
55
|
|
58
|
-
|
59
|
-
|
60
|
-
options[:versions].zip(options[:databases]).each do |v, d|
|
61
|
-
v.dump!(d)
|
56
|
+
options[:versions].collect! do |version|
|
57
|
+
MysqlInspector::Dump.new(version, options[:base_dir])
|
62
58
|
end
|
63
|
-
end
|
64
59
|
|
65
|
-
if options[:
|
66
|
-
|
67
|
-
|
68
|
-
|
60
|
+
if options[:clean]
|
61
|
+
options[:versions].each { |v| v.clean! }
|
62
|
+
end
|
63
|
+
|
64
|
+
if options[:write]
|
65
|
+
raise MysqlInspector::Precondition, "Please specify which version to write" if options[:versions].size == 0
|
66
|
+
raise MysqlInspector::Precondition, "I can only write one version at a time" unless options[:versions].size == 1
|
67
|
+
version = options[:versions].first
|
68
|
+
version.dump!(options[:write])
|
69
|
+
end
|
70
|
+
|
71
|
+
if options[:grep]
|
72
|
+
options[:versions].each do |v|
|
73
|
+
grep = MysqlInspector::Grep.new(v)
|
74
|
+
grep.find(STDOUT, *options[:grep])
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
if options[:diff]
|
79
|
+
inputs = ["current", "target"].collect { |version| MysqlInspector::Dump.new(version, options[:base_dir]) }
|
80
|
+
inputs.each do |input|
|
81
|
+
raise MysqlInspector::Precondition, "No #{input.version} version exists. Write one with `#{how_to_write_version(input)}`" unless input.exists?
|
82
|
+
end
|
83
|
+
comparison = MysqlInspector::Comparison.new(*inputs)
|
84
|
+
comparison.compare(STDOUT)
|
69
85
|
end
|
70
|
-
end
|
71
86
|
|
72
|
-
|
73
|
-
|
74
|
-
comparison = MysqlInspector::Comparison.new(*inputs)
|
75
|
-
comparison.compare(STDOUT)
|
87
|
+
rescue MysqlInspector::Precondition => e
|
88
|
+
puts "#{e.message}."
|
76
89
|
end
|
data/lib/mysql-inspector.rb
CHANGED
@@ -2,6 +2,8 @@ require "fileutils"
|
|
2
2
|
|
3
3
|
module MysqlInspector
|
4
4
|
|
5
|
+
Precondition = Class.new(StandardError)
|
6
|
+
|
5
7
|
module Config
|
6
8
|
extend self
|
7
9
|
|
@@ -17,7 +19,7 @@ module MysqlInspector
|
|
17
19
|
def mysqldump_path
|
18
20
|
@mysqldump_path ||= begin
|
19
21
|
path = `which mysqldump`.chomp
|
20
|
-
raise "mysqldump was not in your path" if path.empty?
|
22
|
+
raise Precondition, "mysqldump was not in your path" if path.empty?
|
21
23
|
path
|
22
24
|
end
|
23
25
|
end
|
@@ -57,8 +59,12 @@ module MysqlInspector
|
|
57
59
|
FileUtils.rm_rf(dir)
|
58
60
|
end
|
59
61
|
|
62
|
+
def exists?
|
63
|
+
File.exist?(dir)
|
64
|
+
end
|
65
|
+
|
60
66
|
def dump!(db_name)
|
61
|
-
raise "
|
67
|
+
raise Precondition, "Can't overwrite an existing schema at #{dir.inspect}" if exists?
|
62
68
|
@db_name = db_name
|
63
69
|
FileUtils.mkdir_p(dir)
|
64
70
|
Config.mysqldump("--no-data", "-T #{dir}", "--skip-opt", db_name).run!
|
@@ -72,7 +78,7 @@ module MysqlInspector
|
|
72
78
|
end
|
73
79
|
|
74
80
|
def read_db_name
|
75
|
-
raise "No dump exists at #{dir.inspect}" unless File.exist?(info_file)
|
81
|
+
raise Precondition, "No dump exists at #{dir.inspect}" unless File.exist?(info_file)
|
76
82
|
File.read(info_file).strip
|
77
83
|
end
|
78
84
|
end
|
data/mysql-inspector.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{mysql-inspector}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Ryan Carver"]
|
12
|
-
s.date = %q{2010-03-
|
12
|
+
s.date = %q{2010-03-05}
|
13
13
|
s.default_executable = %q{mysql-inspector}
|
14
14
|
s.email = %q{ryan@fivesevensix.com}
|
15
15
|
s.executables = ["mysql-inspector"]
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Ryan Carver
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-03-
|
17
|
+
date: 2010-03-05 00:00:00 -08:00
|
18
18
|
default_executable: mysql-inspector
|
19
19
|
dependencies: []
|
20
20
|
|