Commit | Line | Data |
b974984a |
1 | #!perl |
2 | |
3 | use Test::More; |
239acef9 |
4 | use Test::Exception; |
b974984a |
5 | |
6 | use lib 't/lib'; |
7 | use DBICTest; |
8 | use DBIx::Class::DeploymentHandler; |
4ea147c6 |
9 | my $db = 'dbi:SQLite:db.db'; |
e0743c25 |
10 | my $sql_dir = 't/sql'; |
b974984a |
11 | |
b9c4146b |
12 | unlink 'db.db' if -e 'db.db'; |
9d737292 |
13 | if (-d 't/sql') { |
14 | unlink $_ for glob('t/sql/*'); |
15 | } else { |
16 | mkdir 't/sql'; |
17 | } |
b9c4146b |
18 | |
e0743c25 |
19 | VERSION1: { |
b9c4146b |
20 | use_ok 'DBICVersion_v1'; |
21 | my $s = DBICVersion::Schema->connect($db); |
22 | ok($s, 'DBICVersion::Schema 1.0 instantiates correctly'); |
23 | my $handler = DBIx::Class::DeploymentHandler->new({ |
24 | upgrade_directory => $sql_dir, |
25 | schema => $s, |
cf400f48 |
26 | databases => 'SQLite', |
b9c4146b |
27 | }); |
e0743c25 |
28 | |
b9c4146b |
29 | ok($handler, 'DBIx::Class::DeploymentHandler w/1.0 instantiates correctly'); |
e0743c25 |
30 | |
b9c4146b |
31 | my $version = $s->schema_version(); |
9d737292 |
32 | $handler->create_install_ddl(); |
b9c4146b |
33 | ok(-e 't/sql/DBICVersion-Schema-1.0-SQLite.sql', 'DDL for 1.0 got created successfully'); |
239acef9 |
34 | |
b9c4146b |
35 | dies_ok { |
36 | $s->resultset('Foo')->create({ |
37 | bar => 'frew', |
38 | }) |
39 | } 'schema not deployed'; |
40 | $handler->install; |
41 | lives_ok { |
42 | $s->resultset('Foo')->create({ |
43 | bar => 'frew', |
44 | }) |
45 | } 'schema is deployed'; |
e0743c25 |
46 | } |
47 | |
48 | VERSION2: { |
b9c4146b |
49 | use_ok 'DBICVersion_v2'; |
50 | my $s = DBICVersion::Schema->connect($db); |
51 | ok($s, 'DBICVersion::Schema 2.0 instantiates correctly'); |
52 | my $handler = DBIx::Class::DeploymentHandler->new({ |
53 | upgrade_directory => $sql_dir, |
54 | schema => $s, |
cf400f48 |
55 | databases => 'SQLite', |
b9c4146b |
56 | }); |
e0743c25 |
57 | |
b9c4146b |
58 | ok($handler, 'DBIx::Class::DeploymentHandler w/2.0 instantiates correctly'); |
e0743c25 |
59 | |
b9c4146b |
60 | $version = $s->schema_version(); |
9d737292 |
61 | $handler->create_install_ddl(); |
62 | $handler->create_update_ddl($version, '1.0'); |
b9c4146b |
63 | ok(-e 't/sql/DBICVersion-Schema-2.0-SQLite.sql', 'DDL for 2.0 got created successfully'); |
64 | ok(-e 't/sql/DBICVersion-Schema-1.0-2.0-SQLite.sql', 'DDL for migration from 1.0 to 2.0 got created successfully'); |
65 | dies_ok { |
66 | $s->resultset('Foo')->create({ |
67 | bar => 'frew', |
68 | baz => 'frew', |
69 | }) |
70 | } 'schema not deployed'; |
71 | #$handler->install('1.0'); |
72 | dies_ok { |
73 | $s->resultset('Foo')->create({ |
74 | bar => 'frew', |
75 | baz => 'frew', |
76 | }) |
77 | } 'schema not uppgrayyed'; |
78 | $handler->upgrade_single_step('1.0', '2.0'); |
79 | lives_ok { |
80 | $s->resultset('Foo')->create({ |
81 | bar => 'frew', |
82 | baz => 'frew', |
83 | }) |
84 | } 'schema is deployed'; |
e0743c25 |
85 | } |
86 | |
87 | VERSION3: { |
b9c4146b |
88 | use_ok 'DBICVersion_v3'; |
89 | my $s = DBICVersion::Schema->connect($db); |
90 | ok($s, 'DBICVersion::Schema 3.0 instantiates correctly'); |
91 | my $handler = DBIx::Class::DeploymentHandler->new({ |
92 | upgrade_directory => $sql_dir, |
93 | schema => $s, |
cf400f48 |
94 | databases => 'SQLite', |
b9c4146b |
95 | }); |
e0743c25 |
96 | |
b9c4146b |
97 | ok($handler, 'DBIx::Class::DeploymentHandler w/3.0 instantiates correctly'); |
e0743c25 |
98 | |
b9c4146b |
99 | $version = $s->schema_version(); |
9d737292 |
100 | $handler->create_install_ddl; |
101 | $handler->create_update_ddl( $version, '1.0'); |
102 | $handler->create_update_ddl( $version, '2.0'); |
b9c4146b |
103 | ok(-e 't/sql/DBICVersion-Schema-3.0-SQLite.sql', 'DDL for 3.0 got created successfully'); |
104 | ok(-e 't/sql/DBICVersion-Schema-1.0-3.0-SQLite.sql', 'DDL for migration from 1.0 to 3.0 got created successfully'); |
105 | ok(-e 't/sql/DBICVersion-Schema-2.0-3.0-SQLite.sql', 'DDL for migration from 2.0 to 3.0 got created successfully'); |
106 | dies_ok { |
107 | $s->resultset('Foo')->create({ |
108 | bar => 'frew', |
109 | baz => 'frew', |
110 | biff => 'frew', |
111 | }) |
112 | } 'schema not deployed'; |
113 | $handler->upgrade; |
114 | lives_ok { |
115 | $s->resultset('Foo')->create({ |
116 | bar => 'frew', |
117 | baz => 'frew', |
118 | biff => 'frew', |
119 | }) |
120 | } 'schema is deployed'; |
e0743c25 |
121 | } |
b974984a |
122 | |
123 | done_testing; |
4ea147c6 |
124 | __END__ |
125 | |
126 | vim: ts=2,sw=2,expandtab |