2 #===============================================================================
11 # AUTHOR: Gordon Irving (), <goraxe@cpan.org>
13 # CREATED: 28/11/09 16:14:21 GMT
15 #===============================================================================
26 eval "use DBIx::Class::Admin";
27 plan skip_all => "Deps not installed: $@" if $@;
36 use ok 'DBIx::Class::Admin';
39 my $sql_dir = dir(qw/t var/);
40 my @connect_info = DBICTest->_database(
47 # make sure we are clean
51 my $admin = DBIx::Class::Admin->new(
52 schema_class=> "DBICTest::Schema",
54 connect_info => \@connect_info,
56 isa_ok ($admin, 'DBIx::Class::Admin', 'create the admin object');
57 lives_ok { $admin->create('MySQL'); } 'Can create MySQL sql';
58 lives_ok { $admin->create('SQLite'); } 'Can Create SQLite sql';
63 #my $schema = DBICTest->init_schema(
66 # sqlite_use_file => 1,
70 require DBICVersionOrig;
72 my $admin = DBIx::Class::Admin->new(
73 schema_class => 'DBICVersion::Schema',
75 connect_info => \@connect_info,
78 my $schema = $admin->schema();
80 lives_ok { $admin->create($schema->storage->sqlt_type(), {add_drop_table=>0}); } 'Can create DBICVersionOrig sql in ' . $schema->storage->sqlt_type;
81 lives_ok { $admin->deploy( ) } 'Can Deploy schema';
83 # connect to now deployed schema
84 lives_ok { $schema = DBICVersion::Schema->connect(@{$schema->storage->connect_info()}); } 'Connect to deployed Database';
86 is($schema->get_db_version, $DBICVersion::Schema::VERSION, 'Schema deployed and versions match');
89 require DBICVersionNew;
91 $admin = DBIx::Class::Admin->new(
92 schema_class => 'DBICVersion::Schema',
94 connect_info => \@connect_info
97 lives_ok { $admin->create($schema->storage->sqlt_type(), {}, "1.0" ); } 'Can create diff for ' . $schema->storage->sqlt_type;
98 # sleep required for upgrade table to hold a distinct time of upgrade value
99 # otherwise the returned of get_db_version can be undeterministic
102 local $SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /DB version .+? is lower than the schema version/ };
103 lives_ok {$admin->upgrade();} 'upgrade the schema';
106 is($schema->get_db_version, $DBICVersion::Schema::VERSION, 'Schema and db versions match');
114 my $admin = DBIx::Class::Admin->new(
115 schema_class => 'DBICVersion::Schema',
118 connect_info => \@connect_info,
121 $admin->version("3.0");
122 lives_ok { $admin->install(); } 'install schema version 3.0';
123 is($admin->schema->get_db_version, "3.0", 'db thinks its version 3.0');
124 dies_ok { $admin->install("4.0"); } 'cannot install to allready existing version';
127 warnings_exist ( sub {
128 lives_ok { $admin->install("4.0") } 'can force install to allready existing version'
129 }, qr/Forcing install may not be a good idea/, 'Force warning emitted' );
130 is($admin->schema->get_db_version, "4.0", 'db thinks its version 4.0');
131 #clean_dir($sql_dir);
136 $dir = $dir->resolve;
140 foreach my $file ($dir->children) {
141 # skip any hidden files
142 next if ($file =~ /^\./);