Thursday, July 9, 2009

Quieter PostgreSQL deployment from DBIx::Class

I use DBIx::Class to deploy my SQL schema to the database, rather than hand-crafting SQL.
This allows me to deploy the schema to a variety of databases easily, without worrying about inter-database SQL concerns.

In my unit tests, I create quite a lot of test databases.. PostgreSQL in particular is very noisy during this process, printing a LOT of "NOTICE" messages to the console. I wanted to quieten it down, so that actual test failures/warnings were more obvious.

If you'd like that too, try this in your MyApp::Schema class:


# If you use Moose:
before 'deploy' => sub {
my $schema = shift;
$schema->storage->dbh->do('SET client_min_messages = warning');
};

# If you don't use Moose:
sub deploy {
my $schema = shift;
$schema->storage->dbh->do('SET client_min_messages = warning');
$schema->next::method(@_);
}