DBIx-Class-Migration
view release on metacpan or search on metacpan
t/migration-mysql.t view on Meta::CPAN
use strict;
use warnings;
BEGIN {
use Test::Most;
plan skip_all => 'DBICM_TEST_MYSQL not set'
unless $ENV{DBICM_TEST_MYSQL} || $ENV{AUTHOR_MODE};
}
use lib 't/lib';
use DBIx::Class::Migration;
use File::Spec::Functions 'catfile', 'splitpath';
use File::Path 'rmtree';
use Test::Requires qw(Test::mysqld);
use File::Temp 'tempdir';
my $dir = tempdir(CLEANUP => 1); # can't put under "t" as mysqld refuses
chmod 0777, $dir; # default is very secure but mysqld cannot get at it
ok(
my $migration = DBIx::Class::Migration->new(
schema_class=>'Local::Schema',
target_dir => $dir,
db_sandbox_class=>'DBIx::Class::Migration::MySQLSandbox',
),
'created migration with schema_class');
isa_ok(
my $schema = $migration->schema, 'Local::Schema',
'got a reasonable looking schema');
is(
DBIx::Class::Migration::_infer_database_from_schema($schema),
'MySQL',
'can correctly infer a database DBD');
$migration->prepare;
ok(
(my $target_dir = $migration->target_dir),
'got a good target directory');
ok -d catfile($target_dir, 'fixtures'), 'got fixtures';
ok -e catfile($target_dir, 'fixtures','1','conf','all_tables.json'), 'got the all_tables.json';
ok -d catfile($target_dir, 'migrations'), 'got migrations';
ok -e catfile($target_dir, 'migrations','MySQL','deploy','1','001-auto.sql'), 'found DDL';
open(
my $perl_run,
">",
catfile($target_dir, 'migrations', 'MySQL', 'deploy', '1', '002-artists.pl')
) || die "Cannot open: $!";
print $perl_run <<'END';
use Test::Most;
use DBIx::Class::Migration::RunScript;
migrate {
my $self = shift;
if($self->set_has_fixtures('all_tables')) {
lives_ok { $self->populate('all_tables') } "->populate('all_tables')";
} else {
$self->schema
->resultset('Country')
->populate([
['code'],
['bel'],
['deu'],
['fra'],
]);
lives_ok { $self->dump('all_tables') } "->dump('all_tables')";
ok $self->set_has_fixtures('all_tables'),
'Fixture Set exists!';
}
};
( run in 0.792 second using v1.01-cache-2.11-cpan-39bf76dae61 )