add DBIx::Class::Admin
[dbsrgits/DBIx-Class.git] / t / admin / 02ddl.t
1 #
2 #===============================================================================
3 #
4 #         FILE:  02admin..t
5 #
6 #  DESCRIPTION:  
7 #
8 #        FILES:  ---
9 #         BUGS:  ---
10 #        NOTES:  ---
11 #       AUTHOR:  Gordon Irving (), <Gordon.irving@sophos.com>
12 #      COMPANY:  Sophos
13 #      VERSION:  1.0
14 #      CREATED:  28/11/09 16:14:21 GMT
15 #     REVISION:  ---
16 #===============================================================================
17
18 use strict;
19 use warnings;
20
21 use Test::More;                      # last test to print
22
23 use Test::Exception;
24
25 use Path::Class;
26 use FindBin qw($Bin);
27 use lib dir($Bin,'..', '..','lib')->stringify;
28 use lib dir($Bin,'..', 'lib')->stringify;
29
30 use ok 'DBIx::Class::Admin';
31
32 use DBICTest;
33
34 my $sql_dir = dir($Bin,"var","sql");
35
36
37 { # create the schema
38
39 my $schema = DBICTest->init_schema(
40     no_deploy=>1,
41     no_populate=>1,
42         );
43         clean_dir($sql_dir);
44 my $admin = DBIx::Class::Admin->new(
45         schema_class=> "DBICTest::Schema",
46         sql_dir=> $sql_dir,
47         connect_info => $schema->storage->connect_info() 
48 );
49
50 lives_ok { $admin->create('MySQL'); } 'Can create MySQL sql';
51 lives_ok { $admin->create('SQLite'); } 'Can Create SQLite sql';
52 }
53
54
55 { # upgrade schema
56
57 my $schema = DBICTest->init_schema(
58     no_deploy=>1,
59     no_populate=>1,
60         );
61
62         clean_dir($sql_dir);
63 use DBICVersionOrig;
64
65 my $admin = DBIx::Class::Admin->new(
66         schema_class => 'DBICVersion::Schema', 
67         sql_dir =>  $sql_dir,
68         connect_info => $schema->storage->connect_info(),
69 );
70 lives_ok { $admin->create($schema->storage->sqlt_type()); } 'Can create DBICVersionOrig sql in ' . $schema->storage->sqlt_type;
71 lives_ok { $admin->deploy(); } 'Can Deploy schema';
72
73 }
74
75 sub clean_dir {
76         my ($dir)  =@_;
77         foreach my $file ($dir->children) {
78                 unlink $file;
79         }
80 }
81
82 done_testing;