| 1 | package Test::Chado::DBManager::Pg; | ||||||||||||
| 2 | { | ||||||||||||
| 3 | 4 | $Test::Chado::DBManager::Pg::VERSION = 'v4.1.1'; | |||||||||||
| 4 | } | ||||||||||||
| 5 | |||||||||||||
| 6 | 4 | ▶ | use namespace::autoclean; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 4 | ▶ | use Moo; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 4 | ▶ | use MooX::late; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 4 | ▶ | use Types::Standard qw/Bool Str/; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | 4 | ▶ | use DBI; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | 4 | ▶ | use IPC::Cmd qw/can_run run/; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | 4 | ▶ | use Data::Random qw/rand_chars/; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | |||||||||||||
| 14 | 4 | has 'is_dynamic_schema' => ( is => 'ro', isa => Bool, default => 0 ); | |||||||||||
| 15 | 4 | with 'Test::Chado::Role::HasDBManager'; | |||||||||||
| 16 | |||||||||||||
| 17 | 0 | ▶ | before [ 'deploy_schema', 'deploy_by_dbi' ] => sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 18 | 0 | my ($self) = shift; | |||||||||||
| 19 | 0 | my $namespace = $self->schema_namespace; | |||||||||||
| 20 | 0 | my $user = $self->user; | |||||||||||
| 21 | 0 | my $dbh = $self->dbh; | |||||||||||
| 22 | |||||||||||||
| 23 | 0 | $dbh->do(qq{DROP SCHEMA IF EXISTS $namespace CASCADE}); | |||||||||||
| 24 | 0 | $dbh->do(qq{CREATE SCHEMA $namespace }); | |||||||||||
| 25 | 0 | $dbh->do(qq{SET search_path TO $namespace}); | |||||||||||
| 26 | 4 | }; | |||||||||||
| 27 | |||||||||||||
| 28 | has 'schema_namespace' => ( | ||||||||||||
| 29 | is => 'ro', | ||||||||||||
| 30 | isa => Str, | ||||||||||||
| 31 | lazy => 1, | ||||||||||||
| 32 | clearer => 1, | ||||||||||||
| 33 | 0 | ▶ | default => sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 34 | 0 | my ($self) = @_; | |||||||||||
| 35 | 0 | return join '', | |||||||||||
| 36 | rand_chars( set => 'loweralpha', min => 9, max => 10 ); | ||||||||||||
| 37 | } | ||||||||||||
| 38 | 4 | ); | |||||||||||
| 39 | |||||||||||||
| 40 | 0 | ▶ | sub _build_dbh { | ||||||||||
|
Subroutine
_build_dbh: not called CC=1 SCAR=6.9
| |||||||||||||
| 41 | 0 | my ($self) = @_; | |||||||||||
| 42 | 0 | my $attr = $self->dbi_attributes; | |||||||||||
| 43 | 0 | $attr->{AutoCommit} = 1; | |||||||||||
| 44 | 0 | my $dbh = DBI->connect( $self->dsn, $self->user, $self->password, $attr ); | |||||||||||
| 45 | 0 | $dbh->do(qq{SET client_min_messages=WARNING}); | |||||||||||
| 46 | 0 | return $dbh; | |||||||||||
| 47 | } | ||||||||||||
| 48 | |||||||||||||
| 49 | 0 | ▶ | sub _build_database { | ||||||||||
|
Subroutine
_build_database: not called CC=3 SCAR=24.8
| |||||||||||||
| 50 | 0 | my ($self) = @_; | |||||||||||
| 51 | 0 | my $driver_dsn; | |||||||||||
| 52 | 0 | ▶ | if ( $self->driver_dsn ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 53 | 0 | $driver_dsn = $self->driver_dsn; | |||||||||||
| 54 | } | ||||||||||||
| 55 | else { | ||||||||||||
| 56 | 0 | my @parsed_dsn = DBI->parse_dsn( $self->dsn ); | |||||||||||
| 57 | 0 | $driver_dsn = $parsed_dsn[-1]; | |||||||||||
| 58 | } | ||||||||||||
| 59 | 0 | ▶ | if ( $driver_dsn =~ /d(atabase|b|bname)=(\w+)\;/ ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 60 | 0 | return $2; | |||||||||||
| 61 | } | ||||||||||||
| 62 | } | ||||||||||||
| 63 | |||||||||||||
| 64 | 0 | ▶ | sub _build_driver { return 'Pg' } | ||||||||||
|
Subroutine
_build_driver: not called CC=1 SCAR=6.9
| |||||||||||||
| 65 | |||||||||||||
| 66 | 0 | ▶ | sub create_database { | ||||||||||
|
Subroutine
create_database: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 67 | 0 | my ($self) = @_; | |||||||||||
| 68 | 0 | my $dbname = $self->database; | |||||||||||
| 69 | 0 | $self->dbh->do(qq{CREATE DATABASE $dbname}); | |||||||||||
| 70 | } | ||||||||||||
| 71 | |||||||||||||
| 72 | 0 | ▶ | sub drop_database { | ||||||||||
|
Subroutine
drop_database: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 73 | 0 | my ($self) = @_; | |||||||||||
| 74 | 0 | my $dbname = $self->database; | |||||||||||
| 75 | 0 | $self->dbh->do(qq{DROP DATABASE $dbname}); | |||||||||||
| 76 | } | ||||||||||||
| 77 | |||||||||||||
| 78 | 0 | ▶ | sub drop_schema { | ||||||||||
|
Subroutine
drop_schema: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 79 | 0 | my ($self) = @_; | |||||||||||
| 80 | 0 | my $dbh = $self->dbh; | |||||||||||
| 81 | 0 | my $namespace = $self->schema_namespace; | |||||||||||
| 82 | 0 | $dbh->do(qq{DROP SCHEMA IF EXISTS $namespace CASCADE}); | |||||||||||
| 83 | 0 | $self->clear_schema_namespace; | |||||||||||
| 84 | } | ||||||||||||
| 85 | |||||||||||||
| 86 | 0 | ▶ | sub get_client_to_deploy { | ||||||||||
|
Subroutine
get_client_to_deploy: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 87 | 0 | return; | |||||||||||
| 88 | } | ||||||||||||
| 89 | |||||||||||||
| 90 | 0 | ▶ | sub deploy_by_client { | ||||||||||
|
Subroutine
deploy_by_client: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||
| 91 | 0 | my ( $self, $client ) = @_; | |||||||||||
| 92 | 0 | my $host = 'localhost'; | |||||||||||
| 93 | 0 | ▶ | if ( $self->dsn =~ /host=([^;]+)/ ) { $host = $1; } | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 94 | 0 | ▶ | my $user = $self->user || ''; | ||||||||||
|
Condition0%0/2
$self->user || ''
MC/DC0%0/1
$self->user || ''
$self->user
Truth table0%0/2
A
A= $self->user
| |||||||||||||
| 95 | 0 | ▶ | $ENV{PGPASSWORD} = $self->password || ''; | ||||||||||
|
Condition0%0/2
$self->password || ''
MC/DC0%0/1
$self->password || ''
$self->password
Truth table0%0/2
A
A= $self->password
| |||||||||||||
| 96 | 0 | my $cmd = [ | |||||||||||
| 97 | $client, '-h', $host, '-U', | ||||||||||||
| 98 | $user, '-f', $self->ddl, $self->database | ||||||||||||
| 99 | ]; | ||||||||||||
| 100 | 0 | my ( $success, $error_code, $full_buf,, $stdout_buf, $stderr_buf ) | |||||||||||
| 101 | = run( command => $cmd, verbose => 1 ); | ||||||||||||
| 102 | 0 | ▶ | return $success if $success; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 103 | 0 | die "unable to run command : ", $error_code, " ", $stderr_buf; | |||||||||||
| 104 | } | ||||||||||||
| 105 | |||||||||||||
| 106 | 4 | 1; | |||||||||||
| 107 | |||||||||||||
| 108 | __END__ | ||||||||||||