From: Arthur Axel 'fREW' Schmidt Date: Sat, 27 Mar 2010 08:41:46 +0000 (-0500) Subject: make DeployMethod deploy methods public for unversioned use-case X-Git-Tag: v0.001000_01~45 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7d2a697450860554093a1021d3fe4405bac6328e;p=dbsrgits%2FDBIx-Class-DeploymentHandler.git make DeployMethod deploy methods public for unversioned use-case --- diff --git a/lib/DBIx/Class/DeploymentHandler/Dad.pm b/lib/DBIx/Class/DeploymentHandler/Dad.pm index d1a4f83..807c756 100644 --- a/lib/DBIx/Class/DeploymentHandler/Dad.pm +++ b/lib/DBIx/Class/DeploymentHandler/Dad.pm @@ -51,7 +51,7 @@ method install { croak 'Install not possible as versions table already exists in database' if $self->version_storage_is_installed; - my $ddl = $self->_deploy; + my $ddl = $self->deploy; $self->version_storage->add_database_version({ version => $self->to_version, @@ -62,7 +62,7 @@ method install { sub upgrade { my $self = shift; while ( my $version_list = $self->next_version_set ) { - my ($ddl, $upgrade_sql) = @{$self->_upgrade_single_step($version_list)||[]}; + my ($ddl, $upgrade_sql) = @{$self->upgrade_single_step($version_list)||[]}; $self->add_database_version({ version => $version_list->[-1], @@ -72,12 +72,18 @@ sub upgrade { } } -method backup { $self->storage->backup($self->backup_directory) } +sub downgrade { + my $self = shift; + while ( my $version_list = $self->previous_version_set ) { + $self->downgrade_single_step($version_list); -method deploy_version_storage { - $self-> + # do we just delete a row here? I think so but not sure + $self->delete_database_version({ version => $version_list->[-1] }); + } } +method backup { $self->storage->backup($self->backup_directory) } + __PACKAGE__->meta->make_immutable; 1; diff --git a/lib/DBIx/Class/DeploymentHandler/DeployMethod/SQL/Translator.pm b/lib/DBIx/Class/DeploymentHandler/DeployMethod/SQL/Translator.pm index 92f54b5..f8377bf 100644 --- a/lib/DBIx/Class/DeploymentHandler/DeployMethod/SQL/Translator.pm +++ b/lib/DBIx/Class/DeploymentHandler/DeployMethod/SQL/Translator.pm @@ -138,7 +138,7 @@ method _ddl_schema_down_produce_filename($type, $versions, $dir) { return catfile( $dirname, '001-auto.sql'); } -sub _deploy { +sub deploy { my $self = shift; my $storage = $self->storage; @@ -347,7 +347,7 @@ method _read_sql_file($file) { return \@data; } -sub _downgrade_single_step { +sub downgrade_single_step { my $self = shift; my @version_set = @{ shift @_ }; my @downgrade_files = @{$self->_ddl_schema_down_consume_filenames( @@ -364,7 +364,7 @@ sub _downgrade_single_step { } } -sub _upgrade_single_step { +sub upgrade_single_step { my $self = shift; my @version_set = @{ shift @_ }; my @upgrade_files = @{$self->_ddl_schema_up_consume_filenames( diff --git a/lib/DBIx/Class/DeploymentHandler/HandlesDeploy.pm b/lib/DBIx/Class/DeploymentHandler/HandlesDeploy.pm index d328b52..edc39ca 100644 --- a/lib/DBIx/Class/DeploymentHandler/HandlesDeploy.pm +++ b/lib/DBIx/Class/DeploymentHandler/HandlesDeploy.pm @@ -4,9 +4,9 @@ use Moose::Role; requires 'prepare_install'; requires 'prepare_upgrade'; requires 'prepare_downgrade'; -requires '_upgrade_single_step'; -requires '_downgrade_single_step'; -requires '_deploy'; +requires 'upgrade_single_step'; +requires 'downgrade_single_step'; +requires 'deploy'; 1; diff --git a/t/deploy_methods/sql_translator.t b/t/deploy_methods/sql_translator.t index 5eeb3de..779867d 100644 --- a/t/deploy_methods/sql_translator.t +++ b/t/deploy_methods/sql_translator.t @@ -59,7 +59,7 @@ VERSION1: { { my $warned = 0; local $SIG{__WARN__} = sub{$warned = 1}; - $dm->_deploy; + $dm->deploy; ok( $warned, 'deploy warns on sql errors' ); } @@ -126,7 +126,7 @@ VERSION2: { print {$common} qq; close $common; - $dm->_upgrade_single_step([qw( 1.0 2.0 )]); + $dm->upgrade_single_step([qw( 1.0 2.0 )]); is( $s->resultset('Foo')->search({ bar => 'hello', baz => 'world', @@ -137,14 +137,14 @@ VERSION2: { baz => 'frew', }) } 'schema is deployed'; - $dm->_downgrade_single_step([qw( 2.0 1.0 )]); + $dm->downgrade_single_step([qw( 2.0 1.0 )]); dies_ok { $s->resultset('Foo')->create({ bar => 'frew', baz => 'frew', }) } 'schema is downpgrayyed'; - $dm->_upgrade_single_step([qw( 1.0 2.0 )]); + $dm->upgrade_single_step([qw( 1.0 2.0 )]); } VERSION3: { @@ -198,7 +198,7 @@ VERSION3: { biff => 'frew', }) } 'schema not deployed'; - $dm->_upgrade_single_step([qw( 2.0 3.0 )]); + $dm->upgrade_single_step([qw( 2.0 3.0 )]); lives_ok { $s->resultset('Foo')->create({ bar => 'frew', @@ -209,7 +209,7 @@ VERSION3: { rmtree(catfile(qw( t sql SQLite ))); rmtree(catfile(qw( t sql _generic ))); dies_ok { - $dm->_upgrade_single_step([qw( 2.0 3.0 )]); + $dm->upgrade_single_step([qw( 2.0 3.0 )]); } 'dies when sql dir does not exist'; } done_testing; diff --git a/t/deploy_methods/sql_translator_deprecated.t b/t/deploy_methods/sql_translator_deprecated.t index 1b4f0b5..bd9b14d 100644 --- a/t/deploy_methods/sql_translator_deprecated.t +++ b/t/deploy_methods/sql_translator_deprecated.t @@ -40,7 +40,7 @@ VERSION1: { bar => 'frew', }) } 'schema not deployed'; - $dm->_deploy; + $dm->deploy; lives_ok { $s->resultset('Foo')->create({ bar => 'frew', @@ -77,7 +77,7 @@ VERSION2: { baz => 'frew', }) } 'schema not uppgrayyed'; - $dm->_upgrade_single_step(['1.0', $version]); + $dm->upgrade_single_step(['1.0', $version]); lives_ok { $s->resultset('Foo')->create({ bar => 'frew',