Commit | Line | Data |
c9d2e0a2 |
1 | #!/usr/bin/perl |
2 | use strict; |
3 | use warnings; |
4 | use Test::More; |
86ef9f0d |
5 | use File::Spec; |
c9d2e0a2 |
6 | |
7 | BEGIN { |
40dce2a5 |
8 | eval "use DBD::SQLite; use SQL::Translator 0.08;"; |
c9d2e0a2 |
9 | plan $@ |
40dce2a5 |
10 | ? ( skip_all => 'needs DBD::SQLite and SQL::Translator 0.08 for testing' ) |
c9d2e0a2 |
11 | : ( tests => 6 ); |
12 | } |
13 | |
14 | use lib qw(t/lib); |
15 | |
16 | use_ok('DBICVersionOrig'); |
17 | |
18 | my $db_file = "t/var/versioning.db"; |
19 | unlink($db_file) if -e $db_file; |
20 | unlink($db_file . "-journal") if -e $db_file . "-journal"; |
21 | mkdir("t/var") unless -d "t/var"; |
22 | unlink('t/var/DBICVersion-Schema-1.0-SQLite.sql'); |
23 | |
77d76d0f |
24 | my $schema_orig = DBICVersion::Schema->connect( |
25 | "dbi:SQLite:$db_file", |
26 | undef, |
27 | undef, |
28 | { AutoCommit => 1 }, |
29 | ); |
c9d2e0a2 |
30 | # $schema->storage->ensure_connected(); |
31 | |
339e3fd0 |
32 | is($schema_orig->ddl_filename('SQLite', 't/var', '1.0'), File::Spec->catfile('t', 'var', 'DBICVersion-Schema-1.0-SQLite.sql'), 'Filename creation working'); |
e2c0df8e |
33 | $schema_orig->create_ddl_dir('SQLite', undef, 't/var'); |
c9d2e0a2 |
34 | |
35 | ok(-f 't/var/DBICVersion-Schema-1.0-SQLite.sql', 'Created DDL file'); |
36 | ## do this here or let Versioned.pm do it? |
37 | # $schema->deploy(); |
38 | |
e2c0df8e |
39 | my $tvrs = $schema_orig->resultset('Table'); |
a2800991 |
40 | is($schema_orig->_source_exists($tvrs), 1, 'Created schema from DDL file'); |
c9d2e0a2 |
41 | |
42 | eval "use DBICVersionNew"; |
77d76d0f |
43 | my $schema_new = DBICVersion::Schema->connect( |
44 | "dbi:SQLite:$db_file", |
45 | undef, |
46 | undef, |
47 | { AutoCommit => 1 }, |
48 | ); |
c9d2e0a2 |
49 | |
50 | unlink('t/var/DBICVersion-Schema-2.0-SQLite.sql'); |
51 | unlink('t/var/DBICVersion-Schema-1.0-2.0-SQLite.sql'); |
e2c0df8e |
52 | $schema_new->create_ddl_dir('SQLite', undef, 't/var', '1.0'); |
c9d2e0a2 |
53 | ok(-f 't/var/DBICVersion-Schema-1.0-2.0-SQLite.sql', 'Created DDL upgrade file'); |
54 | |
e2c0df8e |
55 | ## create new to pick up filedata for upgrade files we just made (on_connect) |
77d76d0f |
56 | my $schema_upgrade = DBICVersion::Schema->connect( |
57 | "dbi:SQLite:$db_file", |
58 | undef, |
59 | undef, |
60 | { AutoCommit => 1 }, |
61 | ); |
e2c0df8e |
62 | |
c9d2e0a2 |
63 | ## do this here or let Versioned.pm do it? |
e2c0df8e |
64 | $schema_upgrade->upgrade(); |
65 | $tvrs = $schema_upgrade->resultset('Table'); |
a2800991 |
66 | is($schema_upgrade->_source_exists($tvrs), 1, 'Upgraded schema from DDL file'); |
8795fefb |
67 | |
68 | unlink($db_file) if -e $db_file; |
69 | unlink($db_file . "-journal") if -e $db_file . "-journal"; |
70 | unlink('t/var/DBICVersion-Schema-1.0-SQLite.sql'); |
71 | unlink('t/var/DBICVersion-Schema-2.0-SQLite.sql'); |
72 | unlink('t/var/DBICVersion-Schema-1.0-2.0-SQLite.sql'); |
73 | unlink(<t/var/backup/*>); |