Class: Chef::Provider::Database::Mysql

Inherits:
Chef::Provider show all
Includes:
Mixin::ShellOut
Defined in:
lib/cookbooks/database/libraries/provider_database_mysql.rb

Direct Known Subclasses

MysqlUser

Instance Method Summary collapse

Instance Method Details

#action_createObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/cookbooks/database/libraries/provider_database_mysql.rb', line 35

def action_create
  unless exists?
    begin
      Chef::Log.debug("#{@new_resource}: Creating database #{new_resource.database_name}")
      create_sql = "CREATE DATABASE #{new_resource.database_name}"
      create_sql += " CHARACTER SET = #{new_resource.encoding}" if new_resource.encoding
      create_sql += " COLLATE = #{new_resource.collation}" if new_resource.collation
      Chef::Log.debug("#{@new_resource}: Performing query [#{create_sql}]")
      db.query(create_sql)
      @new_resource.updated_by_last_action(true)
    ensure
      close
    end
  end
end

#action_dropObject



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/cookbooks/database/libraries/provider_database_mysql.rb', line 51

def action_drop
  if exists?
    begin
      Chef::Log.debug("#{@new_resource}: Dropping database #{new_resource.database_name}")
      db.query("drop database #{new_resource.database_name}")
      @new_resource.updated_by_last_action(true)
    ensure
      close
    end
  end
end

#action_queryObject



63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/cookbooks/database/libraries/provider_database_mysql.rb', line 63

def action_query
  if exists?
    begin
      db.select_db(@new_resource.database_name) if @new_resource.database_name
      Chef::Log.debug("#{@new_resource}: Performing query [#{new_resource.sql_query}]")
      db.query(@new_resource.sql_query)
      @new_resource.updated_by_last_action(true)
    ensure
      close
    end
  end
end

#load_current_resourceObject



27
28
29
30
31
32
33
# File 'lib/cookbooks/database/libraries/provider_database_mysql.rb', line 27

def load_current_resource
  Gem.clear_paths
  require 'mysql'
  @current_resource = Chef::Resource::Database.new(@new_resource.name)
  @current_resource.database_name(@new_resource.database_name)
  @current_resource
end