| 1 | package DBIO::MySQL::Introspect; | ||||||||||||||||||||
| 2 | # ABSTRACT: Introspect a MySQL/MariaDB database via information_schema | ||||||||||||||||||||
| 3 | |||||||||||||||||||||
| 4 | 4 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 4 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 4 | ▶ | use base 'DBIO::Introspect::Base'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 4 | ▶ | use DBIO::MySQL::Introspect::Tables; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 4 | ▶ | use DBIO::MySQL::Introspect::Columns; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 4 | ▶ | use DBIO::MySQL::Introspect::Indexes; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 4 | ▶ | use DBIO::MySQL::Introspect::ForeignKeys; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 0 | ▶ | sub _build_model { | ||||||||||||||||||
|
Subroutine
_build_model: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 16 | 0 | my ($self) = @_; | |||||||||||||||||||
| 17 | 0 | my $dbh = $self->dbh; | |||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 0 | my $tables = DBIO::MySQL::Introspect::Tables->fetch($dbh); | |||||||||||||||||||
| 20 | return { | ||||||||||||||||||||
| 21 | 0 | tables => $tables, | |||||||||||||||||||
| 22 | columns => DBIO::MySQL::Introspect::Columns->fetch($dbh, $tables), | ||||||||||||||||||||
| 23 | indexes => DBIO::MySQL::Introspect::Indexes->fetch($dbh, $tables), | ||||||||||||||||||||
| 24 | foreign_keys => DBIO::MySQL::Introspect::ForeignKeys->fetch($dbh, $tables), | ||||||||||||||||||||
| 25 | }; | ||||||||||||||||||||
| 26 | } | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 0 | ▶ | sub view_definition { | ||||||||||||||||||
|
Subroutine
view_definition: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||
| 29 | 0 | my ($self, $key) = @_; | |||||||||||||||||||
| 30 | 0 | my $model = $self->model; | |||||||||||||||||||
| 31 | 0 | ▶ | my $tbl = $model->{tables}{$key} // {}; | ||||||||||||||||||
|
Condition0%0/2
$model->{"tables"}{$key} // {}
MC/DC0%0/1
$model->{"tables"}{$key} // {}
$model->{"tables"}{$key}
Truth table0%0/2
A
A= $model->{"tables"}{$key}
| |||||||||||||||||||||
| 32 | 0 | ▶ | return undef unless ($tbl->{kind} // '') eq 'view'; | ||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$tbl->{"kind"} // ""
MC/DC0%0/1
$tbl->{"kind"} // ""
$tbl->{"kind"}
Truth table0%0/2
A
A= $tbl->{"kind"}
| |||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | 0 | my ($def) = $self->dbh->selectrow_array( | |||||||||||||||||||
| 35 | q{SELECT view_definition FROM information_schema.views | ||||||||||||||||||||
| 36 | WHERE table_schema = DATABASE() AND table_name = ?}, | ||||||||||||||||||||
| 37 | undef, $key, | ||||||||||||||||||||
| 38 | ); | ||||||||||||||||||||
| 39 | 0 | return $def; | |||||||||||||||||||
| 40 | } | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | 4 | ▶ | sub result_class_extra_statements { | ||||||||||||||||||
|
Subroutine
result_class_extra_statements: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||
| 43 | 4 | my ($self, $key) = @_; | |||||||||||||||||||
| 44 | 4 | my $model = $self->model; | |||||||||||||||||||
| 45 | 4 | ▶ | my $tbl = $model->{tables}{$key} // {}; | ||||||||||||||||||
|
Condition50%1/2
$model->{"tables"}{$key} // {}
MC/DC0%0/1
$model->{"tables"}{$key} // {}
$model->{"tables"}{$key}
Truth table50%1/2
A
A= $model->{"tables"}{$key}
| |||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | # source_info is a plain setter -- emit ONE statement, a second call | ||||||||||||||||||||
| 48 | # would replace the first | ||||||||||||||||||||
| 49 | 4 | my %info; | |||||||||||||||||||
| 50 | 4 | ▶ | $info{mysql_engine} = $tbl->{engine} if $tbl->{engine}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 51 | 4 | ▶ | $info{mysql_collation} = $tbl->{table_collation} if $tbl->{table_collation}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 4 | ▶ | return %info ? ([ source_info => \%info ]) : (); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 54 | } | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | 4 | 1; | |||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | __END__ | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | =pod | ||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | =encoding UTF-8 | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | =head1 NAME | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | DBIO::MySQL::Introspect - Introspect a MySQL/MariaDB database via information_schema | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | =head1 VERSION | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | version 0.900001 | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | =head1 DESCRIPTION | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | C<DBIO::MySQL::Introspect> reads the live state of a MySQL or MariaDB | ||||||||||||||||||||
| 75 | database via C<information_schema> and returns a unified model | ||||||||||||||||||||
| 76 | hashref. It is the source side of the test-deploy-and-compare strategy | ||||||||||||||||||||
| 77 | used by L<DBIO::MySQL::Deploy>. | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | my $intro = DBIO::MySQL::Introspect->new(dbh => $dbh); | ||||||||||||||||||||
| 80 | my $model = $intro->model; | ||||||||||||||||||||
| 81 | # $model->{tables}, $model->{columns}, $model->{indexes}, $model->{foreign_keys} | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | The model shape mirrors L<DBIO::PostgreSQL::Introspect> and | ||||||||||||||||||||
| 84 | L<DBIO::SQLite::Introspect> so the same diff/deploy patterns apply. | ||||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | The introspection is scoped to the current database (the C<dbname> | ||||||||||||||||||||
| 87 | component of the DSN) via C<DATABASE()> -- to introspect a different | ||||||||||||||||||||
| 88 | schema, connect with that database in the DSN. | ||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | Each model section is fetched by a per-section reader under the | ||||||||||||||||||||
| 91 | C<Introspect/> subdirectory (L<DBIO::MySQL::Introspect::Tables>, | ||||||||||||||||||||
| 92 | L<DBIO::MySQL::Introspect::Columns>, L<DBIO::MySQL::Introspect::Indexes>, | ||||||||||||||||||||
| 93 | L<DBIO::MySQL::Introspect::ForeignKeys>), matching the family layout | ||||||||||||||||||||
| 94 | mandated by core ADR 0018. The shared C<$tables> filter and C<column_type> | ||||||||||||||||||||
| 95 | size parser live in L<DBIO::MySQL::Introspect::Util>. | ||||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | Most of the generation contract (C<table_keys>, C<table_columns>, | ||||||||||||||||||||
| 98 | C<table_columns_info>, C<table_pk_info>, C<table_uniq_info>, | ||||||||||||||||||||
| 99 | C<table_fk_info>, C<table_is_view>) is provided by | ||||||||||||||||||||
| 100 | L<DBIO::Introspect::Base>; this subclass only overrides the bits | ||||||||||||||||||||
| 101 | that are genuinely MySQL-specific -- the model assembly that delegates to | ||||||||||||||||||||
| 102 | the per-section readers, the view-definition source, and the result-class | ||||||||||||||||||||
| 103 | C<source_info> emission. | ||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | =head1 AUTHOR | ||||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | DBIO & DBIx::Class Authors | ||||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||
| 110 | |||||||||||||||||||||
| 111 | Copyright (C) 2026 DBIO Authors | ||||||||||||||||||||
| 112 | Portions Copyright (C) 2005-2025 DBIx::Class Authors | ||||||||||||||||||||
| 113 | Based on DBIx::Class, heavily modified. | ||||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||
| 116 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | =cut | ||||||||||||||||||||