rename create_update_ddl to prepare_update
[dbsrgits/DBIx-Class-DeploymentHandler.git] / t / 04_db_schema_versions.t
1 #!perl
2
3 use Test::More;
4 use Test::Exception;
5
6 use lib 't/lib';
7 use DBICTest;
8 use DBIx::Class::DeploymentHandler;
9 use DBIx::Class::DeploymentHandler::ExplicitVersions;
10 my $db = 'dbi:SQLite:db.db';
11 my @connection = ($db, '', '', { ignore_version => 1 });
12 my $sql_dir = 't/sql';
13
14 unlink 'db.db' if -e 'db.db';
15 if (-d 't/sql') {
16   unlink $_ for glob('t/sql/*');
17 } else {
18   mkdir 't/sql';
19 }
20
21 use DBICVersion_v1;
22 my $s = DBICVersion::Schema->connect(@connection);
23
24 my $handler = DBIx::Class::DeploymentHandler->new({
25    upgrade_directory => $sql_dir,
26    schema => $s,
27    databases => 'SQLite',
28  sqltargs => { add_drop_table => 0 },
29 });
30
31 my $version = $s->schema_version();
32 $handler->prepare_install();
33
34 $handler->install;
35 {
36   my $vh = DBIx::Class::DeploymentHandler::DatabaseToSchemaVersions->new({
37     schema => $s,
38     ordered_versions => $versions,
39     to_version => '5.0',
40   });
41
42   ok( $vh, 'VersionHandler gets instantiated' );
43   ok( eq_array( $vh->next_version_set, [qw( 1.0 5.0 )] ), 'db version and to_version get correctly put into version set');
44   ok( !$vh->next_version_set, 'next_version_set only works once');
45   ok( !$vh->next_version_set, 'seriously.');
46 }
47
48 {
49   my $vh = DBIx::Class::DeploymentHandler::DatabaseToSchemaVersions->new({
50     schema => $s,
51     ordered_versions => $versions,
52   });
53
54   ok( $vh, 'VersionHandler gets instantiated' );
55   ok( !$vh->next_version_set, 'VersionHandler is null when schema_version and db_verison are the same' );
56 }
57
58 {
59   my $vh = DBIx::Class::DeploymentHandler::DatabaseToSchemaVersions->new({
60     schema => $s,
61     ordered_versions => $versions,
62   });
63
64   ok( $vh, 'VersionHandler gets instantiated' );
65   ok( !$vh->next_version_set, 'VersionHandler is null when schema_version and db_verison are the same' );
66 }
67
68 {
69   $DBICVersion::Schema::VERSION = '10.0';
70
71   my $vh = DBIx::Class::DeploymentHandler::DatabaseToSchemaVersions->new({
72     schema => $s,
73     ordered_versions => $versions,
74   });
75
76   ok( $vh, 'VersionHandler gets instantiated' );
77   ok( eq_array( $vh->next_version_set, [qw( 1.0 10.0 )] ), 'db version and schema version get correctly put into version set');
78   ok( !$vh->next_version_set, 'VersionHandler is null on next try' );
79 }
80
81 done_testing;
82 __END__
83
84 vim: ts=2 sw=2 expandtab