DBIx-Class-Migration

 view release on metacpan or  search on metacpan

lib/DBIx/Class/Migration/MySQLSandbox.pm  view on Meta::CPAN

  my $mysqld = $self->test_mysqld->{mysqld};
  my $my_cnf = catfile($base_dir, 'etc', 'my.cnf');
  print $fh <<START;
#!/usr/bin/env sh

$mysqld --defaults-file=$my_cnf &
START

  close($fh);

  chmod oct("0755"), catfile($bin, 'start');
}

sub _write_stop {
  my $base_dir = (my $self = shift)->test_mysqld->base_dir;
  mkpath(my $bin = catdir($base_dir, 'bin'));
  open( my $fh, '>', catfile($bin, 'stop'))
    || $self->log_die( "Cannot open $bin/stop: $!" );

  my $PIDFILE = $self->test_mysqld->{my_cnf}->{'pid-file'};
  print $fh <<STOP;
#!/usr/bin/env sh

kill \$(cat $PIDFILE)
STOP

  close($fh);

  chmod oct("0755"), catfile($bin, 'stop');
}

sub _write_use {
  my $base_dir = (my $self = shift)->test_mysqld->base_dir;
  mkpath(my $bin = catdir($base_dir, 'bin'));
  open( my $fh, '>', catfile($bin, 'use'))
    || $self->log_die( "Cannot open $bin/use: $!" );

  my $mysqld = $self->test_mysqld->{mysqld};
  my $SOCKET = $self->test_mysqld->my_cnf->{socket};
  $mysqld =~s/d$//; ## ug. sorry :(

  print $fh <<USE;
#!/usr/bin/env sh

$mysqld --socket=$SOCKET -u root test
USE

  close($fh);

  chmod oct("0755"), catfile($bin, 'use');
}

sub make_sandbox {
  my $self = shift;
  my $base_dir = $self->_generate_sandbox_dir;

  if( -e catfile($base_dir, 'tmp', 'mysqld.pid')) {
    return $self->test_mysqld->dsn;
  } elsif($self->test_mysqld) {
    $self->_write_start;

lib/DBIx/Class/Migration/PostgresqlSandbox.pm  view on Meta::CPAN

  my $port = $test_postgresql->{port};

  print $fh <<START;
#!/usr/bin/env sh

$postmaster -p $port -D $data &
START

  close($fh);

  chmod oct("0755"), catfile($bin, 'start');
}

sub _write_stop {
  my $base_dir = (my $self = shift)->test_postgresql->base_dir;
  mkpath(my $bin = catdir($base_dir, 'bin'));
  open( my $fh, '>', catfile($bin, 'stop'))
    || $self->log_die( "Cannot open $bin/stop: $!" );

  my $test_postgresql = $self->test_postgresql;
  my $postmaster = $test_postgresql->{postmaster};
  my $pid = catdir($base_dir, 'data','postmaster.pid');

  print $fh <<STOP;
#!/usr/bin/env sh

kill -INT `head -1 $pid`
STOP

  close($fh);

  chmod oct("0755"), catfile($bin, 'stop');
}

sub _write_use {
  my $base_dir = (my $self = shift)->test_postgresql->base_dir;
  mkpath(my $bin = catdir($base_dir, 'bin'));
  open( my $fh, '>', catfile($bin, 'use'))
    || $self->log_die( "Cannot open $bin/use: $!" );

  my $test_postgresql = $self->test_postgresql;
  my $postmaster = $test_postgresql->{postmaster};

lib/DBIx/Class/Migration/PostgresqlSandbox.pm  view on Meta::CPAN

  my $port = $test_postgresql->{port};

  print $fh <<USE;
#!/usr/bin/env sh

$psql -h localhost --user postgres --port $port -d template1
USE

  close($fh);

  chmod oct("0755"), catfile($bin, 'use');
}

sub _write_dump {
  my $base_dir = (my $self = shift)->test_postgresql->base_dir;
  mkpath(my $bin = catdir($base_dir, 'bin'));
  open( my $fh, '>', catfile($bin, 'dump'))
    || $self->log_die( "Cannot open $bin/dump: $!" );

  my $test_postgresql = $self->test_postgresql;
  my $postmaster = $test_postgresql->{postmaster};

lib/DBIx/Class/Migration/PostgresqlSandbox.pm  view on Meta::CPAN

  my $port = $test_postgresql->{port};

  print $fh <<USE;
#!/usr/bin/env sh

$psql -h localhost --user postgres --port $port \$@
USE

  close($fh);

  chmod oct("0755"), catfile($bin, 'dump');
}

sub _write_config {
  my $base_dir = (my $self = shift)->test_postgresql->base_dir;
  mkpath(my $bin = catdir($base_dir, 'bin'));
  open( my $fh, '>', catfile($bin, 'config'))
    || $self->log_die( "Cannot open $bin/config $!" );

  my $test_postgresql = $self->test_postgresql;
  my $postmaster = $test_postgresql->{postmaster};

lib/DBIx/Class/Migration/PostgresqlSandbox.pm  view on Meta::CPAN


  print $fh <<USE;
#!/usr/bin/env perl

my \$connect_info => { dsn => 'DBI:Pg:dbname=template1;host=localhost;port=$port', user => 'postgres', password => '' }

USE

  close($fh);

  chmod oct("0755"), catfile($bin, 'config');
}


sub make_sandbox {
  my $self = shift;
  my $base_dir = $self->_generate_sandbox_dir;

  if($self->test_postgresql) {
    $self->_write_start;
    $self->_write_stop;

t/migration-mysql.t  view on Meta::CPAN

    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(



( run in 0.238 second using v1.01-cache-2.11-cpan-8d75d55dd25 )