sub BUILD {
my $self = shift;
- if ($self->schema->can('ordered_versions')) {
+ if ($self->schema->can('ordered_versions') && $self->schema->ordered_versions) {
apply_all_roles(
$self,
- 'DBIx::Class::DeploymentHandler::WithDatabaseToSchemaVersions'
+ 'DBIx::Class::DeploymentHandler::WithExplicitVersions'
);
} else {
apply_all_roles(
$self,
- 'DBIx::Class::DeploymentHandler::WithExplicitVersions'
+ 'DBIx::Class::DeploymentHandler::WithDatabaseToSchemaVersions'
);
}
}
has version_storage => (
does => 'DBIx::Class::DeploymentHandler::HandlesVersionStorage',
is => 'ro',
- lazy_build => 1,
+ builder => '_build_version_storage',
handles => 'DBIx::Class::DeploymentHandler::HandlesVersionStorage',
);
-package DBIx::Class::DeploymentHandler::VersionStorage::Standard;
+package DBIx::Class::DeploymentHandler::VersionStorage::Deprecated;
use Moose;
use Method::Signatures::Simple;
has version_rs => (
isa => 'DBIx::Class::ResultSet',
is => 'ro',
- lazy_build => 1,
+ builder => '_build_version_rs',
handles => [qw( database_version version_storage_is_installed )],
);
with 'DBIx::Class::DeploymentHandler::HandlesVersionStorage';
+use DBIx::Class::DeploymentHandler::VersionStorage::Deprecated::VersionResult;
sub _build_version_rs {
$_[0]->schema->register_class(
dbix_class_schema_versions =>
use parent 'DBIx::Class::Core';
-__PACKAGE__->table('dbix_class_deploymenthandler_versions');
+__PACKAGE__->table('dbix_class_schema_versions');
__PACKAGE__->add_columns (
version => {
# this is why it's deprecated guys... Serially.
sub create {
my $self = shift;
+ my $args = shift;
my @tm = gettimeofday();
my @dt = gmtime ($tm[0]);
$self->next::method({
- version => $version,
+ %{$args},
installed => sprintf("v%04d%02d%02d_%02d%02d%02d.%03.0f",
$dt[5] + 1900,
$dt[4] + 1,
--- /dev/null
+package DBIx::Class::DeploymentHandler::WithExplicitVersions;
+use Moose::Role;
+
+use DBIx::Class::DeploymentHandler::VersionHandler::ExplicitVersions;
+
+use Carp 'carp';
+
+has version_handler => (
+ is => 'ro',
+ lazy_build => 1,
+ does => 'DBIx::Class::DeploymentHandler::HandlesVersioning',
+ handles => 'DBIx::Class::DeploymentHandler::HandlesVersioning',
+);
+
+sub _build_version_handler {
+ my $self = shift;
+
+ my $args = {
+ database_version => $self->database_version,
+ schema_version => $self->schema_version,
+ };
+
+ $args->{to_version} = $self->to_version if $self->has_to_version;
+ DBIx::Class::DeploymentHandler::VersionHandler::ExplicitVersions->new($args);
+}
+
+1;
+
+__END__
+
+vim: ts=2 sw=2 expandtab
has version_storage => (
does => 'DBIx::Class::DeploymentHandler::HandlesVersionStorage',
is => 'ro',
- lazy_build => 1,
+ builder => '_build_version_storage',
handles => 'DBIx::Class::DeploymentHandler::HandlesVersionStorage',
);
#!perl
-use Test::More;
-use Test::Exception;
-use File::Path 'remove_tree';
-
use lib 't/lib';
use DBICDHTest;
use DBIx::Class::DeploymentHandler;
-my $db = 'dbi:SQLite:db.db';
-my @connection = ($db, '', '', { ignore_version => 1 });
-my $sql_dir = 't/sql';
-
-DBICDHTest::ready;
-
-VERSION1: {
- use_ok 'DBICVersion_v1';
- my $s = DBICVersion::Schema->connect(@connection);
- ok($s, 'DBICVersion::Schema 1.0 instantiates correctly');
- my $handler = DBIx::Class::DeploymentHandler->new({
- upgrade_directory => $sql_dir,
- schema => $s,
- databases => 'SQLite',
- sqltargs => { add_drop_table => 0 },
- });
-
- ok($handler, 'DBIx::Class::DeploymentHandler w/1.0 instantiates correctly');
-
- my $version = $s->schema_version();
- $handler->prepare_install();
-
- dies_ok {
- $s->resultset('Foo')->create({
- bar => 'frew',
- })
- } 'schema not deployed';
- $handler->install;
- dies_ok {
- $handler->install;
- } 'cannot install twice';
- lives_ok {
- $s->resultset('Foo')->create({
- bar => 'frew',
- })
- } 'schema is deployed';
-}
-
-VERSION2: {
- use_ok 'DBICVersion_v2';
- my $s = DBICVersion::Schema->connect(@connection);
- ok($s, 'DBICVersion::Schema 2.0 instantiates correctly');
- my $handler = DBIx::Class::DeploymentHandler->new({
- upgrade_directory => $sql_dir,
- schema => $s,
- databases => 'SQLite',
- });
-
- ok($handler, 'DBIx::Class::DeploymentHandler w/2.0 instantiates correctly');
-
- $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',
- baz => 'frew',
- })
- } 'schema not deployed';
- dies_ok {
- $s->resultset('Foo')->create({
- bar => 'frew',
- baz => 'frew',
- })
- } 'schema not uppgrayyed';
- $handler->upgrade;
- lives_ok {
- $s->resultset('Foo')->create({
- bar => 'frew',
- baz => 'frew',
- })
- } 'schema is deployed';
-}
-
-VERSION3: {
- use_ok 'DBICVersion_v3';
- my $s = DBICVersion::Schema->connect(@connection);
- ok($s, 'DBICVersion::Schema 3.0 instantiates correctly');
- my $handler = DBIx::Class::DeploymentHandler->new({
- upgrade_directory => $sql_dir,
- schema => $s,
- databases => 'SQLite',
- });
-
- ok($handler, 'DBIx::Class::DeploymentHandler w/3.0 instantiates correctly');
+use Test::More;
- $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({
- bar => 'frew',
- baz => 'frew',
- biff => 'frew',
- })
- } 'schema not deployed';
- $handler->upgrade;
- lives_ok {
- $s->resultset('Foo')->create({
- bar => 'frew',
- baz => 'frew',
- biff => 'frew',
- })
- } 'schema is deployed';
-}
+DBICDHTest::test_bundle(DBIx::Class::DeploymentHandler);
done_testing;
-__END__
-
-vim: ts=2 sw=2 expandtab
#!perl
+use lib 't/lib';
+use DBICDHTest;
+use DBIx::Class::DeploymentHandler::Deprecated;
use Test::More;
-use_ok 'DBIx::Class::DeploymentHandler::Deprecated';
+DBICDHTest::test_bundle(DBIx::Class::DeploymentHandler::Deprecated);
done_testing;
-__END__
-
-vim: ts=2 sw=2 expandtab
use warnings;
use File::Path 'remove_tree';
+use Test::More;
+use Test::Exception;
sub ready {
unlink 'db.db' if -e 'db.db';
}
}
+sub test_bundle {
+ my $bundle = shift;
+ my $db = 'dbi:SQLite:db.db';
+ my @connection = ($db, '', '', { ignore_version => 1 });
+ my $sql_dir = 't/sql';
+
+ ready;
+
+ VERSION1: {
+ use_ok 'DBICVersion_v1';
+ my $s = DBICVersion::Schema->connect(@connection);
+ ok($s, 'DBICVersion::Schema 1.0 instantiates correctly');
+ my $handler = $bundle->new({
+ upgrade_directory => $sql_dir,
+ schema => $s,
+ databases => 'SQLite',
+ sqltargs => { add_drop_table => 0 },
+ });
+
+ ok($handler, 'DBIx::Class::DeploymentHandler w/1.0 instantiates correctly');
+
+ my $version = $s->schema_version();
+ $handler->prepare_install();
+
+ dies_ok {
+ $s->resultset('Foo')->create({
+ bar => 'frew',
+ })
+ } 'schema not deployed';
+ $handler->install;
+ dies_ok {
+ $handler->install;
+ } 'cannot install twice';
+ lives_ok {
+ $s->resultset('Foo')->create({
+ bar => 'frew',
+ })
+ } 'schema is deployed';
+ }
+
+ VERSION2: {
+ use_ok 'DBICVersion_v2';
+ my $s = DBICVersion::Schema->connect(@connection);
+ 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_install();
+ $handler->prepare_upgrade('1.0', $version);
+ $handler->prepare_upgrade($version, '1.0');
+ dies_ok {
+ $s->resultset('Foo')->create({
+ bar => 'frew',
+ baz => 'frew',
+ })
+ } 'schema not deployed';
+ dies_ok {
+ $s->resultset('Foo')->create({
+ bar => 'frew',
+ baz => 'frew',
+ })
+ } 'schema not uppgrayyed';
+ $handler->upgrade;
+ lives_ok {
+ $s->resultset('Foo')->create({
+ bar => 'frew',
+ baz => 'frew',
+ })
+ } 'schema is deployed';
+ }
+
+ VERSION3: {
+ use_ok 'DBICVersion_v3';
+ my $s = DBICVersion::Schema->connect(@connection);
+ ok($s, 'DBICVersion::Schema 3.0 instantiates correctly');
+ my $handler = $bundle->new({
+ upgrade_directory => $sql_dir,
+ schema => $s,
+ databases => 'SQLite',
+ });
+
+ ok($handler, 'DBIx::Class::DeploymentHandler w/3.0 instantiates correctly');
+
+ 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({
+ bar => 'frew',
+ baz => 'frew',
+ biff => 'frew',
+ })
+ } 'schema not deployed';
+ $handler->upgrade;
+ lives_ok {
+ $s->resultset('Foo')->create({
+ bar => 'frew',
+ baz => 'frew',
+ biff => 'frew',
+ })
+ } 'schema is deployed';
+ }
+}
+
1;