);
sub _inc_version_idx { $_[0]->_version_idx($_[0]->_version_idx + 1 ) }
+sub _dec_version_idx { $_[0]->_version_idx($_[0]->_version_idx - 1 ) }
sub _build__version_idx {
my $self = shift;
];
}
+sub previous_version_set {
+ my $self = shift;
+ return undef
+ if $self->ordered_versions->[$self->_version_idx] eq $self->database_version;
+
+ # this should never get in infinite loops because we ensure
+ # that the database version is in the list in the version_idx
+ # builder
+ my $next_idx = $self->_dec_version_idx;
+ return [
+ $self->ordered_versions->[$next_idx - 1],
+ $self->ordered_versions->[$next_idx ],
+ ];
+}
+
__PACKAGE__->meta->make_immutable;
1;
VERSION1: {
use_ok 'DBICVersion_v1';
my $s = DBICVersion::Schema->connect(@connection);
+ is $s->schema_version, '1.0', 'schema version is at 1.0';
ok($s, 'DBICVersion::Schema 1.0 instantiates correctly');
my $handler = $bundle->new({
upgrade_directory => $sql_dir,
VERSION2: {
use_ok 'DBICVersion_v2';
my $s = DBICVersion::Schema->connect(@connection);
+ is $s->schema_version, '2.0', 'schema version is at 2.0';
ok($s, 'DBICVersion::Schema 2.0 instantiates correctly');
my $handler = $bundle->new({
upgrade_directory => $sql_dir,
my $version = $s->schema_version();
$handler->prepare_install();
$handler->prepare_upgrade('1.0', $version);
- $handler->prepare_upgrade($version, '1.0');
dies_ok {
$s->resultset('Foo')->create({
bar => 'frew',
VERSION3: {
use_ok 'DBICVersion_v3';
my $s = DBICVersion::Schema->connect(@connection);
+ is $s->schema_version, '3.0', 'schema version is at 3.0';
ok($s, 'DBICVersion::Schema 3.0 instantiates correctly');
my $handler = $bundle->new({
upgrade_directory => $sql_dir,
my $version = $s->schema_version();
$handler->prepare_install;
- $handler->prepare_upgrade( '1.0', $version );
$handler->prepare_upgrade( '2.0', $version );
dies_ok {
$s->resultset('Foo')->create({
})
} 'schema is deployed';
}
+
+ DOWN2: {
+ use_ok 'DBICVersion_v4';
+ my $s = DBICVersion::Schema->connect(@connection);
+ is $s->schema_version, '2.0', 'schema version is at 2.0';
+ ok($s, 'DBICVersion::Schema 2.0 instantiates correctly');
+ my $handler = $bundle->new({
+ upgrade_directory => $sql_dir,
+ schema => $s,
+ databases => 'SQLite',
+ });
+
+ ok($handler, 'DBIx::Class::DeploymentHandler w/2.0 instantiates correctly');
+
+ my $version = $s->schema_version();
+ $handler->prepare_downgrade('3.0', $version);
+ lives_ok {
+ $s->resultset('Foo')->create({
+ bar => 'frew',
+ baz => 'frew',
+ biff => 'frew',
+ })
+ } 'schema at version 3';
+ $handler->downgrade;
+ dies_ok {
+ $s->resultset('Foo')->create({
+ bar => 'frew',
+ baz => 'frew',
+ biff => 'frew',
+ })
+ } 'schema not at version 3';
+ lives_ok {
+ $s->resultset('Foo')->create({
+ bar => 'frew',
+ baz => 'frew',
+ })
+ } 'schema is at version 2';
+ }
}
--- /dev/null
+package DBICVersion::Foo;
+
+use base 'DBIx::Class::Core';
+use strict;
+use warnings;
+
+__PACKAGE__->table('Foo');
+
+__PACKAGE__->add_columns(
+ foo => {
+ data_type => 'INTEGER',
+ is_auto_increment => 1,
+ },
+ bar => {
+ data_type => 'VARCHAR',
+ size => '10'
+ },
+ baz => {
+ data_type => 'VARCHAR',
+ size => '10',
+ is_nullable => 1,
+ },
+);
+
+__PACKAGE__->set_primary_key('foo');
+
+package DBICVersion::Schema;
+use base 'DBIx::Class::Schema';
+use strict;
+use warnings;
+
+our $VERSION = '2.0';
+
+__PACKAGE__->register_class('Foo', 'DBICVersion::Foo');
+__PACKAGE__->load_components('DeploymentHandler::VersionStorage::Standard::Component');
+
+1;