Conditionnally loading a MySQL database

Hello,

Anybody know of a cookbook that would allow to load a SQL dump from a
recipes, but only if the databases is still empty?

The database cookbook make no reference to this, neither the mysql
cookbook.

I could load the script with an execute block calling mysql without problem,
but how can I query the database to look for the missing data? The database
:query action seems more made for manipulation than query, like flushing
privileges but not actually reading results, am I right?

For now, I’m going to use a marker file (since it’s only for development
purpose), but any idea or example on how I could do that?

Thanks

Benoit

On Fri, Oct 7, 2011 at 11:21 AM, Benoit Caron benoit@patentemoi.ca wrote:

Anybody know of a cookbook that would allow to load a SQL dump from a
recipes, but only if the databases is still empty?

This recipe creates a database if it doesn't exist:

https://github.com/opscode/cookbooks/blob/master/wordpress/recipes/default.rb#L76

Also take a look at my MySQL Ruby example in this blog post for a
larger example:

http://blog.loftninjas.org/2011/02/16/the-power-of-chef-and-ruby/

Bryan

On Fri, Oct 7, 2011 at 11:33 AM, Bryan McLellan btm@loftninjas.org wrote:

On Fri, Oct 7, 2011 at 11:21 AM, Benoit Caron benoit@patentemoi.ca
wrote:

Anybody know of a cookbook that would allow to load a SQL dump from a
recipes, but only if the databases is still empty?

This recipe creates a database if it doesn't exist:

https://github.com/opscode/cookbooks/blob/master/wordpress/recipes/default.rb#L76

Great!

Way more neat than what I was about to do :\

Also take a look at my MySQL Ruby example in this blog post for a
larger example:

The power of Chef and Ruby | btm.geek

The lesson learned: use the force (or ruby blocks, whichever are available).

Thanks!