File Coverage

blib/lib/DBIx/Migration/Pg.pm
Criterion Covered Total %
statement 15 22 68.1
branch n/a
condition n/a
subroutine 5 7 71.4
pod 2 2 100.0
total 22 31 70.9


line stmt bran cond sub pod time code
1             package DBIx::Migration::Pg;
2              
3             our $VERSION = '0.32';
4              
5 1     1   1679 use Moo;
  1         3  
  1         7  
6 1     1   529 use MooX::StrictConstructor;
  1         2  
  1         9  
7              
8 1     1   1444 use Log::Any qw( $Logger );
  1         2  
  1         12  
9 1     1   1211 use Types::Standard qw( Str );
  1         2  
  1         11  
10              
11 1     1   1972 use namespace::clean -except => [ qw( new ) ];
  1         3  
  1         11  
12              
13             extends 'DBIx::Migration';
14              
15             has '+do_before' => (
16             default => sub {
17             my $self = shift;
18             return [ [ 'SET search_path TO ?', {}, $self->managed_schema ] ];
19             }
20             );
21             has '+do_while' => (
22             default => sub {
23             my $self = shift;
24             return [ sprintf( 'LOCK TABLE %s IN EXCLUSIVE MODE', $self->quoted_tracking_table ) ];
25             }
26             );
27             has '+dsn' => (
28             coerce => sub {
29             my $dsn = shift;
30             return ( ( $dsn =~ m/\Adbi:Pg:\z/i and exists $ENV{ PGSERVICE } ) ? "dbi:Pg:service=$ENV{ PGSERVICE }" : $dsn );
31             }
32             );
33             has managed_schema => ( is => 'ro', isa => Str, default => 'public' );
34             has tracking_schema => ( is => 'ro', isa => Str, default => 'public' );
35             has '+placeholders' => (
36             default => sub {
37             my $self = shift;
38             return { dbix_migration_managed_schema => $self->{ _dbh }->quote_identifier( $self->managed_schema ) };
39             }
40             );
41              
42             sub create_tracking_table {
43 0     0 1   my $self = shift;
44              
45 0           my $tracking_schema = $self->dbh->quote_identifier( $self->tracking_schema );
46 0           $Logger->debugf( "Create tracking schema '%s'", $tracking_schema );
47 0           $self->dbh->do( "CREATE SCHEMA IF NOT EXISTS $tracking_schema" );
48 0           $self->SUPER::create_tracking_table;
49             }
50              
51             sub quoted_tracking_table {
52 0     0 1   my $self = shift;
53              
54 0           return $self->dbh->quote_identifier( undef, $self->tracking_schema, $self->tracking_table );
55             }
56              
57             1;