Added [if not exists] to [create database] clause.

this should avoid errors like:
ERROR 1007 (HY000): Can't create database 'MyDB'; database exists

This error can cause a multi-master replication to stop due to conflicting
commands between nodes. For  example, if the command create DB is run in
 different nodes and then they will send it in the replication logs to each
other and then they will try to run them second time and fail.
This commit is contained in:
Srinath M 2013-12-15 21:47:10 -05:00
parent 62eb73db07
commit 1cc07977c5

View file

@ -31,7 +31,7 @@ Puppet::Type.type(:mysql_database).provide(:mysql, :parent => Puppet::Provider::
end
def create
mysql([defaults_file, '-NBe', "create database `#{@resource[:name]}` character set #{@resource[:charset]} collate #{@resource[:collate]}"].compact)
mysql([defaults_file, '-NBe', "create database if not exists `#{@resource[:name]}` character set #{@resource[:charset]} collate #{@resource[:collate]}"].compact)
@property_hash[:ensure] = :present
@property_hash[:charset] = @resource[:charset]