15 plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for('admin')
16 unless DBIx::Class::Optional::Dependencies->req_ok_for('admin');
18 plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for('deploy')
19 unless DBIx::Class::Optional::Dependencies->req_ok_for('deploy');
22 use_ok 'DBIx::Class::Admin';
24 my $sql_dir = dir(qw/t var/);
25 my @connect_info = DBICTest->_database(
33 # make sure we are clean
37 my $admin = DBIx::Class::Admin->new(
38 schema_class=> "DBICTest::Schema",
40 connect_info => \@connect_info,
42 isa_ok ($admin, 'DBIx::Class::Admin', 'create the admin object');
43 lives_ok { $admin->create('MySQL'); } 'Can create MySQL sql';
44 lives_ok { $admin->create('SQLite'); } 'Can Create SQLite sql';
46 $SIG{__WARN__} = sub { warn @_ unless $_[0] =~ /no such table.+DROP TABLE/s };
48 } 'Can Deploy schema';
54 require DBICVersion_v1;
56 my $admin = DBIx::Class::Admin->new(
57 schema_class => 'DBICVersion::Schema',
59 connect_info => \@connect_info,
62 my $schema = $admin->schema();
64 lives_ok { $admin->create($schema->storage->sqlt_type(), {add_drop_table=>0}); } 'Can create DBICVersionOrig sql in ' . $schema->storage->sqlt_type;
65 lives_ok { $admin->deploy( ) } 'Can Deploy schema';
67 # connect to now deployed schema
68 lives_ok { $schema = DBICVersion::Schema->connect(@{$schema->storage->connect_info()}); } 'Connect to deployed Database';
70 is($schema->get_db_version, $DBICVersion::Schema::VERSION, 'Schema deployed and versions match');
73 require DBICVersion_v2;
74 DBICVersion::Schema->upgrade_directory (undef); # so that we can test use of $sql_dir
76 $admin = DBIx::Class::Admin->new(
77 schema_class => 'DBICVersion::Schema',
79 connect_info => \@connect_info
82 lives_ok { $admin->create($schema->storage->sqlt_type(), {}, "1.0" ); } 'Can create diff for ' . $schema->storage->sqlt_type;
84 local $SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /DB version .+? is lower than the schema version/ };
85 lives_ok {$admin->upgrade();} 'upgrade the schema';
86 dies_ok {$admin->deploy} 'cannot deploy installed schema, should upgrade instead';
89 is($schema->get_db_version, $DBICVersion::Schema::VERSION, 'Schema and db versions match');
97 my $admin = DBIx::Class::Admin->new(
98 schema_class => 'DBICVersion::Schema',
101 connect_info => \@connect_info,
104 $admin->version("3.0");
105 lives_ok { $admin->install(); } 'install schema version 3.0';
106 is($admin->schema->get_db_version, "3.0", 'db thinks its version 3.0');
107 dies_ok { $admin->install("4.0"); } 'cannot install to allready existing version';
110 warnings_exist ( sub {
111 lives_ok { $admin->install("4.0") } 'can force install to allready existing version'
112 }, qr/Forcing install may not be a good idea/, 'Force warning emitted' );
113 is($admin->schema->get_db_version, "4.0", 'db thinks its version 4.0');
114 #clean_dir($sql_dir);
119 $dir = $dir->resolve;
123 foreach my $file ($dir->children) {
124 # skip any hidden files
125 next if ($file =~ /^\./);