blib/lib/DBICx/Backend/Move/Psql.pm

filter: Statementstmt 46.3% 19 / 41 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 6 / 9 Podpod 100% 1 / 1 totaltotal 49.0% 26 / 53 CC 4 SCAR 20.1
CC
4
Cov
44%
migrate
20.0
__ANON__
2.0
__ANON__
2.0
CRAP 7.5
↑ Summary blib/lib/DBICx/Backend/Move.pm »
1 package DBICx::Backend::Move::Psql;
2  
3 1 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Module::Load 'load';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use DBICx::Deploy;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 extends 'DBICx::Backend::Move';
11  
12 sub migrate
13 0 ▶{
Subroutine migrate: not called CC=4 SCAR=30.0
Pod documented
14 0 my ( $self, $connect_from, $connect_to, $opt ) = @_;
15  
16 0 my $schema = $opt->{schema};
17 0 my $verbose = $opt->{verbose};
18 0 my $logfile = $opt->{logfile};
19  
20 0 $self->deploy($schema, @$connect_to);
21  
22 0 my $from = $schema->connect(@$connect_from);
23 0 my $to = $schema->connect(@$connect_to);
24  
25 0 ▶ $to->txn_do(sub { $to->storage->dbh->do("SET CONSTRAINTS ALL DEFERRED"); $self->transfer_data($from, $to, $opt) });
Subroutine __ANON__: not called CC=1 SCAR=6.9
26  
27  
28 # Transfering data did not update autoincrement sequences so we need to do it manually
29 0 foreach my $source_name ($to->sources) {
30 0 my $column_infos = $to->resultset($source_name)->result_source->columns_info();
31 0 foreach my $column ($to->resultset($source_name)->result_source->columns) {
32 0 ▶ if ($column_infos->{$column}->{is_auto_increment}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($column_infos->{$column}{"is_auto_increment"}) 0 0 0
33  
34 # get the real next value, which is current max+1
35 # If anyone else tries to update this number, it will fail.
36 # Probably ok since we just create this database.
37 0 my $value = $to->resultset($source_name)->get_column($column)->max;
38 0 $value += 1;
39  
40 0 my $table_name = $to->source_registrations->{$source_name}->name;
41 $to->storage->dbh_do(
42 0 ▶ sub { my ($storage, $dbh) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
43 0 my $sequence = $dbh->selectrow_array("select pg_get_serial_sequence('$table_name', '$column');");
44 0 $dbh->do("alter sequence $sequence restart with $value");
45 0 } );
46 }
47 }
48  
49 }
50 0 return 0;
51 }
52  
53 1 1;
↑ Summary blib/lib/DBICx/Backend/Move.pm »