You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
...so they can all be modified from one place.
The current codebase handles each mysql call via calls to the command-line
mysql client. There are basically only two sets of options passed, but the
options are repeated separately in various places throughout the code. The
new self.mysql function now issues the call to the mysql client with one of
the two sets of options (selected via an optional function parameter).
Now the options to all mysql calls can be modified from one place. This will
be useful when we are converting the module to allow for databases on multiple
remote servers, since we will be able to add the -h switch to all calls at
once.
mysql([defaults_file,'-NBe',"show variables like '%_database'",name].compact).split("\n").eachdo |line|
10
+
self.mysql_caller(["show variables like '%_database'",name],'regular').split("\n").eachdo |line|
11
11
k,v=line.split(%r{\s})
12
12
attributes[k]=v
13
13
end
@@ -29,7 +29,7 @@ def self.prefetch(resources)
29
29
end
30
30
31
31
defcreate
32
-
mysql([defaults_file,'-NBe',"create database if not exists `#{@resource[:name]}` character set `#{@resource[:charset]}` collate `#{@resource[:collate]}`"].compact)
32
+
self.class.mysql_caller("create database if not exists `#{@resource[:name]}` character set `#{@resource[:charset]}` collate `#{@resource[:collate]}`",'regular')
33
33
34
34
@property_hash[:ensure]=:present
35
35
@property_hash[:charset]=@resource[:charset]
@@ -39,7 +39,7 @@ def create
39
39
end
40
40
41
41
defdestroy
42
-
mysql([defaults_file,'-NBe',"drop database if exists `#{@resource[:name]}`"].compact)
42
+
self.class.mysql_caller("drop database if exists `#{@resource[:name]}`",'regular')
43
43
44
44
@property_hash.clear
45
45
exists? ? (returnfalse) : (returntrue)
@@ -52,13 +52,13 @@ def exists?
52
52
mk_resource_methods
53
53
54
54
defcharset=(value)
55
-
mysql([defaults_file,'-NBe',"alter database `#{resource[:name]}` CHARACTER SET #{value}"].compact)
55
+
self.class.mysql_caller("alter database `#{resource[:name]}` CHARACTER SET #{value}",'regular')
mysql([defaults_file,system_database,'-e',"CREATE USER '#{merged_name}' IDENTIFIED WITH '#{plugin}' AS '#{password_hash}'"].compact)
66
+
self.class.mysql_caller("CREATE USER '#{merged_name}' IDENTIFIED WITH '#{plugin}' AS '#{password_hash}'",'system')
68
67
else
69
-
mysql([defaults_file,system_database,'-e',"CREATE USER '#{merged_name}' IDENTIFIED WITH '#{plugin}'"].compact)
68
+
self.class.mysql_caller("CREATE USER '#{merged_name}' IDENTIFIED WITH '#{plugin}'",'system')
70
69
end
71
70
@property_hash[:ensure]=:present
72
71
@property_hash[:plugin]=plugin
73
72
else
74
-
mysql([defaults_file,system_database,'-e',"CREATE USER '#{merged_name}' IDENTIFIED BY PASSWORD '#{password_hash}'"].compact)
73
+
self.class.mysql_caller("CREATE USER '#{merged_name}' IDENTIFIED BY PASSWORD '#{password_hash}'",'system')
75
74
@property_hash[:ensure]=:present
76
75
@property_hash[:password_hash]=password_hash
77
76
end
78
77
# rubocop:disable Metrics/LineLength
79
-
mysql([defaults_file,system_database,'-e',"GRANT USAGE ON *.* TO '#{merged_name}' WITH MAX_USER_CONNECTIONS #{max_user_connections} MAX_CONNECTIONS_PER_HOUR #{max_connections_per_hour} MAX_QUERIES_PER_HOUR #{max_queries_per_hour} MAX_UPDATES_PER_HOUR #{max_updates_per_hour}"].compact)
78
+
self.class.mysql_caller("GRANT USAGE ON *.* TO '#{merged_name}' WITH MAX_USER_CONNECTIONS #{max_user_connections} MAX_CONNECTIONS_PER_HOUR #{max_connections_per_hour} MAX_QUERIES_PER_HOUR #{max_queries_per_hour} MAX_UPDATES_PER_HOUR #{max_updates_per_hour}",'system')
provider.expects(:mysql).with([defaults_file,'-NBe',"create database if not exists `#{resource[:name]}` character set `#{resource[:charset]}` collate `#{resource[:collate]}`"])
59
+
provider.expects(:mysql).with("create database if not exists `#{resource[:name]}` character set `#{resource[:charset]}` collate `#{resource[:collate]}`",'regular')
60
60
provider.expects(:exists?).returns(true)
61
61
expect(provider.create).tobe_truthy
62
62
end
63
63
end
64
64
65
65
describe'destroy'do
66
66
it'removes a database if present'do
67
-
provider.expects(:mysql).with([defaults_file,'-NBe',"drop database if exists `#{resource[:name]}`"])
67
+
provider.expects(:mysql).with("drop database if exists `#{resource[:name]}`",'regular')
68
68
provider.expects(:exists?).returns(false)
69
69
expect(provider.destroy).tobe_truthy
70
70
end
@@ -95,7 +95,7 @@
95
95
96
96
describe'charset='do
97
97
it'changes the charset'do
98
-
provider.expects(:mysql).with([defaults_file,'-NBe',"alter database `#{resource[:name]}` CHARACTER SET blah"]).returns('0')
98
+
provider.expects(:mysql).with("alter database `#{resource[:name]}` CHARACTER SET blah",'regular').returns('0')
0 commit comments