change installed column name to id, initial big test for standard version storage
[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);
19DBICDHTest::ready;
20
21my $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
30my $vs = Standard->new({ schema => $s });
31
32ok( $vs, 'DBIC::DH::VersionStorage::Standard instantiates correctly' );
33
34ok( !$vs->version_storage_is_installed, 'VersionStorage is not yet installed' );
35
36$handler->install();
37
38ok( $vs->version_storage_is_installed, 'VersionStorage is now installed' );
39
40
41cmp_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
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
61cmp_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
81ok( $vs->version_storage_is_installed, 'VersionStorage is still installed even if all versions are deleted' );
02d58ac0 82done_testing;