1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2 use DBIx::Class::Optional::Dependencies -skip_all_without => qw( admin deploy );
12 use DBIx::Class::_Util 'sigwarn_silencer';
13 use DBICTest::Util 'rm_rf';
15 use DBIx::Class::Admin;
18 DBICTest->init_schema(no_deploy => 1, no_populate => 1);
20 my $db_fn = DBICTest->_sqlite_dbfilename;
25 { on_connect_do => 'PRAGMA synchronous = OFF' },
27 my $ddl_dir = "t/var/admin_ddl-$$";
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';
44 local $SIG{__WARN__} = sigwarn_silencer( qr/no such table.+DROP TABLE/s );
46 } 'Can Deploy schema';
52 require DBICVersion_v1;
54 my $admin = DBIx::Class::Admin->new(
55 schema_class => 'DBICVersion::Schema',
57 connect_info => \@connect_info,
60 my $schema = $admin->schema();
62 lives_ok { $admin->create($schema->storage->sqlt_type(), {add_drop_table=>0}); } 'Can create DBICVersionOrig sql in ' . $schema->storage->sqlt_type;
63 lives_ok { $admin->deploy( ) } 'Can Deploy schema';
65 # connect to now deployed schema
66 lives_ok { $schema = DBICVersion::Schema->connect(@{$schema->storage->connect_info()}); } 'Connect to deployed Database';
68 is($schema->get_db_version, $DBICVersion::Schema::VERSION, 'Schema deployed and versions match');
71 require DBICVersion_v2;
72 DBICVersion::Schema->upgrade_directory (undef); # so that we can test use of $ddl_dir
74 $admin = DBIx::Class::Admin->new(
75 schema_class => 'DBICVersion::Schema',
77 connect_info => \@connect_info
80 lives_ok { $admin->create($schema->storage->sqlt_type(), {}, "1.0" ); } 'Can create diff for ' . $schema->storage->sqlt_type;
82 local $SIG{__WARN__} = sigwarn_silencer( qr/DB version .+? is lower than the schema version/ );
83 lives_ok { $admin->upgrade() } 'upgrade the schema';
84 dies_ok { $admin->deploy } 'cannot deploy installed schema, should upgrade instead';
87 is($schema->get_db_version, $DBICVersion::Schema::VERSION, 'Schema and db versions match');
95 my $admin = DBIx::Class::Admin->new(
96 schema_class => 'DBICVersion::Schema',
99 connect_info => \@connect_info,
102 $admin->version("3.0");
104 is($admin->schema->get_db_version, "3.0", 'db thinks its version 3.0');
106 $admin->install("4.0")
107 } qr/Schema already has a version. Try upgrade instead/, 'cannot install to allready existing version';
110 warnings_exist ( sub {
111 $admin->install("4.0")
112 }, qr/Forcing install may not be a good idea/, 'Force warning emitted' );
113 is($admin->schema->get_db_version, "4.0", 'db thinks its version 4.0');
117 rm_rf $ddl_dir if -d $ddl_dir;