X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fadmin%2F02ddl.t;h=b2414c356b4c43837dc161235566ee35102bf2a3;hb=da4a8fe752719362c6f6b1be5b42593fc4509ad6;hp=34957deb60f5666e78ed71533f3a77d708aca723;hpb=c71d3367894a638783d2c84cbf9ca68d72fdd314;p=dbsrgits%2FDBIx-Class.git diff --git a/t/admin/02ddl.t b/t/admin/02ddl.t index 34957de..b2414c3 100644 --- a/t/admin/02ddl.t +++ b/t/admin/02ddl.t @@ -1,3 +1,5 @@ +use DBIx::Class::Optional::Dependencies -skip_all_without => qw( admin deploy ); + use strict; use warnings; @@ -5,59 +7,54 @@ use Test::More; use Test::Exception; use Test::Warn; -BEGIN { - 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'); - - 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 lib qw(t/lib); use DBICTest; +use DBIx::Class::_Util 'sigwarn_silencer'; -use Path::Class; - -use_ok 'DBIx::Class::Admin'; +use DBIx::Class::Admin; +# lock early +DBICTest->init_schema(no_deploy => 1, no_populate => 1); -my $sql_dir = dir(qw/t 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 { + local $SIG{__WARN__} = sigwarn_silencer( qr/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); +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, ); @@ -73,17 +70,19 @@ is($schema->get_db_version, $DBICVersion::Schema::VERSION, 'Schema deployed and 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 => $sql_dir, + 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; { - local $SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /DB version .+? is lower than the schema version/ }; - lives_ok {$admin->upgrade();} 'upgrade the schema'; + local $SIG{__WARN__} = sigwarn_silencer( qr/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'); @@ -92,39 +91,37 @@ 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, ); $admin->version("3.0"); -lives_ok { $admin->install(); } 'install schema version 3.0'; +$admin->install; 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'; +throws_ok { + $admin->install("4.0") +} qr/Schema already has a version. Try upgrade instead/, 'cannot install to allready existing version'; $admin->force(1); warnings_exist ( sub { - lives_ok { $admin->install("4.0") } 'can force install to allready existing version' + $admin->install("4.0") }, 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; - } + $dir->rmtree if -d $dir; + unlink $db_fn; +} + +END { + clean_dir($ddl_dir); } done_testing;