Commit | Line | Data |
02d58ac0 |
1 | #!perl |
2 | |
cbbd1b5f |
3 | use strict; |
4 | use warnings; |
5 | |
02d58ac0 |
6 | use Test::More; |
7 | use Test::Exception; |
8 | |
9 | use lib 't/lib'; |
10 | use DBICDHTest; |
3d3e2f00 |
11 | use aliased 'DBIx::Class::DeploymentHandler::VersionStorage::Standard'; |
c8a2f7bd |
12 | use aliased 'DBIx::Class::DeploymentHandler::DeployMethod::SQL::Translator'; |
7b3d00f9 |
13 | use File::Temp 'tempdir'; |
02d58ac0 |
14 | |
3d3e2f00 |
15 | use DBICVersion_v1; |
16 | use DBIx::Class::DeploymentHandler; |
f3b5161e |
17 | my $dbh = DBICDHTest::dbh(); |
624e3018 |
18 | my @connection = (sub { $dbh }, { ignore_version => 1 }); |
7b3d00f9 |
19 | my $sql_dir = tempdir( CLEANUP => 1 ); |
3d3e2f00 |
20 | |
21 | my $s = DBICVersion::Schema->connect(@connection); |
c37d8797 |
22 | { |
02a7b8ac |
23 | my $warning; |
24 | local $SIG{__WARN__} = sub {$warning = shift}; |
25 | my $t = DBICVersion::Schema->connect('frewfrew', '', ''); |
26 | like( $warning, qr/Your DB is currently unversioned. Please call upgrade on your schema to sync the DB/, 'warning when database is unversioned'); |
c37d8797 |
27 | } |
28 | |
c8a2f7bd |
29 | my $dm = Translator->new({ |
02a7b8ac |
30 | schema => $s, |
91adde75 |
31 | script_directory => $sql_dir, |
02a7b8ac |
32 | databases => ['SQLite'], |
33 | sql_translator_args => { add_drop_table => 0 }, |
3d3e2f00 |
34 | }); |
35 | |
3d3e2f00 |
36 | my $vs = Standard->new({ schema => $s }); |
37 | |
be140a5f |
38 | $dm->prepare_resultsource_install({ |
39 | result_source => $vs->version_rs->result_source |
40 | }); |
c8a2f7bd |
41 | |
3d3e2f00 |
42 | ok( $vs, 'DBIC::DH::VersionStorage::Standard instantiates correctly' ); |
43 | |
44 | ok( !$vs->version_storage_is_installed, 'VersionStorage is not yet installed' ); |
45 | |
be140a5f |
46 | $dm->install_resultsource({ |
47 | result_source => $vs->version_rs->result_source, |
48 | version => '1.0', |
49 | }); |
3d3e2f00 |
50 | |
51 | ok( $vs->version_storage_is_installed, 'VersionStorage is now installed' ); |
52 | |
53 | |
c8a2f7bd |
54 | $vs->add_database_version({ |
02a7b8ac |
55 | version => '1.0', |
c8a2f7bd |
56 | }); |
57 | |
566925df |
58 | ok( |
02a7b8ac |
59 | eq_array( |
60 | [ $vs->version_rs->search(undef, {order_by => 'id'})->get_column('version')->all], |
61 | [ '1.0' ], |
62 | ), |
63 | 'initial version works correctly' |
3d3e2f00 |
64 | ); |
65 | |
66 | is( $vs->database_version, '1.0', 'database version is 1.0'); |
67 | $vs->add_database_version({ |
02a7b8ac |
68 | version => '2.0', |
3d3e2f00 |
69 | }); |
70 | is( $vs->database_version, '2.0', 'database version is 2.0'); |
71 | |
566925df |
72 | ok( |
02a7b8ac |
73 | eq_array( |
74 | [ $vs->version_rs->search(undef, {order_by => 'id'})->get_column('version')->all], |
75 | [ '1.0', '2.0', ], |
76 | ), |
77 | 'adding another version works correctly' |
3d3e2f00 |
78 | ); |
79 | |
624e3018 |
80 | my $u; |
c37d8797 |
81 | { |
02a7b8ac |
82 | my $warning; |
83 | local $SIG{__WARN__} = sub {$warning = shift}; |
624e3018 |
84 | $u = DBICVersion::Schema->connect(sub { $dbh }); |
85 | 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'); |
c37d8797 |
86 | } |
87 | |
88 | |
3d3e2f00 |
89 | $vs->version_rs->delete; |
90 | |
91 | ok( $vs->version_storage_is_installed, 'VersionStorage is still installed even if all versions are deleted' ); |
02d58ac0 |
92 | done_testing; |