Skip to content

Commit 82f7f55

Browse files
authored
Merge pull request #942 from xelmedia/master
Replaced 'DROP USER' with 'DROP USER IF EXISTS'
2 parents 049ba89 + b88fe42 commit 82f7f55

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/puppet/provider/mysql_user/mysql.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ def create
9696

9797
def destroy
9898
merged_name = @resource[:name].sub('@', "'@'")
99-
self.class.mysql_caller("DROP USER '#{merged_name}'", 'system')
99+
if_exists = (Puppet::Util::Package.versioncmp(mysqld_version, '5.7') >= 0) ? 'IF EXISTS ' : ''
100+
101+
self.class.mysql_caller("DROP USER #{if_exists}'#{merged_name}'", 'system')
100102

101103
@property_hash.clear
102104
exists? ? (return false) : (return true)

spec/unit/puppet/provider/mysql_user/mysql_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,12 @@
183183
provider.expects(:exists?).returns(false)
184184
expect(provider.destroy).to be_truthy
185185
end
186+
it 'removes a user using IF EXISTS' do
187+
provider.class.instance_variable_set(:@mysqld_version_string, '5.7.1')
188+
189+
provider.class.expects(:mysql_caller).with("DROP USER IF EXISTS 'joe'@'localhost'", 'system')
190+
expect(provider.destroy).to be_truthy
191+
end
186192
end
187193

188194
describe 'exists?' do

0 commit comments

Comments
 (0)