view release on metacpan or search on metacpan
dbcritic - Critique a database schema for best practices
VERSION
version 0.023
USAGE
dbcritic --help
dbcritic --dsn dbi:Oracle:HR --username scott --password tiger
dbcritic --class_name My::Schema --dsn dbi:mysql:database=db --username perl --password pass
DESCRIPTION
This is the command line interface to App::DBCritic, a utility for
scanning a database schema for violations of best practices.
CONFIGURATION
All configuration is done via the command line options described by
dbcritic --help.
bin/dbcritic view on Meta::CPAN
use utf8;
our $VERSION = '0.023'; # VERSION
use Getopt::Long::Descriptive;
use App::DBCritic;
my ( $opt, $usage ) = describe_options(
'%c %o',
[ 'dsn|d=s' => 'DBI data source name' ],
[ 'username|user|u:s' => 'name of user to use to connect to database' ],
[ 'password|pass|p:s' => 'password for connecting to database' ],
[ 'class_name|class|c:s' =>
'DBIx::Class::Schema to use rather than generating one',
],
[ 'help|h' => 'print usage message and exit' ],
);
if ( $opt->help ) {
print $usage->text;
exit;
}
my $critic = App::DBCritic->new(
map { $_ => $opt->$_ }
grep { defined $opt->$_ } qw(dsn username password class_name),
);
$critic->critique();
# PODNAME: dbcritic
# ABSTRACT: Critique a database schema for best practices
__END__
=pod
bin/dbcritic view on Meta::CPAN
dbcritic - Critique a database schema for best practices
=head1 VERSION
version 0.023
=head1 USAGE
dbcritic --help
dbcritic --dsn dbi:Oracle:HR --username scott --password tiger
dbcritic --class_name My::Schema --dsn dbi:mysql:database=db --username perl --password pass
=head1 DESCRIPTION
This is the command line interface to L<App::DBCritic|App::DBCritic>,
a utility for scanning a database schema for violations of best practices.
=head1 CONFIGURATION
All configuration is done via the command line options described by
C<dbcritic --help>.
lib/App/DBCritic.pm view on Meta::CPAN
package App::DBCritic;
# ABSTRACT: Critique a database schema for best practices
#pod =head1 SYNOPSIS
#pod
#pod use App::DBCritic;
#pod
#pod my $critic = App::DBCritic->new(
#pod dsn => 'dbi:Oracle:HR', username => 'scott', password => 'tiger');
#pod $critic->critique();
#pod
#pod =head1 DESCRIPTION
#pod
#pod This package is used to scan a database schema and catalog any violations
#pod of best practices as defined by a set of policy plugins. It takes conceptual
#pod and API inspiration from L<Perl::Critic|Perl::Critic>.
#pod
#pod B<dbcritic> is the command line interface.
#pod
lib/App/DBCritic.pm view on Meta::CPAN
#pod Returns an array of loaded policy names that will be applied during
#pod L</critique>. By default all modules under the
#pod C<App::DBCritic::Policy> namespace are loaded.
#pod
#pod =cut
use Moo;
use Scalar::Util 'blessed';
use App::DBCritic::Loader;
for (qw(username password class_name)) { has $_ => ( is => 'ro' ) }
#pod =attr username
#pod
#pod The optional username used to connect to the database.
#pod
#pod =attr password
#pod
#pod The optional password used to connect to the database.
#pod
#pod =attr class_name
#pod
#pod The name of a L<DBIx::Class::Schema|DBIx::Class::Schema> class you wish to
#pod L</critique>.
#pod Only settable at construction time.
#pod
#pod =cut
has dsn => ( is => 'ro', lazy => 1, default => \&_build_dsn );
lib/App/DBCritic.pm view on Meta::CPAN
coerce => 1,
lazy => 1,
default => \&_build_schema,
coerce => \&_coerce_schema,
predicate => 1,
);
sub _build_schema {
my $self = shift;
my @connect_info = map { $self->$_ } qw(dsn username password);
if ( my $class_name = $self->class_name ) {
return $class_name->connect(@connect_info)
if eval "require $class_name";
}
return _coerce_schema( \@connect_info );
}
sub _coerce_schema {
lib/App/DBCritic.pm view on Meta::CPAN
=head1 VERSION
version 0.023
=head1 SYNOPSIS
use App::DBCritic;
my $critic = App::DBCritic->new(
dsn => 'dbi:Oracle:HR', username => 'scott', password => 'tiger');
$critic->critique();
=head1 DESCRIPTION
This package is used to scan a database schema and catalog any violations
of best practices as defined by a set of policy plugins. It takes conceptual
and API inspiration from L<Perl::Critic|Perl::Critic>.
B<dbcritic> is the command line interface.
This is a work in progress - please see the L</SUPPORT> section below for
information on how to contribute. It especially needs ideas (and
implementations!) of new policies!
=head1 ATTRIBUTES
=head2 username
The optional username used to connect to the database.
=head2 password
The optional password used to connect to the database.
=head2 class_name
The name of a L<DBIx::Class::Schema|DBIx::Class::Schema> class you wish to
L</critique>.
Only settable at construction time.
=head2 dsn
The L<DBI|DBI> data source name (required) used to connect to the database.
lib/App/DBCritic/Policy/BidirectionalRelationship.pm view on Meta::CPAN
package App::DBCritic::Policy::BidirectionalRelationship;
# ABSTRACT: Check for missing bidirectional relationships in ResultSources
#pod =head1 SYNOPSIS
#pod
#pod use App::DBCritic;
#pod
#pod my $critic = App::DBCritic->new(
#pod dsn => 'dbi:Oracle:HR', username => 'scott', password => 'tiger');
#pod $critic->critique();
#pod
#pod =head1 DESCRIPTION
#pod
#pod This policy returns a violation if one or more of a
#pod L<DBIx::Class::ResultSource|DBIx::Class::ResultSource>'s relationships does not
#pod have a corresponding reverse relationship in the other class.
#pod
#pod =cut
lib/App/DBCritic/Policy/BidirectionalRelationship.pm view on Meta::CPAN
=head1 VERSION
version 0.023
=head1 SYNOPSIS
use App::DBCritic;
my $critic = App::DBCritic->new(
dsn => 'dbi:Oracle:HR', username => 'scott', password => 'tiger');
$critic->critique();
=head1 DESCRIPTION
This policy returns a violation if one or more of a
L<DBIx::Class::ResultSource|DBIx::Class::ResultSource>'s relationships does not
have a corresponding reverse relationship in the other class.
=head1 ATTRIBUTES
lib/App/DBCritic/Policy/DuplicateRelationships.pm view on Meta::CPAN
package App::DBCritic::Policy::DuplicateRelationships;
# ABSTRACT: Check for ResultSources with unnecessary duplicate relationships
#pod =head1 SYNOPSIS
#pod
#pod use App::DBCritic;
#pod
#pod my $critic = App::DBCritic->new(
#pod dsn => 'dbi:Oracle:HR', username => 'scott', password => 'tiger');
#pod $critic->critique();
#pod
#pod =head1 DESCRIPTION
#pod
#pod This policy returns a violation if a
#pod L<DBIx::Class::ResultSource|DBIx::Class::ResultSource> has relationships to
#pod other tables that are identical in everything but name.
#pod
#pod =cut
lib/App/DBCritic/Policy/DuplicateRelationships.pm view on Meta::CPAN
=head1 VERSION
version 0.023
=head1 SYNOPSIS
use App::DBCritic;
my $critic = App::DBCritic->new(
dsn => 'dbi:Oracle:HR', username => 'scott', password => 'tiger');
$critic->critique();
=head1 DESCRIPTION
This policy returns a violation if a
L<DBIx::Class::ResultSource|DBIx::Class::ResultSource> has relationships to
other tables that are identical in everything but name.
=head1 ATTRIBUTES
lib/App/DBCritic/Policy/NoPrimaryKey.pm view on Meta::CPAN
package App::DBCritic::Policy::NoPrimaryKey;
# ABSTRACT: Check for DBIx::Class::Schema::ResultSources without primary keys
#pod =head1 SYNOPSIS
#pod
#pod use App::DBCritic;
#pod
#pod my $critic = App::DBCritic->new(
#pod dsn => 'dbi:Oracle:HR', username => 'scott', password => 'tiger');
#pod $critic->critique();
#pod
#pod =head1 DESCRIPTION
#pod
#pod This policy returns a violation if a
#pod L<DBIx::Class::ResultSource|DBIx::Class::ResultSource> has zero primary columns.
#pod
#pod =cut
use strict;
lib/App/DBCritic/Policy/NoPrimaryKey.pm view on Meta::CPAN
=head1 VERSION
version 0.023
=head1 SYNOPSIS
use App::DBCritic;
my $critic = App::DBCritic->new(
dsn => 'dbi:Oracle:HR', username => 'scott', password => 'tiger');
$critic->critique();
=head1 DESCRIPTION
This policy returns a violation if a
L<DBIx::Class::ResultSource|DBIx::Class::ResultSource> has zero primary columns.
=head1 ATTRIBUTES
=head2 description
lib/App/DBCritic/Policy/NullableTextColumn.pm view on Meta::CPAN
package App::DBCritic::Policy::NullableTextColumn;
# ABSTRACT: Check for ResultSources with nullable text columns
#pod =head1 SYNOPSIS
#pod
#pod use App::DBCritic;
#pod
#pod my $critic = App::DBCritic->new(
#pod dsn => 'dbi:Oracle:HR', username => 'scott', password => 'tiger');
#pod $critic->critique();
#pod
#pod =head1 DESCRIPTION
#pod
#pod This policy returns a violation if a
#pod L<DBIx::Class::ResultSource|DBIx::Class::ResultSource> has nullable text
#pod columns.
#pod
#pod =cut
lib/App/DBCritic/Policy/NullableTextColumn.pm view on Meta::CPAN
=head1 VERSION
version 0.023
=head1 SYNOPSIS
use App::DBCritic;
my $critic = App::DBCritic->new(
dsn => 'dbi:Oracle:HR', username => 'scott', password => 'tiger');
$critic->critique();
=head1 DESCRIPTION
This policy returns a violation if a
L<DBIx::Class::ResultSource|DBIx::Class::ResultSource> has nullable text
columns.
=head1 ATTRIBUTES