annotate modules/mysql/lib/puppet/provider/mysql.rb @ 482:d83de9b3a62b default tip

Update hiera.yaml within Puppet config Forgot that we manage it from here. Now has content to match new packages
author IBBoard <dev@ibboard.co.uk>
date Fri, 30 Aug 2024 16:10:36 +0100
parents adf6fe9bbc17
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
389
668df4711671 Update MySQL modules
IBBoard <dev@ibboard.co.uk>
parents: 244
diff changeset
1 # frozen_string_literal: true
668df4711671 Update MySQL modules
IBBoard <dev@ibboard.co.uk>
parents: 244
diff changeset
2
244
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
3 # Puppet provider for mysql
0
956e484adc12 Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4 class Puppet::Provider::Mysql < Puppet::Provider
956e484adc12 Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 # Without initvars commands won't work.
956e484adc12 Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 initvars
244
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
7
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
8 # Make sure we find mysql commands on CentOS and FreeBSD
478
adf6fe9bbc17 Update Puppet modules to latest versions
IBBoard <dev@ibboard.co.uk>
parents: 389
diff changeset
9 ENV['PATH'] = "#{ENV.fetch('PATH', nil)}:/usr/libexec:/usr/local/libexec:/usr/local/bin"
244
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
10 ENV['LD_LIBRARY_PATH'] = [
478
adf6fe9bbc17 Update Puppet modules to latest versions
IBBoard <dev@ibboard.co.uk>
parents: 389
diff changeset
11 ENV.fetch('LD_LIBRARY_PATH', nil),
244
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
12 '/usr/lib',
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
13 '/usr/lib64',
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
14 '/opt/rh/rh-mysql56/root/usr/lib',
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
15 '/opt/rh/rh-mysql56/root/usr/lib64',
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
16 '/opt/rh/rh-mysql57/root/usr/lib',
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
17 '/opt/rh/rh-mysql57/root/usr/lib64',
389
668df4711671 Update MySQL modules
IBBoard <dev@ibboard.co.uk>
parents: 244
diff changeset
18 '/opt/rh/rh-mysql80/root/usr/lib',
668df4711671 Update MySQL modules
IBBoard <dev@ibboard.co.uk>
parents: 244
diff changeset
19 '/opt/rh/rh-mysql80/root/usr/lib64',
244
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
20 '/opt/rh/rh-mariadb100/root/usr/lib',
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
21 '/opt/rh/rh-mariadb100/root/usr/lib64',
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
22 '/opt/rh/rh-mariadb101/root/usr/lib',
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
23 '/opt/rh/rh-mariadb101/root/usr/lib64',
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
24 '/opt/rh/rh-mariadb102/root/usr/lib',
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
25 '/opt/rh/rh-mariadb102/root/usr/lib64',
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
26 '/opt/rh/rh-mariadb103/root/usr/lib',
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
27 '/opt/rh/rh-mariadb103/root/usr/lib64',
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
28 '/opt/rh/mysql55/root/usr/lib',
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
29 '/opt/rh/mysql55/root/usr/lib64',
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
30 '/opt/rh/mariadb55/root/usr/lib',
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
31 '/opt/rh/mariadb55/root/usr/lib64',
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
32 '/usr/mysql/5.5/lib',
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
33 '/usr/mysql/5.5/lib64',
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
34 '/usr/mysql/5.6/lib',
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
35 '/usr/mysql/5.6/lib64',
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
36 '/usr/mysql/5.7/lib',
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
37 '/usr/mysql/5.7/lib64',
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
38 ].join(':')
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
39
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
40 # rubocop:disable Style/HashSyntax
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
41 commands :mysql_raw => 'mysql'
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
42 commands :mysqld => 'mysqld'
0
956e484adc12 Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
43 commands :mysqladmin => 'mysqladmin'
244
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
44 # rubocop:enable Style/HashSyntax
0
956e484adc12 Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
45
956e484adc12 Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
46 # Optional defaults file
956e484adc12 Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
47 def self.defaults_file
244
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
48 "--defaults-extra-file=#{Facter.value(:root_home)}/.my.cnf" if File.file?("#{Facter.value(:root_home)}/.my.cnf")
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
49 end
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
50
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
51 def self.mysqld_type
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
52 # find the mysql "dialect" like mariadb / mysql etc.
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
53 mysqld_version_string.scan(%r{mariadb}i) { return 'mariadb' }
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
54 mysqld_version_string.scan(%r{\s\(percona}i) { return 'percona' }
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
55 'mysql'
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
56 end
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
57
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
58 def mysqld_type
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
59 self.class.mysqld_type
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
60 end
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
61
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
62 def self.mysqld_version_string
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
63 # As the possibility of the mysqld being remote we need to allow the version string to be overridden,
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
64 # this can be done by facter.value as seen below. In the case that it has not been set and the facter
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
65 # value is nil we use the mysql -v command to ensure we report the correct version of mysql for later use cases.
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
66 @mysqld_version_string ||= Facter.value(:mysqld_version) || mysqld('-V')
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
67 end
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
68
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
69 def mysqld_version_string
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
70 self.class.mysqld_version_string
0
956e484adc12 Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
71 end
244
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
72
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
73 def self.mysqld_version
389
668df4711671 Update MySQL modules
IBBoard <dev@ibboard.co.uk>
parents: 244
diff changeset
74 # NOTE: be prepared for '5.7.6-rc-log' etc results
244
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
75 # versioncmp detects 5.7.6-log to be newer then 5.7.6
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
76 # this is why we need the trimming.
389
668df4711671 Update MySQL modules
IBBoard <dev@ibboard.co.uk>
parents: 244
diff changeset
77 mysqld_version_string&.scan(%r{\d+\.\d+\.\d+})&.first
244
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
78 end
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
79
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
80 def mysqld_version
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
81 self.class.mysqld_version
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
82 end
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
83
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
84 def self.newer_than(forks_versions)
389
668df4711671 Update MySQL modules
IBBoard <dev@ibboard.co.uk>
parents: 244
diff changeset
85 forks_versions.key?(mysqld_type) && Puppet::Util::Package.versioncmp(mysqld_version, forks_versions[mysqld_type]) >= 0
244
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
86 end
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
87
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
88 def newer_than(forks_versions)
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
89 self.class.newer_than(forks_versions)
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
90 end
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
91
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
92 def self.older_than(forks_versions)
478
adf6fe9bbc17 Update Puppet modules to latest versions
IBBoard <dev@ibboard.co.uk>
parents: 389
diff changeset
93 forks_versions.key?(mysqld_type) && Puppet::Util::Package.versioncmp(mysqld_version, forks_versions[mysqld_type]).negative?
244
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
94 end
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
95
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
96 def older_than(forks_versions)
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
97 self.class.older_than(forks_versions)
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
98 end
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
99
0
956e484adc12 Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
100 def defaults_file
956e484adc12 Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
101 self.class.defaults_file
956e484adc12 Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
102 end
956e484adc12 Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
103
244
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
104 def self.mysql_caller(text_of_sql, type)
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
105 if type.eql? 'system'
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
106 if File.file?("#{Facter.value(:root_home)}/.mylogin.cnf")
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
107 ENV['MYSQL_TEST_LOGIN_FILE'] = "#{Facter.value(:root_home)}/.mylogin.cnf"
389
668df4711671 Update MySQL modules
IBBoard <dev@ibboard.co.uk>
parents: 244
diff changeset
108 mysql_raw([system_database, '-e', text_of_sql].flatten.compact).scrub
244
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
109 else
389
668df4711671 Update MySQL modules
IBBoard <dev@ibboard.co.uk>
parents: 244
diff changeset
110 mysql_raw([defaults_file, system_database, '-e', text_of_sql].flatten.compact).scrub
244
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
111 end
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
112 elsif type.eql? 'regular'
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
113 if File.file?("#{Facter.value(:root_home)}/.mylogin.cnf")
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
114 ENV['MYSQL_TEST_LOGIN_FILE'] = "#{Facter.value(:root_home)}/.mylogin.cnf"
389
668df4711671 Update MySQL modules
IBBoard <dev@ibboard.co.uk>
parents: 244
diff changeset
115 mysql_raw(['-NBe', text_of_sql].flatten.compact).scrub
244
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
116 else
389
668df4711671 Update MySQL modules
IBBoard <dev@ibboard.co.uk>
parents: 244
diff changeset
117 mysql_raw([defaults_file, '-NBe', text_of_sql].flatten.compact).scrub
244
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
118 end
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
119 else
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
120 raise Puppet::Error, _("#mysql_caller: Unrecognised type '%{type}'" % { type: type })
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
121 end
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
122 end
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
123
0
956e484adc12 Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
124 def self.users
244
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
125 mysql_caller("SELECT CONCAT(User, '@',Host) AS User FROM mysql.user", 'regular').split("\n")
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
126 end
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
127
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
128 # Optional parameter to run a statement on the MySQL system database.
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
129 def self.system_database
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
130 '--database=mysql'
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
131 end
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
132
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
133 def system_database
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
134 self.class.system_database
0
956e484adc12 Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
135 end
956e484adc12 Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
136
956e484adc12 Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
137 # Take root@localhost and munge it to 'root'@'localhost'
244
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
138 # Take root@id123@localhost and munge it to 'root@id123'@'localhost'
0
956e484adc12 Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
139 def self.cmd_user(user)
244
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
140 "'#{user.reverse.sub('@', "'@'").reverse}'"
0
956e484adc12 Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
141 end
956e484adc12 Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
142
956e484adc12 Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
143 # Take root.* and return ON `root`.*
956e484adc12 Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
144 def self.cmd_table(table)
956e484adc12 Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
145 table_string = ''
956e484adc12 Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
146
956e484adc12 Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
147 # We can't escape *.* so special case this.
389
668df4711671 Update MySQL modules
IBBoard <dev@ibboard.co.uk>
parents: 244
diff changeset
148 table_string += if table == '*.*'
244
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
149 '*.*'
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
150 # Special case also for FUNCTIONs and PROCEDUREs
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
151 elsif table.start_with?('FUNCTION ', 'PROCEDURE ')
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
152 table.sub(%r{^(FUNCTION|PROCEDURE) (.*)(\..*)}, '\1 `\2`\3')
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
153 else
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
154 table.sub(%r{^(.*)(\..*)}, '`\1`\2')
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
155 end
0
956e484adc12 Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
156 table_string
956e484adc12 Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
157 end
956e484adc12 Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
158
956e484adc12 Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
159 def self.cmd_privs(privileges)
244
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
160 return 'ALL PRIVILEGES' if privileges.include?('ALL')
478
adf6fe9bbc17 Update Puppet modules to latest versions
IBBoard <dev@ibboard.co.uk>
parents: 389
diff changeset
161
244
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
162 priv_string = ''
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
163 privileges.each do |priv|
389
668df4711671 Update MySQL modules
IBBoard <dev@ibboard.co.uk>
parents: 244
diff changeset
164 priv_string += "#{priv}, "
0
956e484adc12 Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
165 end
956e484adc12 Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
166 # Remove trailing , from the last element.
244
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
167 priv_string.sub(%r{, $}, '')
0
956e484adc12 Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
168 end
956e484adc12 Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
169
956e484adc12 Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
170 # Take in potential options and build up a query string with them.
956e484adc12 Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
171 def self.cmd_options(options)
956e484adc12 Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
172 option_string = ''
956e484adc12 Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
173 options.each do |opt|
389
668df4711671 Update MySQL modules
IBBoard <dev@ibboard.co.uk>
parents: 244
diff changeset
174 option_string += ' WITH GRANT OPTION' if opt == 'GRANT'
0
956e484adc12 Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
175 end
956e484adc12 Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
176 option_string
956e484adc12 Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
177 end
956e484adc12 Initial public release of Puppet configs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
178 end