I think there is probably a better way—and I’d like to know one but don’t have time to code dive, play—but this kind of thing should work.
use warnings;
no warnings "uninitialized";
use strict;
use MyApp::Schema;
my $schema = MyApp::Schema->connect("dbi:SQLite::memory:");
my ( $first_source ) = $schema->sources;
my $ok = eval {
$schema->resultset($first_source)->count || 1;
};
if ( $@ =~ /no such table/ )
{
warn $@;
print "Trying to deploy...\n";
$schema->deploy;
$schema->resultset($first_source)->count;
print "Deploy seems good!\n";
}
elsif ( not $ok )
{
die $@ || "Uh... something bad, something, something\n";
}
|