« DeploymentHandler/VersionHandler/Monotonic.pm
↑ Summary
DeploymentHandler/VersionStorage/Standard/VersionResult.pm »
| 1 | package DBIx::Class::DeploymentHandler::Dad; | ||||||||||||||||||||||||
| 2 | 12 | $DBIx::Class::DeploymentHandler::Dad::VERSION = '0.002235'; | |||||||||||||||||||||||
| 3 | # ABSTRACT: Parent class for DeploymentHandlers | ||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||
| 5 | 12 | ▶ | use Moose; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 6 | 12 | require DBIx::Class::Schema; # loaded for type constraint | |||||||||||||||||||||||
| 7 | 12 | ▶ | use Carp::Clan '^DBIx::Class::DeploymentHandler'; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 8 | 12 | ▶ | use DBIx::Class::DeploymentHandler::LogImporter ':log'; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 9 | 12 | ▶ | use DBIx::Class::DeploymentHandler::Types; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||
| 11 | 12 | has schema => ( | |||||||||||||||||||||||
| 12 | is => 'ro', | ||||||||||||||||||||||||
| 13 | required => 1, | ||||||||||||||||||||||||
| 14 | ); | ||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||
| 16 | 12 | has backup_directory => ( | |||||||||||||||||||||||
| 17 | isa => 'Str', | ||||||||||||||||||||||||
| 18 | is => 'ro', | ||||||||||||||||||||||||
| 19 | predicate => 'has_backup_directory', | ||||||||||||||||||||||||
| 20 | ); | ||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||
| 22 | 12 | has to_version => ( | |||||||||||||||||||||||
| 23 | is => 'ro', | ||||||||||||||||||||||||
| 24 | isa => 'Str', | ||||||||||||||||||||||||
| 25 | lazy_build => 1, | ||||||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||
| 28 | 31 | ▶ | sub _build_to_version { | ||||||||||||||||||||||
|
Subroutine
_build_to_version: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||
| 29 | 31 | my $version = $_[0]->schema_version; | |||||||||||||||||||||||
| 30 | 31 | ▶ | ref($version) ? $version->numify : $version; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||
| 33 | 12 | has schema_version => ( | |||||||||||||||||||||||
| 34 | is => 'ro', | ||||||||||||||||||||||||
| 35 | lazy_build => 1, | ||||||||||||||||||||||||
| 36 | ); | ||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||
| 38 | 36 | ▶ | sub _build_schema_version { $_[0]->schema->schema_version } | ||||||||||||||||||||||
|
Subroutine
_build_schema_version: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||
| 40 | 19 | ▶ | sub install { | ||||||||||||||||||||||
|
Subroutine
install: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||
| 41 | 19 | my $self = shift; | |||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||
| 43 | 19 | ▶ | my $version = (shift @_ || {})->{version} || $self->to_version; | ||||||||||||||||||||||
|
Condition80%4/5
+(shift @_ || {})->{'version'} || $self->to_version
shift @_ || {}
MC/DC0%0/2
+(shift @_ || {})->{'version'} || $self->to_version
shift @_
$self->to_version
Truth table66%2/3
A || B
A= shift @_B= $self->to_version
| |||||||||||||||||||||||||
| 44 | 0 | ▶ | log_info { "installing version $version" }; | ||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||
| 45 | 19 | ▶ | croak 'Install not possible as versions table already exists in database' | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 46 | if $self->version_storage_is_installed; | ||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||
| 48 | 12 | ▶ | $self->txn_do(sub { | ||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 49 | 12 | my $ddl = $self->deploy({ version=> $version }); | |||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||
| 51 | 12 | $self->add_database_version({ | |||||||||||||||||||||||
| 52 | version => $version, | ||||||||||||||||||||||||
| 53 | ddl => $ddl, | ||||||||||||||||||||||||
| 54 | }); | ||||||||||||||||||||||||
| 55 | 12 | }); | |||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||
| 58 | 15 | ▶ | sub upgrade { | ||||||||||||||||||||||
|
Subroutine
upgrade: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||
| 59 | 0 | ▶ | log_info { 'upgrading' }; | ||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||
| 60 | 15 | my $self = shift; | |||||||||||||||||||||||
| 61 | 15 | my $ran_once = 0; | |||||||||||||||||||||||
| 62 | 15 | ▶ | $self->txn_do(sub { | ||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||
| 63 | 15 | ▶ | while ( my $version_list = $self->next_version_set ) { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 64 | 15 | $ran_once = 1; | |||||||||||||||||||||||
| 65 | my ($ddl, $upgrade_sql) = @{ | ||||||||||||||||||||||||
| 66 | 15 | ▶ | $self->upgrade_single_step({ version_set => $version_list }) | ||||||||||||||||||||||
|
Condition50%1/2
$self->upgrade_single_step({'version_set', $version_list}) || []
MC/DC0%0/1
$self->upgrade_single_step({'version_set', $version_list}) || []
$self->upgrade_single_step({'version_set', $version_list})
Truth table50%1/2
A
A= $self->upgrade_single_step({'version_set', $version_list})
| |||||||||||||||||||||||||
| 67 | ||[]}; | ||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||
| 69 | 15 | $self->add_database_version({ | |||||||||||||||||||||||
| 70 | version => $version_list->[-1], | ||||||||||||||||||||||||
| 71 | ddl => $ddl, | ||||||||||||||||||||||||
| 72 | upgrade_sql => $upgrade_sql, | ||||||||||||||||||||||||
| 73 | }); | ||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||
| 75 | 15 | }); | |||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||
| 77 | 0 | ▶ | log_warn { 'no need to run upgrade' } unless $ran_once; | ||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
Branch: 1 branch
| |||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||
| 80 | 7 | ▶ | sub downgrade { | ||||||||||||||||||||||
|
Subroutine
downgrade: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||
| 81 | 0 | ▶ | log_info { 'downgrading' }; | ||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||
| 82 | 7 | my $self = shift; | |||||||||||||||||||||||
| 83 | 7 | my $ran_once = 0; | |||||||||||||||||||||||
| 84 | 7 | ▶ | $self->txn_do(sub { | ||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||
| 85 | 7 | ▶ | while ( my $version_list = $self->previous_version_set ) { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 86 | 7 | $ran_once = 1; | |||||||||||||||||||||||
| 87 | 7 | $self->downgrade_single_step({ version_set => $version_list }); | |||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||
| 89 | # do we just delete a row here? I think so but not sure | ||||||||||||||||||||||||
| 90 | 7 | $self->delete_database_version({ version => $version_list->[0] }); | |||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||
| 92 | 7 | }); | |||||||||||||||||||||||
| 93 | 0 | ▶ | log_warn { 'no version to run downgrade' } unless $ran_once; | ||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
Branch: 1 branch
| |||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||
| 96 | 0 | ▶ | sub backup { | ||||||||||||||||||||||
|
Subroutine
backup: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||
| 97 | 0 | my $self = shift; | |||||||||||||||||||||||
| 98 | 0 | ▶ | log_info { 'backing up' }; | ||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||
| 99 | 0 | $self->schema->storage->backup($self->backup_directory) | |||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||
| 102 | 12 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||
| 104 | 12 | 1; | |||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||
| 106 | # vim: ts=2 sw=2 expandtab | ||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||
| 108 | __END__ | ||||||||||||||||||||||||