1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
package TestSchema;
use strict;
use warnings;
use File::Spec;
our $VERSION = 0.001;
use parent 'DBIx::Class::Schema';
__PACKAGE__->load_namespaces(
default_resultset_class => 'ResultSet',
);
__PACKAGE__->load_components(qw(
Helper::Schema::LintContents
Helper::Schema::QuoteNames
Helper::Schema::DidYouMean
));
sub upgrade_directory { './t/lib' }
sub ddl_filename {
my $self = shift;
$_[2] = $self->upgrade_directory;
$self->next::method(@_)
}
sub deploy_or_connect {
my $self = shift;
my $schema = $self->connect(@_);
$schema->deploy();
return $schema;
}
sub connection {
my $self = shift;
if (@_) {
return $self->next::method(@_);
} else {
return $self->next::method('dbi:SQLite::memory:');
}
}
sub generate_ddl {
my $self = shift;
my $schema = $self->connect;
$schema->create_ddl_dir(
$_,
$schema->schema_version,
undef,
undef, {
($_ ne 'SQLite'
? (
add_drop_table => 1,
filters => [
sub {
#remove circular dependency. Not used for
#non-sqlite tests
my $foo = shift->get_table('Foo');
my @constraints = map { $_->name } $foo->get_constraints;
$foo->drop_constraint($_) for grep { /bar/ } @constraints;
}
]
)
: ( add_drop_table => 0 )
)
},
) for qw(SQLite MySQL PostgreSQL SQLServer Oracle);
}
sub prepopulate {
my $self = shift;
$self->resultset($_)->delete for qw{Bar Foo Gnarly_Station Bloaty Gnarly Station HasAccessor};
$self->populate( Gnarly => [
[qw{id name}],
[1,'frew'],
[2,'frioux'],
[3,'frooh'],
]);
$self->populate( Station => [
[qw{id name}],
[1,'frew'],
[2,'frioux'],
[3,'frooh'],
]);
$self->populate( Gnarly_Station => [
[qw{gnarly_id station_id}],
[1,1],
[1,3],
[2,1],
[3,1],
]);
$self->populate(Bloaty => [
[qw{id name}],
[1,1],
[2,2],
[3,3],
[4,4],
[5,5],
]);
$self->populate(Foo => [
[qw{id bar_id}],
[1,1],
[2,2],
[3,3],
[4,4],
[5,5],
]);
$self->populate(Bar => [
[qw{id foo_id}],
[1,1],
[2,2],
[3,3],
[4,4],
[5,5],
]);
$self->populate( HasAccessor => [
[qw{id usable_column unusable_column}],
[1,'aa','bb'],
[2,'cc','dd'],
[3,'ee','ff'],
]);
$self->populate(SerializeAll => [
[qw{id text_column}],
[1,'frew'],
[2,'frioux'],
[3,'frooh'],
]);
}
'kitten eater';
|