10 eval "use DBIx::Class::Admin";
11 plan skip_all => "Deps not installed: $@" if $@;
20 use ok 'DBIx::Class::Admin';
23 my $sql_dir = dir(qw/t var/);
24 my @connect_info = DBICTest->_database(
31 # make sure we are clean
35 my $admin = DBIx::Class::Admin->new(
36 schema_class=> "DBICTest::Schema",
38 connect_info => \@connect_info,
40 isa_ok ($admin, 'DBIx::Class::Admin', 'create the admin object');
41 lives_ok { $admin->create('MySQL'); } 'Can create MySQL sql';
42 lives_ok { $admin->create('SQLite'); } 'Can Create SQLite sql';
47 #my $schema = DBICTest->init_schema(
50 # sqlite_use_file => 1,
54 require DBICVersionOrig;
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 DBICVersionNew;
75 $admin = DBIx::Class::Admin->new(
76 schema_class => 'DBICVersion::Schema',
78 connect_info => \@connect_info
81 lives_ok { $admin->create($schema->storage->sqlt_type(), {}, "1.0" ); } 'Can create diff for ' . $schema->storage->sqlt_type;
82 # sleep required for upgrade table to hold a distinct time of upgrade value
83 # otherwise the returned of get_db_version can be undeterministic
86 local $SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /DB version .+? is lower than the schema version/ };
87 lives_ok {$admin->upgrade();} 'upgrade the schema';
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 =~ /^\./);