Commit | Line | Data |
02d58ac0 |
1 | #!perl |
2 | |
3 | use Test::More; |
3d3e2f00 |
4 | use Test::Deep; |
02d58ac0 |
5 | use Test::Exception; |
6 | |
7 | use lib 't/lib'; |
8 | use DBICDHTest; |
9 | use DBICTest; |
3d3e2f00 |
10 | use aliased 'DBIx::Class::DeploymentHandler::VersionStorage::Standard'; |
02d58ac0 |
11 | |
3d3e2f00 |
12 | use DBICVersion_v1; |
13 | use DBIx::Class::DeploymentHandler; |
14 | my $db = 'dbi:SQLite:db.db'; |
15 | my @connection = ($db, '', '', { ignore_version => 1 }); |
16 | my $sql_dir = 't/sql'; |
17 | |
18 | my $s = DBICVersion::Schema->connect(@connection); |
19 | DBICDHTest::ready; |
20 | |
21 | my $handler = DBIx::Class::DeploymentHandler->new({ |
22 | upgrade_directory => $sql_dir, |
23 | schema => $s, |
24 | databases => 'SQLite', |
25 | sqltargs => { add_drop_table => 0 }, |
26 | }); |
27 | |
28 | $handler->prepare_install(); |
29 | |
30 | my $vs = Standard->new({ schema => $s }); |
31 | |
32 | ok( $vs, 'DBIC::DH::VersionStorage::Standard instantiates correctly' ); |
33 | |
34 | ok( !$vs->version_storage_is_installed, 'VersionStorage is not yet installed' ); |
35 | |
36 | $handler->install(); |
37 | |
38 | ok( $vs->version_storage_is_installed, 'VersionStorage is now installed' ); |
39 | |
40 | |
41 | cmp_deeply( |
42 | [ map +{ |
43 | version => $_->version, |
44 | ddl => $_->ddl, |
45 | upgrade_sql => $_->upgrade_sql, |
46 | }, $vs->version_rs->search(undef, {order_by => 'id'})->all], |
47 | [{ |
48 | version => '1.0', |
49 | ddl => undef, |
50 | upgrade_sql => undef |
51 | }], |
52 | 'initial version works correctly' |
53 | ); |
54 | |
55 | is( $vs->database_version, '1.0', 'database version is 1.0'); |
56 | $vs->add_database_version({ |
57 | version => '2.0', |
58 | }); |
59 | is( $vs->database_version, '2.0', 'database version is 2.0'); |
60 | |
61 | cmp_deeply( |
62 | [ map +{ |
63 | version => $_->version, |
64 | ddl => $_->ddl, |
65 | upgrade_sql => $_->upgrade_sql, |
66 | }, $vs->version_rs->search(undef, {order_by => 'id'})->all], |
67 | [{ |
68 | version => '1.0', |
69 | ddl => undef, |
70 | upgrade_sql => undef |
71 | },{ |
72 | version => '2.0', |
73 | ddl => undef, |
74 | upgrade_sql => undef |
75 | }], |
76 | 'adding another version works correctly' |
77 | ); |
78 | |
79 | $vs->version_rs->delete; |
80 | |
81 | ok( $vs->version_storage_is_installed, 'VersionStorage is still installed even if all versions are deleted' ); |
02d58ac0 |
82 | done_testing; |