Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

DBIC & deploy

by pileofrogs (Priest)
on Mar 30, 2009 at 19:56 UTC ( #754237=perlquestion: print w/ replies, xml ) Need Help??
pileofrogs has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks.

I'm working with a DBIx::Class::Schema object and I've just discovered the 'deploy' method, which will create all my tables for me if they don't exist. What I haven't yet found is a good way to determine if the tables are already there.

So, my question is, if you are using the deploy method of a DBIx::Class::Schema object, how do you tell if the database is already deployed?

I'm going to use this for testing, where I create a sqlite db on the fly during testing and I'm going to probably use this to make installing my app on various servers easier.

Thanks!

--Pileofrogs

Comment on DBIC & deploy
Re: DBIC & deploy
by afoken (Parson) on Mar 30, 2009 at 23:38 UTC

    Some ideas:

      1. CREATE TABLE foo will fail when a table foo exists
      2. DBI should report the error
      3. deploy should fail
    • SELECT 42 AS result FROM foo should fail when no table and no view named foo exists
    • You can enumerate the tables in the database, and you can enumerate the columns in the table.

    Testing one table is usually not sufficient, as you usually have more than one table, and you may add or remove tables as development goes on. The same applies to columns in the tables. Ideally, deploy() should handle all these cases.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
Re: DBIC & deploy
by castaway (Parson) on Mar 31, 2009 at 06:45 UTC
    At which level do you want to find out? DBIx::Class::Schema::Versioned uses this construct:
    sub _source_exists { my ($self, $rs) = @_; my $c = eval { $rs->search({ 1, 0 })->count; }; return 0 if $@ || !defined $c; return 1; }
    This is called on a $schema object, and passed a plain $resultset object.

    Or you could just use Versioned.

    C.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://754237]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2014-12-28 08:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (179 votes), past polls