| 1 | package DBIO::DB2::Introspect; | ||||||||||||||||||||
| 2 | # ABSTRACT: Introspect a DB2 database via SYSCAT + information_schema | ||||||||||||||||||||
| 3 | |||||||||||||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 3 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 3 | ▶ | use base 'DBIO::Introspect::Base'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 3 | ▶ | use DBIO::DB2::Introspect::Tables; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 3 | ▶ | use DBIO::DB2::Introspect::Columns; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 3 | ▶ | use DBIO::DB2::Introspect::Indexes; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 3 | ▶ | use DBIO::DB2::Introspect::ForeignKeys; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 0 | ▶ | sub schema { $_[0]->{schema} // 'USER' } | ||||||||||||||||||
|
Subroutine
schema: not called CC=2 SCAR=17.9
Pod
documented
Condition0%0/2
$_[0]{"schema"} // "USER"
MC/DC0%0/1
$_[0]{"schema"} // "USER"
$_[0]{"schema"}
Truth table0%0/2
A
A= $_[0]{"schema"}
| |||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 0 | ▶ | sub _build_model { | ||||||||||||||||||
|
Subroutine
_build_model: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 19 | 0 | my ($self) = @_; | |||||||||||||||||||
| 20 | 0 | my $dbh = $self->dbh; | |||||||||||||||||||
| 21 | 0 | my $schema = $self->schema; | |||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | 0 | my $tables = DBIO::DB2::Introspect::Tables->fetch($dbh, $schema); | |||||||||||||||||||
| 24 | 0 | my $columns = DBIO::DB2::Introspect::Columns->fetch($dbh, $schema, $tables); | |||||||||||||||||||
| 25 | 0 | my $indexes = DBIO::DB2::Introspect::Indexes->fetch($dbh, $schema, $tables); | |||||||||||||||||||
| 26 | 0 | my $fks = DBIO::DB2::Introspect::ForeignKeys->fetch($dbh, $schema, $tables); | |||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | return { | ||||||||||||||||||||
| 29 | 0 | tables => $tables, | |||||||||||||||||||
| 30 | columns => $columns, | ||||||||||||||||||||
| 31 | indexes => $indexes, | ||||||||||||||||||||
| 32 | foreign_keys => $fks, | ||||||||||||||||||||
| 33 | }; | ||||||||||||||||||||
| 34 | } | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | 2 | ▶ | sub table_fk_info { | ||||||||||||||||||
|
Subroutine
table_fk_info: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||
| 38 | 2 | my ($self, $table_key) = @_; | |||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | return [ | ||||||||||||||||||||
| 41 | map { | ||||||||||||||||||||
| 42 | { | ||||||||||||||||||||
| 43 | constraint_name => $_->{constraint_name}, | ||||||||||||||||||||
| 44 | 1 | ▶ | local_columns => [ @{ $_->{from_columns} || [] } ], | ||||||||||||||||||
|
Condition50%1/2
$_->{'from_columns'} || []
MC/DC0%0/1
$_->{'from_columns'} || []
$_->{'from_columns'}
Truth table50%1/2
A
A= $_->{'from_columns'}
| |||||||||||||||||||||
| 45 | 1 | ▶ | remote_columns => [ @{ $_->{to_columns} || [] } ], | ||||||||||||||||||
|
Condition50%1/2
$_->{'to_columns'} || []
MC/DC0%0/1
$_->{'to_columns'} || []
$_->{'to_columns'}
Truth table50%1/2
A
A= $_->{'to_columns'}
| |||||||||||||||||||||
| 46 | remote_schema => $_->{to_schema}, | ||||||||||||||||||||
| 47 | remote_table => $_->{to_table}, | ||||||||||||||||||||
| 48 | attrs => { | ||||||||||||||||||||
| 49 | on_delete => $_->{on_delete}, | ||||||||||||||||||||
| 50 | on_update => $_->{on_update}, | ||||||||||||||||||||
| 51 | }, | ||||||||||||||||||||
| 52 | } | ||||||||||||||||||||
| 53 | 2 | ▶ | } @{ $self->model->{foreign_keys}{$table_key} || [] } | ||||||||||||||||||
|
Condition100%2/2
$self->model->{'foreign_keys'}{$table_key} || []
MC/DC100%1/1
$self->model->{'foreign_keys'}{$table_key} || []
$self->model->{'foreign_keys'}{$table_key}
Truth table100%2/2
A
A= $self->model->{'foreign_keys'}{$table_key}
| |||||||||||||||||||||
| 54 | ]; | ||||||||||||||||||||
| 55 | } | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | 2 | ▶ | sub table_is_view { | ||||||||||||||||||
|
Subroutine
table_is_view: called CC=4 SCAR=14.3
Pod
documented
| |||||||||||||||||||||
| 59 | 2 | my ($self, $table_key) = @_; | |||||||||||||||||||
| 60 | 2 | ▶ | my $table = $self->model->{tables}{$table_key} || {}; | ||||||||||||||||||
|
Condition50%1/2
$self->model->{'tables'}{$table_key} || {}
MC/DC0%0/1
$self->model->{'tables'}{$table_key} || {}
$self->model->{'tables'}{$table_key}
Truth table50%1/2
A
A= $self->model->{'tables'}{$table_key}
| |||||||||||||||||||||
| 61 | 2 | ▶ | return ($table->{kind} || '') eq 'view' ? 1 : 0; | ||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$table->{'kind'} || ''
MC/DC0%0/1
$table->{'kind'} || ''
$table->{'kind'}
Truth table50%1/2
A
A= $table->{'kind'}
| |||||||||||||||||||||
| 62 | } | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 3 | 1; | |||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | __END__ | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | =pod | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | =encoding UTF-8 | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | =head1 NAME | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | DBIO::DB2::Introspect - Introspect a DB2 database via SYSCAT + information_schema | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | =head1 VERSION | ||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | version 0.900001 | ||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | =head1 DESCRIPTION | ||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | C<DBIO::DB2::Introspect> reads the live state of a DB2 database via | ||||||||||||||||||||
| 83 | C<SYSCAT> and C<information_schema>, returning a unified model hashref. | ||||||||||||||||||||
| 84 | It is the source side of the test-deploy-and-compare strategy used by | ||||||||||||||||||||
| 85 | L<DBIO::DB2::Deploy>. | ||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | my $intro = DBIO::DB2::Introspect->new(dbh => $dbh); | ||||||||||||||||||||
| 88 | my $model = $intro->model; | ||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | Model shape mirrors L<DBIO::DuckDB::Introspect>: | ||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | { | ||||||||||||||||||||
| 93 | tables => { $name => { ... } }, | ||||||||||||||||||||
| 94 | columns => { $table => [ { ... }, ... ] }, | ||||||||||||||||||||
| 95 | indexes => { $table => { $name => { ... } } }, | ||||||||||||||||||||
| 96 | foreign_keys => { $table => [ { ... }, ... ] }, | ||||||||||||||||||||
| 97 | } | ||||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | =head1 ATTRIBUTES | ||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | =head2 schema | ||||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | DB2 schema to introspect. Defaults to C<USER> (current user's schema). | ||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | =head1 METHODS | ||||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | =head2 table_fk_info | ||||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | =head2 table_is_view | ||||||||||||||||||||
| 110 | |||||||||||||||||||||
| 111 | =head1 NORMALIZED CONTRACT | ||||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | The L<DBIO::Introspect::Base> contract used by L<DBIO::Generate> is satisfied | ||||||||||||||||||||
| 114 | by the base-class defaults: the native model built by C<_build_model> already | ||||||||||||||||||||
| 115 | uses the canonical shape (bare table-name keys; C<columns> with | ||||||||||||||||||||
| 116 | C<column_name>/C<data_type>/C<size>/C<not_null>/C<default_value>/C<is_pk>/ | ||||||||||||||||||||
| 117 | C<pk_position>/C<is_auto_increment>; C<indexes> with C<origin> marking the PK | ||||||||||||||||||||
| 118 | index; C<tables> with C<kind>). So C<table_keys>, C<table_columns>, | ||||||||||||||||||||
| 119 | C<table_columns_info>, C<table_pk_info>, C<table_uniq_info> and C<table_is_view> | ||||||||||||||||||||
| 120 | are inherited unchanged. | ||||||||||||||||||||
| 121 | |||||||||||||||||||||
| 122 | Only C<table_fk_info> is overridden: DB2 carries the constraint name and the | ||||||||||||||||||||
| 123 | referenced schema, which the generic default drops. | ||||||||||||||||||||
| 124 | |||||||||||||||||||||
| 125 | =head1 AUTHOR | ||||||||||||||||||||
| 126 | |||||||||||||||||||||
| 127 | DBIO & DBIx::Class Authors | ||||||||||||||||||||
| 128 | |||||||||||||||||||||
| 129 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||
| 130 | |||||||||||||||||||||
| 131 | Copyright (C) 2026 DBIO Authors | ||||||||||||||||||||
| 132 | Portions Copyright (C) 2005-2025 DBIx::Class Authors | ||||||||||||||||||||
| 133 | Based on DBIx::Class, heavily modified. | ||||||||||||||||||||
| 134 | |||||||||||||||||||||
| 135 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||
| 136 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||
| 137 | |||||||||||||||||||||
| 138 | =cut | ||||||||||||||||||||