in reply to Re: Database-independent means of creating database?
in thread Database-independent means of creating database?

This is working great and is successfully creating my database from the provided schema but is there a way to make sure the database doesn't exist before calling deploy? I tried checking $@ after calling deploy inside an eval but it stays empty. If I'm using SQLite I can check if -e but I'd rather not be limited to any certain database...
  • Comment on Re^2: Database-independent means of creating database?

Replies are listed 'Best First'.
Re^3: Database-independent means of creating database?
by Your Mother (Archbishop) on Jan 27, 2011 at 01:20 UTC

    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"; }