Patch for ? in NoBindVars data from Tom Hukins
[dbsrgits/DBIx-Class-Historic.git] / t / 94versioning.t
CommitLineData
c9d2e0a2 1#!/usr/bin/perl
2use strict;
3use warnings;
4use Test::More;
86ef9f0d 5use File::Spec;
c9d2e0a2 6
7BEGIN {
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
14use lib qw(t/lib);
15
16use_ok('DBICVersionOrig');
17
18my $db_file = "t/var/versioning.db";
19unlink($db_file) if -e $db_file;
20unlink($db_file . "-journal") if -e $db_file . "-journal";
21mkdir("t/var") unless -d "t/var";
22unlink('t/var/DBICVersion-Schema-1.0-SQLite.sql');
23
77d76d0f 24my $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 32is($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
35ok(-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 39my $tvrs = $schema_orig->resultset('Table');
a2800991 40is($schema_orig->_source_exists($tvrs), 1, 'Created schema from DDL file');
c9d2e0a2 41
42eval "use DBICVersionNew";
77d76d0f 43my $schema_new = DBICVersion::Schema->connect(
44 "dbi:SQLite:$db_file",
45 undef,
46 undef,
47 { AutoCommit => 1 },
48);
c9d2e0a2 49
50unlink('t/var/DBICVersion-Schema-2.0-SQLite.sql');
51unlink('t/var/DBICVersion-Schema-1.0-2.0-SQLite.sql');
e2c0df8e 52$schema_new->create_ddl_dir('SQLite', undef, 't/var', '1.0');
c9d2e0a2 53ok(-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 56my $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 66is($schema_upgrade->_source_exists($tvrs), 1, 'Upgraded schema from DDL file');
8795fefb 67
68unlink($db_file) if -e $db_file;
69unlink($db_file . "-journal") if -e $db_file . "-journal";
70unlink('t/var/DBICVersion-Schema-1.0-SQLite.sql');
71unlink('t/var/DBICVersion-Schema-2.0-SQLite.sql');
72unlink('t/var/DBICVersion-Schema-1.0-2.0-SQLite.sql');
73unlink(<t/var/backup/*>);