release 0.001000_05
[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';
c8a2f7bd 10use aliased 'DBIx::Class::DeploymentHandler::DeployMethod::SQL::Translator';
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
c8a2f7bd 28my $dm = Translator->new({
29 schema => $s,
3d3e2f00 30 upgrade_directory => $sql_dir,
c8a2f7bd 31 databases => ['SQLite'],
32 sqltargs => { add_drop_table => 0 },
3d3e2f00 33});
34
3d3e2f00 35my $vs = Standard->new({ schema => $s });
36
c8a2f7bd 37$dm->prepare_resultsource_install(
38 $vs->version_rs->result_source
39);
40
3d3e2f00 41ok( $vs, 'DBIC::DH::VersionStorage::Standard instantiates correctly' );
42
43ok( !$vs->version_storage_is_installed, 'VersionStorage is not yet installed' );
44
c8a2f7bd 45$dm->install_resultsource(
46 $vs->version_rs->result_source,
47 '1.0',
48);
3d3e2f00 49
50ok( $vs->version_storage_is_installed, 'VersionStorage is now installed' );
51
52
c8a2f7bd 53$vs->add_database_version({
54 version => '1.0',
55});
56
566925df 57ok(
58 eq_array(
59 [ $vs->version_rs->search(undef, {order_by => 'id'})->get_column('version')->all],
60 [ '1.0' ],
61 ),
3d3e2f00 62 'initial version works correctly'
63);
64
65is( $vs->database_version, '1.0', 'database version is 1.0');
66$vs->add_database_version({
67 version => '2.0',
68});
69is( $vs->database_version, '2.0', 'database version is 2.0');
70
566925df 71ok(
72 eq_array(
73 [ $vs->version_rs->search(undef, {order_by => 'id'})->get_column('version')->all],
74 [ '1.0', '2.0', ],
75 ),
3d3e2f00 76 'adding another version works correctly'
77);
78
c37d8797 79{
80 my $warning;
81 local $SIG{__WARN__} = sub {$warning = shift};
82 my $u = DBICVersion::Schema->connect($db, '', '');
83 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');
84}
85
86
3d3e2f00 87$vs->version_rs->delete;
88
89ok( $vs->version_storage_is_installed, 'VersionStorage is still installed even if all versions are deleted' );
02d58ac0 90done_testing;