in reply to Database-independent means of creating database?

DBIx::Class::Schema->deploy can do this. You write -- or can automatically generate with DBIx::Class::Schema::Loader's make_schema_at if you have a DB already -- your DBIC schema. Then you can deploy it to (most) any DB by providing a valid/permissive connection.

There are caveats and edge cases because DBs can be customized so much; read the docs thoroughly.

Class::DBI might have similar functionality now, it didn't in the past. I used it a lot for a couple of years but haven't gone back since DBIC matured.

Replies are listed 'Best First'.
Re^2: Database-independent means of creating database?
by unix_hacker_beard (Novice) on Jan 25, 2011 at 16:14 UTC
    Great! This seems to be what I was looking for!
Re^2: Database-independent means of creating database?
by unix_hacker_beard (Novice) on Jan 26, 2011 at 21:32 UTC
    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...

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