tests for component (and therefor bugfixes!)
[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;
9use DBICTest;
3d3e2f00 10use aliased 'DBIx::Class::DeploymentHandler::VersionStorage::Standard';
02d58ac0 11
3d3e2f00 12use DBICVersion_v1;
13use DBIx::Class::DeploymentHandler;
14my $db = 'dbi:SQLite:db.db';
15my @connection = ($db, '', '', { ignore_version => 1 });
16my $sql_dir = 't/sql';
17
18my $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 26DBICDHTest::ready;
27
28my $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
37my $vs = Standard->new({ schema => $s });
38
39ok( $vs, 'DBIC::DH::VersionStorage::Standard instantiates correctly' );
40
41ok( !$vs->version_storage_is_installed, 'VersionStorage is not yet installed' );
42
43$handler->install();
44
45ok( $vs->version_storage_is_installed, 'VersionStorage is now installed' );
46
47
48cmp_deeply(
49 [ map +{
50 version => $_->version,
51 ddl => $_->ddl,
52 upgrade_sql => $_->upgrade_sql,
53 }, $vs->version_rs->search(undef, {order_by => 'id'})->all],
54 [{
55 version => '1.0',
56 ddl => undef,
57 upgrade_sql => undef
58 }],
59 'initial version works correctly'
60);
61
62is( $vs->database_version, '1.0', 'database version is 1.0');
63$vs->add_database_version({
64 version => '2.0',
65});
66is( $vs->database_version, '2.0', 'database version is 2.0');
67
68cmp_deeply(
69 [ map +{
70 version => $_->version,
71 ddl => $_->ddl,
72 upgrade_sql => $_->upgrade_sql,
73 }, $vs->version_rs->search(undef, {order_by => 'id'})->all],
74 [{
75 version => '1.0',
76 ddl => undef,
77 upgrade_sql => undef
78 },{
79 version => '2.0',
80 ddl => undef,
81 upgrade_sql => undef
82 }],
83 'adding another version works correctly'
84);
85
c37d8797 86{
87 my $warning;
88 local $SIG{__WARN__} = sub {$warning = shift};
89 my $u = DBICVersion::Schema->connect($db, '', '');
90 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');
91}
92
93
3d3e2f00 94$vs->version_rs->delete;
95
96ok( $vs->version_storage_is_installed, 'VersionStorage is still installed even if all versions are deleted' );
02d58ac0 97done_testing;