initial monotonic commit
[dbsrgits/DBIx-Class-DeploymentHandler.git] / t / version_storages / standard.t
CommitLineData
02d58ac0 1#!perl
2
3use Test::More;
3d3e2f00 4use Test::Deep;
02d58ac0 5use Test::Exception;
6
7use lib 't/lib';
8use DBICDHTest;
3d3e2f00 9use aliased 'DBIx::Class::DeploymentHandler::VersionStorage::Standard';
02d58ac0 10
3d3e2f00 11use DBICVersion_v1;
12use DBIx::Class::DeploymentHandler;
13my $db = 'dbi:SQLite:db.db';
14my @connection = ($db, '', '', { ignore_version => 1 });
15my $sql_dir = 't/sql';
16
17my $s = DBICVersion::Schema->connect(@connection);
c37d8797 18{
19 my $warning;
20 local $SIG{__WARN__} = sub {$warning = shift};
21 my $t = DBICVersion::Schema->connect('frewfrew', '', '');
22 like( $warning, qr/Your DB is currently unversioned. Please call upgrade on your schema to sync the DB/, 'warning when database is unversioned');
23}
24
3d3e2f00 25DBICDHTest::ready;
26
27my $handler = DBIx::Class::DeploymentHandler->new({
28 upgrade_directory => $sql_dir,
29 schema => $s,
30 databases => 'SQLite',
31 sqltargs => { add_drop_table => 0 },
32});
33
34$handler->prepare_install();
35
36my $vs = Standard->new({ schema => $s });
37
38ok( $vs, 'DBIC::DH::VersionStorage::Standard instantiates correctly' );
39
40ok( !$vs->version_storage_is_installed, 'VersionStorage is not yet installed' );
41
42$handler->install();
43
44ok( $vs->version_storage_is_installed, 'VersionStorage is now installed' );
45
46
566925df 47ok(
48 eq_array(
49 [ $vs->version_rs->search(undef, {order_by => 'id'})->get_column('version')->all],
50 [ '1.0' ],
51 ),
3d3e2f00 52 'initial version works correctly'
53);
54
55is( $vs->database_version, '1.0', 'database version is 1.0');
56$vs->add_database_version({
57 version => '2.0',
58});
59is( $vs->database_version, '2.0', 'database version is 2.0');
60
566925df 61ok(
62 eq_array(
63 [ $vs->version_rs->search(undef, {order_by => 'id'})->get_column('version')->all],
64 [ '1.0', '2.0', ],
65 ),
3d3e2f00 66 'adding another version works correctly'
67);
68
c37d8797 69{
70 my $warning;
71 local $SIG{__WARN__} = sub {$warning = shift};
72 my $u = DBICVersion::Schema->connect($db, '', '');
73 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');
74}
75
76
3d3e2f00 77$vs->version_rs->delete;
78
79ok( $vs->version_storage_is_installed, 'VersionStorage is still installed even if all versions are deleted' );
02d58ac0 80done_testing;