« DeploymentHandler/VersionStorage/Deprecated/Component.pm
↑ Summary
DeploymentHandler/VersionHandler/DatabaseToSchemaVersions.pm »
| 1 | package DBIx::Class::DeploymentHandler::DeployMethod::SQL::Translator::ScriptHelpers; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 1 | $DBIx::Class::DeploymentHandler::DeployMethod::SQL::Translator::ScriptHelpers::VERSION = '0.002235'; | |||||||||||||||||||||||||||||||||||||||||
| 3 | # ABSTRACT: CodeRef Transforms for common use-cases in DBICDH Migrations | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Sub::Exporter::Progressive -setup => { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | exports => [qw(dbh schema_from_schema_loader)], | ||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use List::Util 'first'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Text::Brew 'distance'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use DBIx::Class::DeploymentHandler::LogImporter qw(:dlog); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 2 | ▶ | sub dbh { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dbh: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 2 | my ($code) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 19 | 2 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 2 | my ($schema, $versions) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 21 | 2 | ▶ | $schema->storage->dbh_do(sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 2 | $code->($_[1], $versions) | |||||||||||||||||||||||||||||||||||||||||
| 23 | }) | ||||||||||||||||||||||||||||||||||||||||||
| 24 | 2 | } | |||||||||||||||||||||||||||||||||||||||||
| 25 | 2 | } | |||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 6 | ▶ | sub _rearrange_connect_info { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_rearrange_connect_info: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 6 | my ($storage) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 6 | my $nci = $storage->_normalize_connect_info($storage->connect_info); | |||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 11 | ▶ | dbh_maker => sub { $storage->dbh }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 6 | map %{$nci->{$_}}, grep { $_ ne 'arguments' } keys %$nci, | |||||||||||||||||||||||||||||||||||||||||
| 35 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 1 | my $count = 0; | |||||||||||||||||||||||||||||||||||||||||
| 39 | 6 | ▶ | sub schema_from_schema_loader { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
schema_from_schema_loader: called CC=10 SCAR=27.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 6 | my ($opts, $code) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 6 | ▶ | die 'schema_from_schema_loader requires options!' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$opts and ref $opts and ref $opts eq "HASH"
$opts and ref $opts
MC/DC0%0/3
$opts and ref $opts and ref $opts eq "HASH"
$opts
ref $opts
ref $opts eq "HASH"
Truth table25%1/4
A and B and C
A= $optsB= ref $optsC= ref $opts eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | unless $opts && ref $opts && ref $opts eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | die 'schema_from_schema_loader requires naming settings to be set!' | ||||||||||||||||||||||||||||||||||||||||||
| 46 | 6 | ▶ | unless $opts->{naming}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | warn 'using "current" naming in a deployment script is begging for problems. Just Say No.' | ||||||||||||||||||||||||||||||||||||||||||
| 49 | if $opts->{naming} eq 'current' || | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | (ref $opts->{naming} eq 'HASH' && first { $_ eq 'current' } values %{$opts->{naming}}); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.3
Branch: 1 branch
Condition33%2/6
$opts->{"naming"} eq "current" or ref $opts->{"naming"} eq "HASH" and &first(sub {
$_ eq "current";
}
, values %{$$opts{"naming"};})
ref $opts->{"naming"} eq "HASH" and &first(sub {
$_ eq "current";
}
, values %{$$opts{"naming"};})
MC/DC0%0/3
$opts->{"naming"} eq "current" or ref $opts->{"naming"} eq "HASH" and &first(sub {
$_ eq "current";
}
, values %{$$opts{"naming"};})
$opts->{"naming"} eq "current"
ref $opts->{"naming"} eq "HASH"
&first(sub {
$_ eq "current";
}
, values %{$$opts{"naming"};})
Truth table25%1/4
A or B and C
A= $opts->{"naming"} eq "current"B= ref $opts->{"naming"} eq "HASH"C= &first(sub {
$_ eq "current";
}
, values %{$$opts{"naming"};})
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | $opts->{debug} = 1 | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 6 | ▶ | if !exists $opts->{debug} && $ENV{DBICDH_TRACE}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not exists $opts->{"debug"} and $ENV{"DBICDH_TRACE"}
MC/DC0%0/2
not exists $opts->{"debug"} and $ENV{"DBICDH_TRACE"}
not exists $opts->{"debug"}
$ENV{"DBICDH_TRACE"}
Truth table33%1/3
not(A) and B
A= not exists $opts->{"debug"}B= $ENV{"DBICDH_TRACE"}
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 6 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 6 | my ($schema, $versions) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 6 | require DBIx::Class::Schema::Loader; | |||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 6 | $schema->storage->ensure_connected; | |||||||||||||||||||||||||||||||||||||||||
| 61 | 6 | my @ci = _rearrange_connect_info($schema->storage); | |||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 6 | my $new_schema = DBIx::Class::Schema::Loader::make_schema_at( | |||||||||||||||||||||||||||||||||||||||||
| 64 | 'SHSchema::' . $count++, $opts, \@ci | ||||||||||||||||||||||||||||||||||||||||||
| 65 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | Dlog_debug { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | "schema_from_schema_loader generated the following sources: $_" | |||||||||||||||||||||||||||||||||||||||||
| 69 | 6 | } [ $new_schema->sources ]; | |||||||||||||||||||||||||||||||||||||||||
| 70 | 6 | my $sl_schema = $new_schema->connect(@ci); | |||||||||||||||||||||||||||||||||||||||||
| 71 | 6 | ▶ | try { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 6 | $code->($sl_schema, $versions) | |||||||||||||||||||||||||||||||||||||||||
| 73 | 1 | ▶ | } catch { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.3
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 1 | ▶ | if (m/Can't find source for (.+?) at/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | my @presentsources = map { | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 1 | ▶ | (distance($_, $1))[0] < 3 ? "$_ <== Possible Match\n" : "$_\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | } $sl_schema->sources; | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 1 | die <<"ERR"; | |||||||||||||||||||||||||||||||||||||||||
| 80 | $_ | ||||||||||||||||||||||||||||||||||||||||||
| 81 | You are seeing this error because the DBIx::Class::ResultSource in your | ||||||||||||||||||||||||||||||||||||||||||
| 82 | migration script called "$1" is not part of the schema that ::Schema::Loader | ||||||||||||||||||||||||||||||||||||||||||
| 83 | has inferred from your existing database. | ||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | To help you debug this issue, here's a list of the actual sources that the | ||||||||||||||||||||||||||||||||||||||||||
| 86 | schema available to your migration knows about: | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | @presentsources | ||||||||||||||||||||||||||||||||||||||||||
| 89 | ERR | ||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | die $_; | |||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||
| 93 | 6 | } | |||||||||||||||||||||||||||||||||||||||||
| 94 | 6 | } | |||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | __END__ | ||||||||||||||||||||||||||||||||||||||||||