10 plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for('admin')
11 unless DBIx::Class::Optional::Dependencies->req_ok_for('admin');
13 plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for('deploy')
14 unless DBIx::Class::Optional::Dependencies->req_ok_for('deploy');
22 use_ok 'DBIx::Class::Admin';
25 my $sql_dir = dir(qw/t var/);
26 my @connect_info = DBICTest->_database(
34 # make sure we are clean
38 my $admin = DBIx::Class::Admin->new(
39 schema_class=> "DBICTest::Schema",
41 connect_info => \@connect_info,
43 isa_ok ($admin, 'DBIx::Class::Admin', 'create the admin object');
44 lives_ok { $admin->create('MySQL'); } 'Can create MySQL sql';
45 lives_ok { $admin->create('SQLite'); } 'Can Create SQLite sql';
47 $SIG{__WARN__} = sub { warn @_ unless $_[0] =~ /no such table.+DROP TABLE/s };
49 } 'Can Deploy schema';
55 require DBICVersion_v1;
57 my $admin = DBIx::Class::Admin->new(
58 schema_class => 'DBICVersion::Schema',
60 connect_info => \@connect_info,
63 my $schema = $admin->schema();
65 lives_ok { $admin->create($schema->storage->sqlt_type(), {add_drop_table=>0}); } 'Can create DBICVersionOrig sql in ' . $schema->storage->sqlt_type;
66 lives_ok { $admin->deploy( ) } 'Can Deploy schema';
68 # connect to now deployed schema
69 lives_ok { $schema = DBICVersion::Schema->connect(@{$schema->storage->connect_info()}); } 'Connect to deployed Database';
71 is($schema->get_db_version, $DBICVersion::Schema::VERSION, 'Schema deployed and versions match');
74 require DBICVersion_v2;
75 DBICVersion::Schema->upgrade_directory (undef); # so that we can test use of $sql_dir
77 $admin = DBIx::Class::Admin->new(
78 schema_class => 'DBICVersion::Schema',
80 connect_info => \@connect_info
83 lives_ok { $admin->create($schema->storage->sqlt_type(), {}, "1.0" ); } 'Can create diff for ' . $schema->storage->sqlt_type;
85 local $SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /DB version .+? is lower than the schema version/ };
86 lives_ok {$admin->upgrade();} 'upgrade the schema';
87 dies_ok {$admin->deploy} 'cannot deploy installed schema, should upgrade instead';
90 is($schema->get_db_version, $DBICVersion::Schema::VERSION, 'Schema and db versions match');
98 my $admin = DBIx::Class::Admin->new(
99 schema_class => 'DBICVersion::Schema',
102 connect_info => \@connect_info,
105 $admin->version("3.0");
106 lives_ok { $admin->install(); } 'install schema version 3.0';
107 is($admin->schema->get_db_version, "3.0", 'db thinks its version 3.0');
108 dies_ok { $admin->install("4.0"); } 'cannot install to allready existing version';
111 warnings_exist ( sub {
112 lives_ok { $admin->install("4.0") } 'can force install to allready existing version'
113 }, qr/Forcing install may not be a good idea/, 'Force warning emitted' );
114 is($admin->schema->get_db_version, "4.0", 'db thinks its version 4.0');
115 #clean_dir($sql_dir);
120 $dir = $dir->resolve;
124 foreach my $file ($dir->children) {
125 # skip any hidden files
126 next if ($file =~ /^\./);