b1f90fd1d2
This is a major change to the module and would be released as a new version. * Add self.instances to database and database_user for puppet resource. * Update database provider to use flush method. * Update module to conform to puppet-lint recommendations. * Cleanup some unecessary logic in mysql::db define type. * Move mysql_restart to config class. * Use class to class dependency instead of resource dependency. * Change appropriate rspec-puppet tests. * Add fixtures directory to simplify testing. * Update raketask and spec_helper to reflect fixture changes. * Update mysql_password function to support validation. * Move client installation to a separate class. * Update documentation and readme.
42 lines
901 B
Ruby
42 lines
901 B
Ruby
Puppet::Type.type(:database).provide(:mysql) do
|
|
|
|
desc "Manages MySQL database."
|
|
|
|
defaultfor :kernel => 'Linux'
|
|
|
|
optional_commands :mysql => 'mysql'
|
|
optional_commands :mysqladmin => 'mysqladmin'
|
|
|
|
def self.instances
|
|
mysql('-NBe', "show databases").split("\n").collect do |name|
|
|
new(:name => name)
|
|
end
|
|
end
|
|
|
|
def create
|
|
mysql('-NBe', "create database #{@resource[:name]} character set #{resource[:charset]}")
|
|
end
|
|
|
|
def destroy
|
|
mysqladmin('-f', 'drop', @resource[:name])
|
|
end
|
|
|
|
def charset
|
|
mysql('-NBe', "show create database #{resource[:name]}").match(/.*?(\S+)\s\*\//)[1]
|
|
end
|
|
|
|
def charset=(value)
|
|
mysql('-NBe', "alter database #{resource[:name]} CHARACTER SET #{value}")
|
|
end
|
|
|
|
def exists?
|
|
begin
|
|
mysql('-NBe', "show databases").match(/^#{@resource[:name]}$/)
|
|
rescue => e
|
|
debug(e.message)
|
|
return nil
|
|
end
|
|
end
|
|
|
|
end
|
|
|