File Coverage

lib/DBIx/SchemaChecksum/App/ShowUpdatePath.pm
Criterion Covered Total %
statement 30 32 93.7
branch 9 16 56.2
condition 1 3 33.3
subroutine 7 7 100.0
pod n/a
total 47 58 81.0


line stmt bran cond sub pod time code
1             package DBIx::SchemaChecksum::App::ShowUpdatePath;
2 2     2   37600 use 5.010;
  2         12  
3              
4             # ABSTRACT: Show the update path
5              
6 2     2   635 use MooseX::App::Command;
  2         748198  
  2         21  
7             extends qw(DBIx::SchemaChecksum::App);
8 2     2   1469364 use Carp qw(croak);
  2         8  
  2         166  
9 2     2   18 use Moose::Util::TypeConstraints;
  2         6  
  2         25  
10              
11             option 'from_checksum' => ( is => 'ro', isa => 'Str',documentation => q[start update path from this checksum]
12             );
13             option 'output' => ( is => 'ro', default=>'nice',isa=>enum([qw[ nice concat psql ]]),);
14             option 'dbname' => ( is=>'ro', isa=>'Str', default=>'datebase_name');
15             option '+sqlsnippetdir' => ( required => 1);
16              
17             has '_concat' => (is=>'rw',isa=>'Str', default=>'');
18              
19             sub run {
20 1     1   3226 my $self = shift;
21              
22 1   33     73 $self->show_update_path( $self->from_checksum || $self->checksum );
23              
24             }
25              
26             sub show_update_path {
27 5     5   16 my ($self, $this_checksum) = @_;
28 5         181 my $update_path = $self->_update_path;
29              
30             my $update = $update_path->{$this_checksum}
31 5 100       18 if ( exists $update_path->{$this_checksum} );
32              
33 5 100       15 unless ($update) {
34 1 50       33 print "# " if $self->output eq 'psql';
35 1 50       30 print "-- " if $self->output eq 'concat';
36 1         16 say "No update found that's based on $this_checksum.";
37 1         10 return;
38             }
39              
40 4 100       14 if ( $update->[0] eq 'SAME_CHECKSUM' ) {
41 2         9 my ( $file, $post_checksum ) = splice( @$update, 1, 2 );
42 2         10 $self->report_file($file, $post_checksum);
43 2         302 $self->show_update_path($post_checksum);
44             }
45             else {
46 2         73 $self->report_file($update->[0],$update->[1]);
47 2         381 $self->show_update_path($update->[1]);
48             }
49             }
50              
51             sub report_file {
52 4     4   10 my ($self, $file, $checksum) = @_;
53              
54 4 50       124 if ($self->output eq 'nice') {
    0          
    0          
55 4         138 say $file->relative($self->sqlsnippetdir) ." ($checksum)";
56             }
57             elsif ($self->output eq 'psql') {
58 0           say 'psql '.$self->dbname.' -1 -f '.$file->relative($self->sqlsnippetdir);
59             }
60             elsif ($self->output eq 'concat') {
61 0           say "\n-- file: ".$file->relative($self->sqlsnippetdir)."\n".join('',$file->slurp)."\n";
62             }
63             }
64              
65             __PACKAGE__->meta->make_immutable();
66             1;
67              
68             __END__
69              
70             =pod
71              
72             =encoding UTF-8
73              
74             =head1 NAME
75              
76             DBIx::SchemaChecksum::App::ShowUpdatePath - Show the update path
77              
78             =head1 VERSION
79              
80             version 1.102
81              
82             =head1 DESCRIPTION
83              
84             Show the whole update path starting from the current checksum, or from
85             the one provided via C<--from_checksum>. Use 'C<--output concat>' to
86             concat all changes to STDOUT. Use 'C<--output psql --dbname your-db>'
87             to print some C<psql> commands to apply changes.
88              
89             =head1 AUTHORS
90              
91             =over 4
92              
93             =item *
94              
95             Thomas Klausner <domm@cpan.org>
96              
97             =item *
98              
99             MaroÅ¡ Kollár <maros@cpan.org>
100              
101             =item *
102              
103             Klaus Ita <koki@worstofall.com>
104              
105             =back
106              
107             =head1 COPYRIGHT AND LICENSE
108              
109             This software is copyright (c) 2012 by Thomas Klausner, MaroÅ¡ Kollár, Klaus Ita.
110              
111             This is free software; you can redistribute it and/or modify it under
112             the same terms as the Perl 5 programming language system itself.
113              
114             =cut