Skip to content

Commit

Permalink
Merge branch 'COOK-521'
Browse files Browse the repository at this point in the history
  • Loading branch information
schisamo committed Apr 25, 2011
2 parents 0002378 + ca4862e commit 6774225
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 26 deletions.
6 changes: 3 additions & 3 deletions mysql/libraries/database.rb
Expand Up @@ -8,11 +8,11 @@ module Opscode
module Mysql
module Database
def db
@@db ||= ::Mysql.new new_resource.host, new_resource.username, new_resource.password
@db ||= ::Mysql.new new_resource.host, new_resource.username, new_resource.password
end
def close
@@db.close rescue nil
@@db = nil
@db.close rescue nil
@db = nil
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion mysql/metadata.json
Expand Up @@ -222,5 +222,5 @@
"mysql::server": "Installs packages required for mysql servers w/o manual intervention",
"mysql::server_ec2": "Performs EC2-specific mountpoint manipulation"
},
"version": "1.0.1"
"version": "1.0.2"
}
2 changes: 1 addition & 1 deletion mysql/metadata.rb
Expand Up @@ -3,7 +3,7 @@
license "Apache 2.0"
description "Installs and configures mysql for client or server"
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version "1.0.1"
version "1.0.2"
recipe "mysql", "Includes the client recipe to configure a client"
recipe "mysql::client", "Installs packages required for mysql clients using run_action magic"
recipe "mysql::server", "Installs packages required for mysql servers w/o manual intervention"
Expand Down
51 changes: 30 additions & 21 deletions mysql/providers/database.rb
Expand Up @@ -20,27 +20,31 @@
include Opscode::Mysql::Database

action :flush_tables_with_read_lock do
begin
Chef::Log.info "mysql_database: flushing tables with read lock"
db.query "flush tables with read lock"
new_resource.updated_by_last_action(true)
ensure
db.close
if exists?
begin
Chef::Log.info "mysql_database: flushing tables with read lock"
db.query "flush tables with read lock"
new_resource.updated_by_last_action(true)
ensure
db.close
end
end
end

action :unflush_tables do
begin
Chef::Log.info "mysql_database: unlocking tables"
db.query "unlock tables"
new_resource.updated_by_last_action(true)
ensure
db.close
if exists?
begin
Chef::Log.info "mysql_database: unlocking tables"
db.query "unlock tables"
new_resource.updated_by_last_action(true)
ensure
db.close
end
end
end

action :create_db do
unless @mysqldb.exists
unless exists?
begin
Chef::Log.info "mysql_database: Creating database #{new_resource.database}"
db.query("create database #{new_resource.database}")
Expand All @@ -52,12 +56,14 @@
end

action :query do
begin
Chef::Log.info "mysql_database: Performing Query: #{new_resource.sql}"
db.query(new_resource.sql)
new_resource.updated_by_last_action(true)
ensure
db.close
if exists?
begin
Chef::Log.info "mysql_database: Performing Query: #{new_resource.sql}"
db.query(new_resource.sql)
new_resource.updated_by_last_action(true)
ensure
db.close
end
end
end

Expand All @@ -67,6 +73,9 @@ def load_current_resource

@mysqldb = Chef::Resource::MysqlDatabase.new(new_resource.name)
@mysqldb.database(new_resource.database)
exists = db.list_dbs.include?(new_resource.database)
@mysqldb.exists(exists)
end

private
def exists?
db.list_dbs.include?(new_resource.database)
end

0 comments on commit 6774225

Please sign in to comment.