12 use DBIx::Class::_Util 'sigwarn_silencer';
16 plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for('admin')
17 unless DBIx::Class::Optional::Dependencies->req_ok_for('admin');
19 plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for('deploy')
20 unless DBIx::Class::Optional::Dependencies->req_ok_for('deploy');
23 use_ok 'DBIx::Class::Admin';
26 DBICTest->init_schema(no_deploy => 1, no_populate => 1);
28 my $db_fn = DBICTest->_sqlite_dbfilename;
33 { on_connect_do => 'PRAGMA synchronous = OFF' },
35 my $ddl_dir = dir(qw/t var/, "admin_ddl-$$");
39 # make sure we are clean
43 my $admin = DBIx::Class::Admin->new(
44 schema_class=> "DBICTest::Schema",
46 connect_info => \@connect_info,
48 isa_ok ($admin, 'DBIx::Class::Admin', 'create the admin object');
49 lives_ok { $admin->create('MySQL'); } 'Can create MySQL sql';
50 lives_ok { $admin->create('SQLite'); } 'Can Create SQLite sql';
52 local $SIG{__WARN__} = sigwarn_silencer( qr/no such table.+DROP TABLE/s );
54 } 'Can Deploy schema';
60 require DBICVersion_v1;
62 my $admin = DBIx::Class::Admin->new(
63 schema_class => 'DBICVersion::Schema',
65 connect_info => \@connect_info,
68 my $schema = $admin->schema();
70 lives_ok { $admin->create($schema->storage->sqlt_type(), {add_drop_table=>0}); } 'Can create DBICVersionOrig sql in ' . $schema->storage->sqlt_type;
71 lives_ok { $admin->deploy( ) } 'Can Deploy schema';
73 # connect to now deployed schema
74 lives_ok { $schema = DBICVersion::Schema->connect(@{$schema->storage->connect_info()}); } 'Connect to deployed Database';
76 is($schema->get_db_version, $DBICVersion::Schema::VERSION, 'Schema deployed and versions match');
79 require DBICVersion_v2;
80 DBICVersion::Schema->upgrade_directory (undef); # so that we can test use of $ddl_dir
82 $admin = DBIx::Class::Admin->new(
83 schema_class => 'DBICVersion::Schema',
85 connect_info => \@connect_info
88 lives_ok { $admin->create($schema->storage->sqlt_type(), {}, "1.0" ); } 'Can create diff for ' . $schema->storage->sqlt_type;
90 local $SIG{__WARN__} = sigwarn_silencer( qr/DB version .+? is lower than the schema version/ );
91 lives_ok { $admin->upgrade() } 'upgrade the schema';
92 dies_ok { $admin->deploy } 'cannot deploy installed schema, should upgrade instead';
95 is($schema->get_db_version, $DBICVersion::Schema::VERSION, 'Schema and db versions match');
103 my $admin = DBIx::Class::Admin->new(
104 schema_class => 'DBICVersion::Schema',
107 connect_info => \@connect_info,
110 $admin->version("3.0");
112 is($admin->schema->get_db_version, "3.0", 'db thinks its version 3.0');
114 $admin->install("4.0")
115 } qr/Schema already has a version. Try upgrade instead/, 'cannot install to allready existing version';
118 warnings_exist ( sub {
119 $admin->install("4.0")
120 }, qr/Forcing install may not be a good idea/, 'Force warning emitted' );
121 is($admin->schema->get_db_version, "4.0", 'db thinks its version 4.0');
126 $dir->rmtree if -d $dir;