1 use DBIx::Class::Optional::Dependencies -skip_all_without => qw( admin deploy );
14 use DBIx::Class::_Util 'sigwarn_silencer';
16 use DBIx::Class::Admin;
19 DBICTest->init_schema(no_deploy => 1, no_populate => 1);
21 my $db_fn = DBICTest->_sqlite_dbfilename;
26 { on_connect_do => 'PRAGMA synchronous = OFF' },
28 my $ddl_dir = dir(qw/t var/, "admin_ddl-$$");
32 # make sure we are clean
36 my $admin = DBIx::Class::Admin->new(
37 schema_class=> "DBICTest::Schema",
39 connect_info => \@connect_info,
41 isa_ok ($admin, 'DBIx::Class::Admin', 'create the admin object');
42 lives_ok { $admin->create('MySQL'); } 'Can create MySQL sql';
43 lives_ok { $admin->create('SQLite'); } 'Can Create SQLite sql';
45 local $SIG{__WARN__} = sigwarn_silencer( qr/no such table.+DROP TABLE/s );
47 } 'Can Deploy schema';
53 require DBICVersion_v1;
55 my $admin = DBIx::Class::Admin->new(
56 schema_class => 'DBICVersion::Schema',
58 connect_info => \@connect_info,
61 my $schema = $admin->schema();
63 lives_ok { $admin->create($schema->storage->sqlt_type(), {add_drop_table=>0}); } 'Can create DBICVersionOrig sql in ' . $schema->storage->sqlt_type;
64 lives_ok { $admin->deploy( ) } 'Can Deploy schema';
66 # connect to now deployed schema
67 lives_ok { $schema = DBICVersion::Schema->connect(@{$schema->storage->connect_info()}); } 'Connect to deployed Database';
69 is($schema->get_db_version, $DBICVersion::Schema::VERSION, 'Schema deployed and versions match');
72 require DBICVersion_v2;
73 DBICVersion::Schema->upgrade_directory (undef); # so that we can test use of $ddl_dir
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;
83 local $SIG{__WARN__} = sigwarn_silencer( qr/DB version .+? is lower than the schema version/ );
84 lives_ok { $admin->upgrade() } 'upgrade the schema';
85 dies_ok { $admin->deploy } 'cannot deploy installed schema, should upgrade instead';
88 is($schema->get_db_version, $DBICVersion::Schema::VERSION, 'Schema and db versions match');
96 my $admin = DBIx::Class::Admin->new(
97 schema_class => 'DBICVersion::Schema',
100 connect_info => \@connect_info,
103 $admin->version("3.0");
105 is($admin->schema->get_db_version, "3.0", 'db thinks its version 3.0');
107 $admin->install("4.0")
108 } qr/Schema already has a version. Try upgrade instead/, 'cannot install to allready existing version';
111 warnings_exist ( sub {
112 $admin->install("4.0")
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');
119 $dir->rmtree if -d $dir;