checking for table existande before adding add_drop_table
[chaz/p5-DBIx-Class-ResultSet-RecursiveUpdate] / t / lib / DBSchema.pm
1 package DBSchema;
2
3 # Created by DBIx::Class::Schema::Loader v0.03000 @ 2006-10-02 08:24:09
4
5 use strict;
6 use warnings;
7
8 use base 'DBIx::Class::Schema';
9 use DateTime;
10
11 __PACKAGE__->load_namespaces( default_resultset_class => '+DBIx::Class::ResultSet::RecursiveUpdate' );
12
13 sub tables_exist {
14 my ( $dsn, $user, $pass ) = @_;
15 my $dbh = DBI->connect($dsn, $user, $pass, );
16 return $dbh->tables( '%', '%', 'dvd', );
17 }
18
19
20 sub get_test_schema {
21 my ( $dsn, $user, $pass ) = @_;
22 $dsn ||= 'dbi:SQLite:dbname=t/var/dvdzbr.db';
23 warn "testing $dsn";
24 my $schema = __PACKAGE__->connect( $dsn, $user, $pass, {} );
25 my $deploy_attrs;
26 $deploy_attrs->{add_drop_table} = 1 if tables_exist( $dsn, $user, $pass );
27 $schema->deploy( $deploy_attrs );
28 $schema->populate('User', [
29 [ qw/username name password / ],
30 [ 'jgda', 'Jonas Alves', ''],
31 [ 'isa' , 'Isa', '', ],
32 [ 'zby' , 'Zbyszek Lukasiak', ''],
33 ]
34 );
35 $schema->populate('Tag', [
36 [ qw/name file / ],
37 [ 'comedy', '' ],
38 [ 'dramat', '' ],
39 [ 'australian', '' ],
40 ]
41 );
42 $schema->populate('Dvd', [
43 [ qw/name imdb_id owner current_borrower creation_date alter_date / ],
44 [ 'Picnick under the Hanging Rock', 123, 1, 3, '2003-01-16 23:12:01', undef ],
45 [ 'The Deerhunter', 1234, 1, 1, undef, undef ],
46 [ 'Rejs', 1235, 3, 1, undef, undef ],
47 [ 'Seksmisja', 1236, 3, 1, undef, undef ],
48 ]
49 );
50 $schema->populate( 'Dvdtag', [
51 [ qw/ dvd tag / ],
52 [ 1, 2 ],
53 [ 1, 3 ],
54 [ 3, 1 ],
55 [ 4, 1 ],
56 ]
57 );
58 return $schema;
59 }
60
61
62 1;
63
This page took 0.040084 seconds and 5 git commands to generate.