mysql_rake_tasks 0.1.3 → 1.0.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 +7 -0
- data/{LICENSE → LICENSE.txt} +0 -0
- data/README.rdoc +7 -7
- data/Rakefile +1 -0
- data/lib/mysql_rake_tasks/tasks.rb +31 -24
- data/lib/mysql_rake_tasks/version.rb +1 -1
- data/mysql_rake_tasks.gemspec +4 -3
- data/test/tasks_test.rb +12 -6
- metadata +49 -29
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b08d5ab0c8ee9fd347b874e6a137aa16ebf1bc33a94d9ecc961b5958a3c7a0ac
|
4
|
+
data.tar.gz: '02799bc1c94a6bddbec2a795a85355782dc937476571cf428a4dc23b8d3a016a'
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 95dada497b356fce73cea69e704357e41cc746b93db227ad4d8cdd7f14ca49e667ee9ed8af55915e3592ef7dc2b3d433b7c222e1f95871c610a19f301e8fdc8a
|
7
|
+
data.tar.gz: 507bb3184fa1ade352f24a52aa9c7c255ad3c61a8b4398bf403c3feafd9eac54047c5656a99dfac7a271899efe51d6074b524c37c4efb0e6e6a14e483c9f1de2
|
data/{LICENSE → LICENSE.txt}
RENAMED
File without changes
|
data/README.rdoc
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
|
1
|
+
# mysql_rake_tasks
|
2
2
|
|
3
3
|
A collection of rails rake tasks for mysql
|
4
4
|
1. create_users - creates localhost mysql user accounts for each database listing in the database.yml
|
5
5
|
2. stats - database stats - table size
|
6
6
|
|
7
|
-
|
7
|
+
## Install
|
8
8
|
|
9
9
|
1. Add mysql_rake_tasks to your gem file
|
10
10
|
|
@@ -14,9 +14,9 @@ A collection of rails rake tasks for mysql
|
|
14
14
|
|
15
15
|
bundle install
|
16
16
|
|
17
|
-
|
17
|
+
## Examples
|
18
18
|
|
19
|
-
|
19
|
+
### create_users
|
20
20
|
|
21
21
|
To create mysql users in interactive mode run:
|
22
22
|
|
@@ -28,7 +28,7 @@ You can also specify your root username and password on the command line:
|
|
28
28
|
|
29
29
|
rake db:mysel:create_users[root,mypassword]
|
30
30
|
|
31
|
-
|
31
|
+
### stats
|
32
32
|
|
33
33
|
To display database stats:
|
34
34
|
|
@@ -46,11 +46,11 @@ To display database stats:
|
|
46
46
|
+--------------------------------+---------------+-----------+----------+------------+
|
47
47
|
Database: mydb_development MySQL Server Version: 5.1.58
|
48
48
|
|
49
|
-
|
49
|
+
## License
|
50
50
|
|
51
51
|
MIT
|
52
52
|
|
53
|
-
|
53
|
+
## Credits
|
54
54
|
|
55
55
|
Author: Gregory Ostermayr gregory.ostermayr@gmail.com
|
56
56
|
|
data/Rakefile
CHANGED
@@ -42,15 +42,15 @@ module MysqlRakeTasks
|
|
42
42
|
db_name = @config['database']
|
43
43
|
|
44
44
|
begin
|
45
|
-
db = Mysql2::Client.new(
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
45
|
+
db = Mysql2::Client.new( host: 'localhost', username: @root_user, password: @pass)
|
46
|
+
|
47
|
+
sql = self.create_user_sql(@config)
|
48
|
+
db.query(sql)
|
49
|
+
|
50
|
+
sql = self.grant_user_sql(@config)
|
51
|
+
db.query(sql)
|
52
|
+
|
53
|
+
$stdout.puts "Created #{username} on #{db_name}\n"
|
54
54
|
rescue Mysql2::Error => e
|
55
55
|
error_output(e)
|
56
56
|
ensure # disconnect from server
|
@@ -60,33 +60,40 @@ module MysqlRakeTasks
|
|
60
60
|
end
|
61
61
|
|
62
62
|
def self.create_user_sql(config)
|
63
|
-
|
64
|
-
|
63
|
+
return '' unless config
|
64
|
+
|
65
|
+
if config['username'].nil?
|
66
|
+
puts 'Error code: missing username entry'
|
65
67
|
end
|
66
68
|
|
69
|
+
sql = <<-SQL
|
70
|
+
CREATE USER '#{config['username']}'@'localhost' IDENTIFIED BY '#{config['password']}';
|
71
|
+
SQL
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.grant_user_sql(config)
|
75
|
+
return '' unless config
|
76
|
+
|
67
77
|
if config['username'].nil?
|
68
78
|
puts 'Error code: missing username entry'
|
69
79
|
end
|
70
80
|
|
71
|
-
sql
|
72
|
-
GRANT
|
73
|
-
ALL PRIVILEGES
|
74
|
-
ON #{config['database']}.*
|
75
|
-
TO #{config['username']}@localhost
|
76
|
-
IDENTIFIED BY '#{config['password']}';
|
81
|
+
sql = <<-SQL
|
82
|
+
GRANT ALL ON #{config['database']}.* TO '#{config['username']}'@'localhost';
|
77
83
|
SQL
|
78
84
|
end
|
79
85
|
|
80
86
|
def self.stats
|
81
|
-
config = Rails::configuration.database_configuration[Rails.env]
|
87
|
+
config = Rails::configuration.database_configuration[Rails.env].clone
|
82
88
|
|
83
89
|
begin
|
84
|
-
|
90
|
+
db = Mysql2::Client.new( host: config['host'], username: config['username'], password: config['password'])
|
91
|
+
|
85
92
|
db_name = config['database']
|
86
|
-
version =
|
93
|
+
version = db.info[:version]
|
87
94
|
|
88
95
|
sql = stats_query(db_name)
|
89
|
-
result =
|
96
|
+
result = db.query sql
|
90
97
|
|
91
98
|
print_header
|
92
99
|
|
@@ -100,7 +107,7 @@ module MysqlRakeTasks
|
|
100
107
|
rescue Mysql2::Error => e
|
101
108
|
error_output(e)
|
102
109
|
ensure
|
103
|
-
|
110
|
+
db.close if db
|
104
111
|
end
|
105
112
|
end
|
106
113
|
|
@@ -118,7 +125,7 @@ module MysqlRakeTasks
|
|
118
125
|
def self.print_stat_line(row)
|
119
126
|
printf "| %30s | %13s | %9s | %8s | %10s |\n",
|
120
127
|
row["table_name"].ljust(30),
|
121
|
-
number_to_human(row["
|
128
|
+
number_to_human(row["table_rows"]).rjust(13),
|
122
129
|
number_to_human_size(row["data"]),
|
123
130
|
number_to_human_size(row["idx"]),
|
124
131
|
number_to_human_size(row["total_size"])
|
@@ -135,7 +142,7 @@ module MysqlRakeTasks
|
|
135
142
|
def self.stats_query(db_name)
|
136
143
|
sql = <<-SQL
|
137
144
|
SELECT table_name,
|
138
|
-
concat(table_rows)
|
145
|
+
concat(table_rows) as table_rows,
|
139
146
|
concat(data_length) data,
|
140
147
|
concat(index_length) idx,
|
141
148
|
concat(data_length+index_length) total_size
|
data/mysql_rake_tasks.gemspec
CHANGED
@@ -12,20 +12,21 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.description = %q{A collection of rails rake tasks for mysql.}
|
13
13
|
s.license = "MIT"
|
14
14
|
s.extra_rdoc_files = [
|
15
|
-
|
15
|
+
"LICENSE.txt",
|
16
16
|
"README.rdoc"
|
17
17
|
]
|
18
18
|
|
19
19
|
s.rubyforge_project = "mysql_rake_tasks"
|
20
20
|
|
21
21
|
s.files = `git ls-files`.split("\n")
|
22
|
-
s.test_files = Dir['test/*.rb']
|
22
|
+
s.test_files = Dir['test/*.rb']
|
23
23
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
24
24
|
s.require_paths = ["lib"]
|
25
25
|
|
26
26
|
# specify any dependencies here; for example:
|
27
27
|
# s.add_development_dependency "rspec"
|
28
|
-
s.add_development_dependency 'rake', '~> 0
|
28
|
+
s.add_development_dependency 'rake', '~> 13.0'
|
29
29
|
s.add_development_dependency 'mocha', '~> 0.9.12'
|
30
|
+
s.add_development_dependency 'test-unit-rails', '~> 6.0'
|
30
31
|
s.add_runtime_dependency 'mysql2', '>= 0.2.7'
|
31
32
|
end
|
data/test/tasks_test.rb
CHANGED
@@ -6,7 +6,7 @@ require 'mocha'
|
|
6
6
|
|
7
7
|
class TasksTest < Test::Unit::TestCase
|
8
8
|
def setup
|
9
|
-
Rails.stubs(:configuration).returns(Rails::Application::Configuration.allocate)
|
9
|
+
Rails.stubs(:configuration).returns(Rails::Application::Configuration.allocate)
|
10
10
|
Rails.configuration.stubs(:database_configuration).returns(stub_config)
|
11
11
|
end
|
12
12
|
|
@@ -35,7 +35,7 @@ class TasksTest < Test::Unit::TestCase
|
|
35
35
|
screen = io_mock do |input|
|
36
36
|
MysqlRakeTasks::Tasks.create_users(:root_user => 'root', :pass => 'wrong')
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
assert_equal 'Error code: 1045', screen[0]
|
40
40
|
assert_equal "Error message: Access denied for user 'root'@'localhost' (using password: YES)", screen[1]
|
41
41
|
assert_equal 'Error code: 1045', screen[2]
|
@@ -47,7 +47,11 @@ class TasksTest < Test::Unit::TestCase
|
|
47
47
|
def test_successful_creation
|
48
48
|
screen = io_mock do |input|
|
49
49
|
# :pass needs to be set to mysql root in order to pass
|
50
|
-
|
50
|
+
# mysqladmin --user=root password "myrootpass"
|
51
|
+
# create database task_test
|
52
|
+
# create database task_production
|
53
|
+
# drop user 'test'@'localhost';drop user 'dev'@'localhost';drop user 'prod'@'localhost';
|
54
|
+
MysqlRakeTasks::Tasks.create_users(:root_user => 'root', :pass => 'myrootpass')
|
51
55
|
end
|
52
56
|
|
53
57
|
assert_equal "Created dev on task_development", screen[0], 'Note: ***check test machine password***'
|
@@ -56,8 +60,10 @@ class TasksTest < Test::Unit::TestCase
|
|
56
60
|
end
|
57
61
|
|
58
62
|
def test_lack_of_user_throws_error
|
59
|
-
config = stub_config
|
63
|
+
config = stub_config.clone
|
60
64
|
config["development"].delete "username"
|
65
|
+
config["production"].delete "username"
|
66
|
+
config["test"].delete "username"
|
61
67
|
|
62
68
|
Rails.configuration.stubs(:database_configuration).returns(config)
|
63
69
|
|
@@ -67,7 +73,7 @@ class TasksTest < Test::Unit::TestCase
|
|
67
73
|
end
|
68
74
|
|
69
75
|
assert_equal 'Error code: missing username entry', screen[0], 'Note: ***check test machine password***'
|
70
|
-
assert_equal 'Error code:
|
76
|
+
assert_equal 'Error code: 1396', screen[1]
|
71
77
|
end
|
72
78
|
|
73
79
|
def test_stats_outputs_header
|
@@ -101,7 +107,7 @@ class TasksTest < Test::Unit::TestCase
|
|
101
107
|
"database"=>"task_production",
|
102
108
|
"pool"=>5,
|
103
109
|
"username"=>"prod",
|
104
|
-
"password"=>"prodpassword"}}
|
110
|
+
"password"=>"prodpassword"}}
|
105
111
|
end
|
106
112
|
|
107
113
|
|
metadata
CHANGED
@@ -1,61 +1,83 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mysql_rake_tasks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Gregory Ostermayr
|
9
|
-
autorequire:
|
8
|
+
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2020-07-18 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rake
|
16
|
-
requirement:
|
17
|
-
none: false
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
|
-
- - ~>
|
17
|
+
- - "~>"
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version: 0
|
19
|
+
version: '13.0'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
|
-
version_requirements:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '13.0'
|
25
27
|
- !ruby/object:Gem::Dependency
|
26
28
|
name: mocha
|
27
|
-
requirement:
|
28
|
-
none: false
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
29
30
|
requirements:
|
30
|
-
- - ~>
|
31
|
+
- - "~>"
|
31
32
|
- !ruby/object:Gem::Version
|
32
33
|
version: 0.9.12
|
33
34
|
type: :development
|
34
35
|
prerelease: false
|
35
|
-
version_requirements:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.9.12
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: test-unit-rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '6.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '6.0'
|
36
55
|
- !ruby/object:Gem::Dependency
|
37
56
|
name: mysql2
|
38
|
-
requirement:
|
39
|
-
none: false
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
40
58
|
requirements:
|
41
|
-
- -
|
59
|
+
- - ">="
|
42
60
|
- !ruby/object:Gem::Version
|
43
61
|
version: 0.2.7
|
44
62
|
type: :runtime
|
45
63
|
prerelease: false
|
46
|
-
version_requirements:
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.2.7
|
47
69
|
description: A collection of rails rake tasks for mysql.
|
48
70
|
email:
|
49
71
|
- gregory.ostermayr@gmail.com
|
50
72
|
executables: []
|
51
73
|
extensions: []
|
52
74
|
extra_rdoc_files:
|
53
|
-
- LICENSE
|
75
|
+
- LICENSE.txt
|
54
76
|
- README.rdoc
|
55
77
|
files:
|
56
|
-
- .gitignore
|
78
|
+
- ".gitignore"
|
57
79
|
- Gemfile
|
58
|
-
- LICENSE
|
80
|
+
- LICENSE.txt
|
59
81
|
- README.rdoc
|
60
82
|
- Rakefile
|
61
83
|
- lib/mysql_rake_tasks.rb
|
@@ -68,27 +90,25 @@ files:
|
|
68
90
|
homepage: https://github.com/gregors/mysql_rake_tasks
|
69
91
|
licenses:
|
70
92
|
- MIT
|
71
|
-
|
93
|
+
metadata: {}
|
94
|
+
post_install_message:
|
72
95
|
rdoc_options: []
|
73
96
|
require_paths:
|
74
97
|
- lib
|
75
98
|
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
-
none: false
|
77
99
|
requirements:
|
78
|
-
- -
|
100
|
+
- - ">="
|
79
101
|
- !ruby/object:Gem::Version
|
80
102
|
version: '0'
|
81
103
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
-
none: false
|
83
104
|
requirements:
|
84
|
-
- -
|
105
|
+
- - ">="
|
85
106
|
- !ruby/object:Gem::Version
|
86
107
|
version: '0'
|
87
108
|
requirements: []
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
specification_version: 3
|
109
|
+
rubygems_version: 3.0.8
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
92
112
|
summary: Rake tasks for mysql
|
93
113
|
test_files:
|
94
114
|
- test/tasks_test.rb
|