Class: Chef::Provider::Database::Mysql
- Inherits:
-
Chef::Provider
- Object
- Chef::Provider
- Chef::Provider::Database::Mysql
- Includes:
- Mixin::ShellOut
- Defined in:
- lib/cookbooks/database/libraries/provider_database_mysql.rb
Direct Known Subclasses
Instance Method Summary collapse
- #action_create ⇒ Object
- #action_drop ⇒ Object
- #action_query ⇒ Object
- #load_current_resource ⇒ Object
Instance Method Details
#action_create ⇒ Object
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_drop ⇒ Object
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_query ⇒ Object
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_resource ⇒ Object
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 |