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