Sha256: d9ac3c41cbcb5a9d14b4ea581a7a1b24f491d8eca9cda8a3a5abd7da8e7873c3

Contents?: true

Size: 1.28 KB

Versions: 7

Compression:

Stored size: 1.28 KB

Contents

Puppet::Type.type(:database).provide(:mysql) do
  desc 'Manages MySQL database.'

  defaultfor :kernel => 'Linux'

  optional_commands :mysql      => 'mysql'
  optional_commands :mysqladmin => 'mysqladmin'

  def self.defaults_file
    if File.file?("#{Facter.value(:root_home)}/.my.cnf")
      "--defaults-extra-file=#{Facter.value(:root_home)}/.my.cnf"
    else
      nil
    end
  end

  def defaults_file
    self.class.defaults_file
  end

  def self.instances
    mysql([defaults_file, '-NBe', 'show databases'].compact).split("\n").collect do |name|
      new(:name => name)
    end
  end

  def create
    mysql([defaults_file, '-NBe', "create database `#{@resource[:name]}` character set #{resource[:charset]}"].compact)
  end

  def destroy
    mysqladmin([defaults_file, '-f', 'drop', @resource[:name]].compact)
  end

  def charset
    mysql([defaults_file, '-NBe', "show create database `#{resource[:name]}`"].compact).match(/.*?(\S+)\s(?:COLLATE.*)?\*\//)[1]
  end

  def charset=(value)
    mysql([defaults_file, '-NBe', "alter database `#{resource[:name]}` CHARACTER SET #{value}"].compact)
  end

  def exists?
    begin
      mysql([defaults_file, '-NBe', 'show databases'].compact).match(/^#{@resource[:name]}$/)
    rescue => e
      debug(e.message)
      return nil
    end
  end

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
freighthop-0.3.3 modules/mysql/lib/puppet/provider/database/mysql.rb
freighthop-0.3.2 modules/mysql/lib/puppet/provider/database/mysql.rb
freighthop-0.3.1 modules/mysql/lib/puppet/provider/database/mysql.rb
freighthop-0.3.0 modules/mysql/lib/puppet/provider/database/mysql.rb
freighthop-0.2.1 modules/mysql/lib/puppet/provider/database/mysql.rb
freighthop-0.2.0 modules/mysql/lib/puppet/provider/database/mysql.rb
freighthop-0.1.0 modules/mysql/lib/puppet/provider/database/mysql.rb