Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

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.



Replies are listed 'Best First'.
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.

Re: DBIC & deploy
by afoken (Monsignor) 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.


    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://754237]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2017-04-28 18:55 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (528 votes). Check out past polls.