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); |
c37d8797 |
19 | { |
20 | my $warning; |
21 | local $SIG{__WARN__} = sub {$warning = shift}; |
22 | my $t = DBICVersion::Schema->connect('frewfrew', '', ''); |
23 | like( $warning, qr/Your DB is currently unversioned. Please call upgrade on your schema to sync the DB/, 'warning when database is unversioned'); |
24 | } |
25 | |
3d3e2f00 |
26 | DBICDHTest::ready; |
27 | |
28 | my $handler = DBIx::Class::DeploymentHandler->new({ |
29 | upgrade_directory => $sql_dir, |
30 | schema => $s, |
31 | databases => 'SQLite', |
32 | sqltargs => { add_drop_table => 0 }, |
33 | }); |
34 | |
35 | $handler->prepare_install(); |
36 | |
37 | my $vs = Standard->new({ schema => $s }); |
38 | |
39 | ok( $vs, 'DBIC::DH::VersionStorage::Standard instantiates correctly' ); |
40 | |
41 | ok( !$vs->version_storage_is_installed, 'VersionStorage is not yet installed' ); |
42 | |
43 | $handler->install(); |
44 | |
45 | ok( $vs->version_storage_is_installed, 'VersionStorage is now installed' ); |
46 | |
47 | |
566925df |
48 | ok( |
49 | eq_array( |
50 | [ $vs->version_rs->search(undef, {order_by => 'id'})->get_column('version')->all], |
51 | [ '1.0' ], |
52 | ), |
3d3e2f00 |
53 | 'initial version works correctly' |
54 | ); |
55 | |
56 | is( $vs->database_version, '1.0', 'database version is 1.0'); |
57 | $vs->add_database_version({ |
58 | version => '2.0', |
59 | }); |
60 | is( $vs->database_version, '2.0', 'database version is 2.0'); |
61 | |
566925df |
62 | ok( |
63 | eq_array( |
64 | [ $vs->version_rs->search(undef, {order_by => 'id'})->get_column('version')->all], |
65 | [ '1.0', '2.0', ], |
66 | ), |
3d3e2f00 |
67 | 'adding another version works correctly' |
68 | ); |
69 | |
c37d8797 |
70 | { |
71 | my $warning; |
72 | local $SIG{__WARN__} = sub {$warning = shift}; |
73 | my $u = DBICVersion::Schema->connect($db, '', ''); |
74 | like( $warning, qr/Versions out of sync. This is 1.0, your database contains version 2.0, please call upgrade on your Schema./, 'warning when database/schema mismatch'); |
75 | } |
76 | |
77 | |
3d3e2f00 |
78 | $vs->version_rs->delete; |
79 | |
80 | ok( $vs->version_storage_is_installed, 'VersionStorage is still installed even if all versions are deleted' ); |
02d58ac0 |
81 | done_testing; |