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';
25 DBICTest->init_schema(no_deploy => 1, no_populate => 1);
27 my $db_fn = DBICTest->_sqlite_dbfilename;
32 { on_connect_do => 'PRAGMA synchronous = OFF' },
34 my $ddl_dir = dir(qw/t var/, "admin_ddl-$$");
38 # make sure we are clean
42 my $admin = DBIx::Class::Admin->new(
43 schema_class=> "DBICTest::Schema",
45 connect_info => \@connect_info,
47 isa_ok ($admin, 'DBIx::Class::Admin', 'create the admin object');
48 lives_ok { $admin->create('MySQL'); } 'Can create MySQL sql';
49 lives_ok { $admin->create('SQLite'); } 'Can Create SQLite sql';
51 $SIG{__WARN__} = sub { warn @_ unless $_[0] =~ /no such table.+DROP TABLE/s };
53 } 'Can Deploy schema';
59 require DBICVersion_v1;
61 my $admin = DBIx::Class::Admin->new(
62 schema_class => 'DBICVersion::Schema',
64 connect_info => \@connect_info,
67 my $schema = $admin->schema();
69 lives_ok { $admin->create($schema->storage->sqlt_type(), {add_drop_table=>0}); } 'Can create DBICVersionOrig sql in ' . $schema->storage->sqlt_type;
70 lives_ok { $admin->deploy( ) } 'Can Deploy schema';
72 # connect to now deployed schema
73 lives_ok { $schema = DBICVersion::Schema->connect(@{$schema->storage->connect_info()}); } 'Connect to deployed Database';
75 is($schema->get_db_version, $DBICVersion::Schema::VERSION, 'Schema deployed and versions match');
78 require DBICVersion_v2;
79 DBICVersion::Schema->upgrade_directory (undef); # so that we can test use of $ddl_dir
81 $admin = DBIx::Class::Admin->new(
82 schema_class => 'DBICVersion::Schema',
84 connect_info => \@connect_info
87 lives_ok { $admin->create($schema->storage->sqlt_type(), {}, "1.0" ); } 'Can create diff for ' . $schema->storage->sqlt_type;
89 local $SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /DB version .+? is lower than the schema version/ };
90 lives_ok {$admin->upgrade();} 'upgrade the schema';
91 dies_ok {$admin->deploy} 'cannot deploy installed schema, should upgrade instead';
94 is($schema->get_db_version, $DBICVersion::Schema::VERSION, 'Schema and db versions match');
102 my $admin = DBIx::Class::Admin->new(
103 schema_class => 'DBICVersion::Schema',
106 connect_info => \@connect_info,
109 $admin->version("3.0");
110 lives_ok { $admin->install(); } 'install schema version 3.0';
111 is($admin->schema->get_db_version, "3.0", 'db thinks its version 3.0');
112 dies_ok { $admin->install("4.0"); } 'cannot install to allready existing version';
115 warnings_exist ( sub {
116 lives_ok { $admin->install("4.0") } 'can force install to allready existing version'
117 }, qr/Forcing install may not be a good idea/, 'Force warning emitted' );
118 is($admin->schema->get_db_version, "4.0", 'db thinks its version 4.0');
123 $dir->rmtree if -d $dir;