From: Arthur Axel 'fREW' Schmidt Date: Sat, 27 Mar 2010 04:55:56 +0000 (-0500) Subject: initial cut of deprecated bundle X-Git-Tag: v0.001000_01~51 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=013429985a2df1b341d8e27f98252fa14f878c1f;p=dbsrgits%2FDBIx-Class-DeploymentHandler.git initial cut of deprecated bundle --- diff --git a/lib/DBIx/Class/DeploymentHandler/Deprecated.pm b/lib/DBIx/Class/DeploymentHandler/Deprecated.pm new file mode 100644 index 0000000..5024417 --- /dev/null +++ b/lib/DBIx/Class/DeploymentHandler/Deprecated.pm @@ -0,0 +1,32 @@ +package DBIx::Class::DeploymentHandler::Deprecated; + +use Moose; +use Moose::Util 'apply_all_roles'; + +extends 'DBIx::Class::DeploymentHandler::Dad'; +with 'DBIx::Class::DeploymentHandler::Deprecated::WithDeprecatedSqltDeployMethod', + 'DBIx::Class::DeploymentHandler::Deprecated::WithDeprecatedVersionStorage'; + +sub BUILD { + my $self = shift; + + if ($self->schema->can('ordered_versions')) { + apply_all_roles( + $self, + 'DBIx::Class::DeploymentHandler::WithDatabaseToSchemaVersions' + ); + } else { + apply_all_roles( + $self, + 'DBIx::Class::DeploymentHandler::WithExplicitVersions' + ); + } +} + +__PACKAGE__->meta->make_immutable; + +1; + +__END__ + +vim: ts=2 sw=2 expandtab diff --git a/lib/DBIx/Class/DeploymentHandler/Deprecated/WithDeprecatedSqltDeployMethod.pm b/lib/DBIx/Class/DeploymentHandler/Deprecated/WithDeprecatedSqltDeployMethod.pm new file mode 100644 index 0000000..ab68755 --- /dev/null +++ b/lib/DBIx/Class/DeploymentHandler/Deprecated/WithDeprecatedSqltDeployMethod.pm @@ -0,0 +1,27 @@ +package DBIx::Class::DeploymentHandler::Deprecated::WithDeprecatedSqltDeployMethod; +use Moose::Role; + +use DBIx::Class::DeploymentHandler::DeployMethod::SQL::Translator::Deprecated; + +has deploy_method => ( + does => 'DBIx::Class::DeploymentHandler::HandlesDeploy', + is => 'ro', + lazy_build => 1, + handles => 'DBIx::Class::DeploymentHandler::HandlesDeploy', +); + +sub _build_deploy_method { + my $self = shift; + DBIx::Class::DeploymentHandler::DeployMethod::SQL::Translator::Deprecated->new({ + schema => $self->schema, + databases => $self->databases, + upgrade_directory => $self->upgrade_directory, + sqltargs => $self->sqltargs, + }); +} + +1; + +__END__ + +vim: ts=2 sw=2 expandtab diff --git a/lib/DBIx/Class/DeploymentHandler/Deprecated/WithDeprecatedVersionStorage.pm b/lib/DBIx/Class/DeploymentHandler/Deprecated/WithDeprecatedVersionStorage.pm new file mode 100644 index 0000000..b8bf470 --- /dev/null +++ b/lib/DBIx/Class/DeploymentHandler/Deprecated/WithDeprecatedVersionStorage.pm @@ -0,0 +1,22 @@ +package DBIx::Class::DeploymentHandler::Deprecated::WithDeprecatedVersionStorage; +use Moose::Role; + +use DBIx::Class::DeploymentHandler::VersionStorage::Deprecated; + +has version_storage => ( + does => 'DBIx::Class::DeploymentHandler::HandlesVersionStorage', + is => 'ro', + lazy_build => 1, + handles => 'DBIx::Class::DeploymentHandler::HandlesVersionStorage', +); + +sub _build_version_storage { + DBIx::Class::DeploymentHandler::VersionStorage::Deprecated + ->new({ schema => $_[0]->schema }); +} + +1; + +__END__ + +vim: ts=2 sw=2 expandtab diff --git a/lib/DBIx/Class/DeploymentHandler/VersionStorage/Deprecated.pm b/lib/DBIx/Class/DeploymentHandler/VersionStorage/Deprecated.pm new file mode 100644 index 0000000..385d070 --- /dev/null +++ b/lib/DBIx/Class/DeploymentHandler/VersionStorage/Deprecated.pm @@ -0,0 +1,39 @@ +package DBIx::Class::DeploymentHandler::VersionStorage::Standard; +use Moose; +use Method::Signatures::Simple; + +has schema => ( + isa => 'DBIx::Class::Schema', + is => 'ro', + required => 1, +); + +has version_rs => ( + isa => 'DBIx::Class::ResultSet', + is => 'ro', + lazy_build => 1, + handles => [qw( database_version version_storage_is_installed )], +); + +with 'DBIx::Class::DeploymentHandler::HandlesVersionStorage'; + +sub _build_version_rs { + $_[0]->schema->register_class( + dbix_class_schema_versions => + 'DBIx::Class::DeploymentHandler::VersionStorage::Deprecated::VersionResult' + ); + $_[0]->schema->resultset('dbix_class_schema_versions') +} + +sub add_database_version { + # deprecated doesn't support ddl or upgrade_ddl + $_[0]->version_rs->create({ version => $_[1]->{version} }) +} + +__PACKAGE__->meta->make_immutable; + +1; + +__END__ + +vim: ts=2 sw=2 expandtab diff --git a/lib/DBIx/Class/DeploymentHandler/VersionStorage/Deprecated/Component.pm b/lib/DBIx/Class/DeploymentHandler/VersionStorage/Deprecated/Component.pm new file mode 100644 index 0000000..bfd96dc --- /dev/null +++ b/lib/DBIx/Class/DeploymentHandler/VersionStorage/Deprecated/Component.pm @@ -0,0 +1,37 @@ +package DBIx::Class::DeploymentHandler::VersionStorage::Deprecated::Component; + +use strict; +use warnings; + +use Carp 'carp'; +use DBIx::Class::DeploymentHandler::VersionStorage::Deprecated::VersionResult; + +sub attach_version_storage { + $_[0]->register_class( + dbix_class_schema_versions => 'DBIx::Class::DeploymentHandler::VersionStorage::Deprecated::VersionResult' + ); +} + +sub connection { + my $self = shift; + $self->next::method(@_); + + $self->attach_version_storage; + + my $args = $_[3] || {}; + + unless ( $args->{ignore_version} || $ENV{DBIC_NO_VERSION_CHECK}) { + my $versions = $self->resultset('dbix_class_schema_versions'); + + if (!$versions->version_storage_is_installed) { + carp "Your DB is currently unversioned. Please call upgrade on your schema to sync the DB.\n"; + } elsif ($versions->database_version ne $self->schema_version) { + carp 'Versions out of sync. This is ' . $self->schema_version . + ', your database contains version ' . $versions->database_version . ", please call upgrade on your Schema.\n"; + } + } + + return $self; +} + +1; diff --git a/lib/DBIx/Class/DeploymentHandler/VersionStorage/Deprecated/VersionResult.pm b/lib/DBIx/Class/DeploymentHandler/VersionStorage/Deprecated/VersionResult.pm new file mode 100644 index 0000000..072d8f7 --- /dev/null +++ b/lib/DBIx/Class/DeploymentHandler/VersionStorage/Deprecated/VersionResult.pm @@ -0,0 +1,28 @@ +package DBIx::Class::DeploymentHandler::VersionStorage::Deprecated::VersionResult; + +use strict; +use warnings; + +use parent 'DBIx::Class::Core'; + +__PACKAGE__->table('dbix_class_deploymenthandler_versions'); + +__PACKAGE__->add_columns ( + version => { + data_type => 'VARCHAR', + is_nullable => 0, + size => '10' + }, + installed => { + data_type => 'VARCHAR', + is_nullable => 0, + size => '20' + }, +); + +__PACKAGE__->set_primary_key('version'); + +__PACKAGE__->resultset_class('DBIx::Class::DeploymentHandler::VersionStorage::Deprecated::VersionResultSet'); + +1; + diff --git a/lib/DBIx/Class/DeploymentHandler/VersionStorage/Deprecated/VersionResultSet.pm b/lib/DBIx/Class/DeploymentHandler/VersionStorage/Deprecated/VersionResultSet.pm new file mode 100644 index 0000000..cc4699b --- /dev/null +++ b/lib/DBIx/Class/DeploymentHandler/VersionStorage/Deprecated/VersionResultSet.pm @@ -0,0 +1,49 @@ +package DBIx::Class::DeploymentHandler::VersionStorage::Deprecated::VersionResultSet; + +use strict; +use warnings; + +use parent 'DBIx::Class::ResultSet'; + +use Try::Tiny; +use Time::HiRes 'gettimeofday'; + +sub version_storage_is_installed { + my $self = shift; + try { $self->next; 1 } catch { undef } +} + +sub database_version { + my $self = shift; + $self->search(undef, { + order_by => { -desc => 'installed' }, + rows => 1 + })->get_column('version')->next; +} + +# this is why it's deprecated guys... Serially. +sub create { + my $self = shift; + + my @tm = gettimeofday(); + my @dt = gmtime ($tm[0]); + + $self->next::method({ + version => $version, + installed => sprintf("v%04d%02d%02d_%02d%02d%02d.%03.0f", + $dt[5] + 1900, + $dt[4] + 1, + $dt[3], + $dt[2], + $dt[1], + $dt[0], + $tm[1] / 1000, # convert to millisecs, format as up/down rounded int above + ), + }); +} + +1; + +__END__ + +vim: ts=2 sw=2 expandtab diff --git a/t/03-deprecated.t b/t/03-deprecated.t new file mode 100644 index 0000000..10fbc2d --- /dev/null +++ b/t/03-deprecated.t @@ -0,0 +1,10 @@ +#!perl + +use Test::More; + +use_ok 'DBIx::Class::DeploymentHandler::Deprecated'; + +done_testing; +__END__ + +vim: ts=2 sw=2 expandtab