Introducing DBIx::Class::Schema::SanityChecker
[dbsrgits/DBIx-Class.git] / t / cdbi / testlib / MyBase.pm
CommitLineData
c6d74d3e 1package # hide from PAUSE
2 MyBase;
ea2e61bf 3
4a233f30 4use warnings;
ea2e61bf 5use strict;
4a233f30 6
d2cee1fa 7use DBI;
8d6b1478 8use DBICTest;
9
12e7015a 10BEGIN {
11 # offset the warning from DBIx::Class::Schema on 5.8
12 # keep the ::Schema default as-is otherwise
13 DBIx::Class::_ENV_::OLD_MRO
14 and
15 ( eval <<'EOS' or die $@ );
16
17 sub setup_schema_instance {
18 my $s = shift->next::method(@_);
19 $s->schema_sanity_checker('');
20 $s;
21 }
22
23 1;
24EOS
25}
26
8d6b1478 27use base qw(DBIx::Class::CDBICompat);
28
9381840d 29my @connect = (@ENV{map { "DBICTEST_MYSQL_${_}" } qw/DSN USER PASS/}, { PrintError => 0});
8d6b1478 30# this is only so we grab a lock on mysql
31{
32 my $x = DBICTest::Schema->connect(@connect);
33}
34
83eef562 35our $dbh = DBI->connect(@connect) or die DBI->errstr;
ea2e61bf 36my @table;
37
961d79db 38END {
39 $dbh->do("DROP TABLE $_") for @table;
40 undef $dbh;
41}
ea2e61bf 42
43__PACKAGE__->connection(@connect);
44
45sub set_table {
6a3bf251 46 my $class = shift;
47 $class->table($class->create_test_table);
ea2e61bf 48}
49
50sub create_test_table {
6a3bf251 51 my $self = shift;
52 my $table = $self->next_available_table;
53 my $create = sprintf "CREATE TABLE $table ( %s )", $self->create_sql;
54 push @table, $table;
55 $dbh->do($create);
56 return $table;
ea2e61bf 57}
58
59sub next_available_table {
6a3bf251 60 my $self = shift;
61 my @tables = sort @{
62 $dbh->selectcol_arrayref(
63 qq{
ea2e61bf 64 SHOW TABLES
65 }
6a3bf251 66 )
67 };
68 my $table = $tables[-1] || "aaa";
69 return "z$table";
ea2e61bf 70}
71
721;