X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fadmin%2F02ddl.t;h=8b1c57fc2d2ca28ae56eda711c8181d333ba3cba;hb=445bc0cd67d1176df63280ecbb415cd768a7c6df;hp=df24bad44bdba605fcb6a1752b452d8e32f868e9;hpb=1edd4ca695754f9ffdebff19f3ea918ecc72d2fd;p=dbsrgits%2FDBIx-Class.git diff --git a/t/admin/02ddl.t b/t/admin/02ddl.t index df24bad..8b1c57f 100644 --- a/t/admin/02ddl.t +++ b/t/admin/02ddl.t @@ -1,79 +1,66 @@ -# -#=============================================================================== -# -# FILE: 02admin..t -# -# DESCRIPTION: -# -# FILES: --- -# BUGS: --- -# NOTES: --- -# AUTHOR: Gordon Irving (), -# VERSION: 1.0 -# CREATED: 28/11/09 16:14:21 GMT -# REVISION: --- -#=============================================================================== - use strict; use warnings; -use Test::More; # last test to print - +use Test::More; use Test::Exception; +use Test::Warn; + +use Path::Class; +use lib qw(t/lib); +use DBICTest; BEGIN { - use FindBin qw($Bin); - use File::Spec::Functions qw(catdir); - use lib catdir($Bin,'..', '..','lib'); - use lib catdir($Bin,'..', 'lib'); + require DBIx::Class; + plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for('admin') + unless DBIx::Class::Optional::Dependencies->req_ok_for('admin'); - eval "use DBIx::Class::Admin"; - plan skip_all => "Deps not installed: $@" if $@; + plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for('deploy') + unless DBIx::Class::Optional::Dependencies->req_ok_for('deploy'); } -use Path::Class; - -use ok 'DBIx::Class::Admin'; +use_ok 'DBIx::Class::Admin'; -use DBICTest; +# lock early +DBICTest->init_schema(no_deploy => 1, no_populate => 1); -my $sql_dir = dir($Bin,"..","var"); -my @connect_info = DBICTest->_database( - no_deploy=>1, - no_populate=>1, - sqlite_use_file => 1, +my $db_fn = DBICTest->_sqlite_dbfilename; +my @connect_info = ( + "dbi:SQLite:$db_fn", + undef, + undef, + { on_connect_do => 'PRAGMA synchronous = OFF' }, ); +my $ddl_dir = dir(qw/t var/, "admin_ddl-$$"); + { # create the schema # make sure we are clean -clean_dir($sql_dir); +clean_dir($ddl_dir); my $admin = DBIx::Class::Admin->new( schema_class=> "DBICTest::Schema", - sql_dir=> $sql_dir, - connect_info => \@connect_info, + sql_dir=> $ddl_dir, + connect_info => \@connect_info, ); isa_ok ($admin, 'DBIx::Class::Admin', 'create the admin object'); lives_ok { $admin->create('MySQL'); } 'Can create MySQL sql'; lives_ok { $admin->create('SQLite'); } 'Can Create SQLite sql'; +lives_ok { + $SIG{__WARN__} = sub { warn @_ unless $_[0] =~ /no such table.+DROP TABLE/s }; + $admin->deploy() +} 'Can Deploy schema'; } { # upgrade schema -#my $schema = DBICTest->init_schema( -# no_deploy => 1, -# no_populat => 1, -# sqlite_use_file => 1, -#); - -clean_dir($sql_dir); -require DBICVersionOrig; +clean_dir($ddl_dir); +require DBICVersion_v1; my $admin = DBIx::Class::Admin->new( - schema_class => 'DBICVersion::Schema', - sql_dir => $sql_dir, + schema_class => 'DBICVersion::Schema', + sql_dir => $ddl_dir, connect_info => \@connect_info, ); @@ -88,19 +75,21 @@ lives_ok { $schema = DBICVersion::Schema->connect(@{$schema->storage->connect_in is($schema->get_db_version, $DBICVersion::Schema::VERSION, 'Schema deployed and versions match'); -require DBICVersionNew; +require DBICVersion_v2; +DBICVersion::Schema->upgrade_directory (undef); # so that we can test use of $ddl_dir $admin = DBIx::Class::Admin->new( - schema_class => 'DBICVersion::Schema', - sql_dir => "t/var", + schema_class => 'DBICVersion::Schema', + sql_dir => $ddl_dir, connect_info => \@connect_info ); lives_ok { $admin->create($schema->storage->sqlt_type(), {}, "1.0" ); } 'Can create diff for ' . $schema->storage->sqlt_type; -# sleep required for upgrade table to hold a distinct time of upgrade value -# otherwise the returned of get_db_version can be undeterministic -sleep 1; -lives_ok {$admin->upgrade();} 'upgrade the schema'; +{ + local $SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /DB version .+? is lower than the schema version/ }; + lives_ok {$admin->upgrade();} 'upgrade the schema'; + dies_ok {$admin->deploy} 'cannot deploy installed schema, should upgrade instead'; +} is($schema->get_db_version, $DBICVersion::Schema::VERSION, 'Schema and db versions match'); @@ -108,11 +97,11 @@ is($schema->get_db_version, $DBICVersion::Schema::VERSION, 'Schema and db versio { # install -clean_dir($sql_dir); +clean_dir($ddl_dir); my $admin = DBIx::Class::Admin->new( - schema_class => 'DBICVersion::Schema', - sql_dir => $sql_dir, + schema_class => 'DBICVersion::Schema', + sql_dir => $ddl_dir, _confirm => 1, connect_info => \@connect_info, ); @@ -121,24 +110,22 @@ $admin->version("3.0"); lives_ok { $admin->install(); } 'install schema version 3.0'; is($admin->schema->get_db_version, "3.0", 'db thinks its version 3.0'); dies_ok { $admin->install("4.0"); } 'cannot install to allready existing version'; -sleep 1; + $admin->force(1); -lives_ok { $admin->install("4.0"); } 'can force install to allready existing version'; +warnings_exist ( sub { + lives_ok { $admin->install("4.0") } 'can force install to allready existing version' +}, qr/Forcing install may not be a good idea/, 'Force warning emitted' ); is($admin->schema->get_db_version, "4.0", 'db thinks its version 4.0'); -#clean_dir($sql_dir); } sub clean_dir { - my ($dir) =@_; - $dir = $dir->resolve; - if ( ! -d $dir ) { - $dir->mkpath(); - } - foreach my $file ($dir->children) { - # skip any hidden files - next if ($file =~ /^\./); - unlink $file; - } + my ($dir) = @_; + $dir->rmtree if -d $dir; + unlink $db_fn; +} + +END { + clean_dir($ddl_dir); } done_testing;