1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2 use DBIx::Class::Optional::Dependencies -skip_all_without => qw( admin deploy );
15 use DBIx::Class::_Util 'sigwarn_silencer';
17 use DBIx::Class::Admin;
20 DBICTest->init_schema(no_deploy => 1, no_populate => 1);
22 my $db_fn = DBICTest->_sqlite_dbfilename;
27 { on_connect_do => 'PRAGMA synchronous = OFF' },
29 my $ddl_dir = dir(qw/t var/, "admin_ddl-$$");
33 # make sure we are clean
37 my $admin = DBIx::Class::Admin->new(
38 schema_class=> "DBICTest::Schema",
40 connect_info => \@connect_info,
42 isa_ok ($admin, 'DBIx::Class::Admin', 'create the admin object');
43 lives_ok { $admin->create('MySQL'); } 'Can create MySQL sql';
44 lives_ok { $admin->create('SQLite'); } 'Can Create SQLite sql';
46 local $SIG{__WARN__} = sigwarn_silencer( qr/no such table.+DROP TABLE/s );
48 } 'Can Deploy schema';
54 require DBICVersion_v1;
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 DBICVersion_v2;
74 DBICVersion::Schema->upgrade_directory (undef); # so that we can test use of $ddl_dir
76 $admin = DBIx::Class::Admin->new(
77 schema_class => 'DBICVersion::Schema',
79 connect_info => \@connect_info
82 lives_ok { $admin->create($schema->storage->sqlt_type(), {}, "1.0" ); } 'Can create diff for ' . $schema->storage->sqlt_type;
84 local $SIG{__WARN__} = sigwarn_silencer( qr/DB version .+? is lower than the schema version/ );
85 lives_ok { $admin->upgrade() } 'upgrade the schema';
86 dies_ok { $admin->deploy } 'cannot deploy installed schema, should upgrade instead';
89 is($schema->get_db_version, $DBICVersion::Schema::VERSION, 'Schema and db versions match');
97 my $admin = DBIx::Class::Admin->new(
98 schema_class => 'DBICVersion::Schema',
101 connect_info => \@connect_info,
104 $admin->version("3.0");
106 is($admin->schema->get_db_version, "3.0", 'db thinks its version 3.0');
108 $admin->install("4.0")
109 } qr/Schema already has a version. Try upgrade instead/, 'cannot install to allready existing version';
112 warnings_exist ( sub {
113 $admin->install("4.0")
114 }, qr/Forcing install may not be a good idea/, 'Force warning emitted' );
115 is($admin->schema->get_db_version, "4.0", 'db thinks its version 4.0');
120 $dir->rmtree if -d $dir;