App-LedgerSMB-Admin
view release on metacpan or search on metacpan
lib/App/LedgerSMB/Admin/Database.pm view on Meta::CPAN
=head1 PROPERTIES INHERITED FROM PGObject::Util::DBAdmin
Please see the docs for PGObject::Util::DBAdmin.
=head2 username
=head2 password
=head2 host
=head2 port
=head2 dbname
=head1 ADDITIONAL PROPERTIES
=head2 version
Returns the version number of the database.
=cut
has version => (is => 'lazy');
sub _build_version {
my $self = shift;
return App::LedgerSMB::Admin::Database::Setting->new(
database => $self,
setting_key => 'version')->value;
}
=head2 major_version
Major versions are generally understood to be not backwards compatible. In
LedgerSMB, as with PostgreSQL, major versions are based on the second numbers
in the version, so 1.2, 1.3, and 1.4 are major versions.
=cut
has major_version => (is => 'lazy');
sub _build_major_version {
my $self = shift;
my $version = $self->version;
$version =~ s/\.\d*(?:-dev)?$//;
return $version;
}
=head1 METHODS INHERITED
Please see the docs for PGObject::Util::DBAdmin
=head2 create
=head2 connect
=head2 drop
=head2 run_file
=head2 backup
=head2 restore_backup
=head1 NEW METHODS
=head2 stats
Returns a hashref of table names to rows. The following tables are counted:
=over
=item ar
=item ap
=item gl
=item oe
=item acc_trans
=item users
=item entity_credit_account
=item entity
=back
=cut
my @tables = qw(ar ap gl users entity_credit_account entity acc_trans oe);
sub stats {
my ($self) = @_;
my $dbh = $self->connect;
my $results;
$results->{$_->{table}} = $_->{count}
for map {
my $sth = $dbh->prepare($_->{query});
$sth->execute;
my ($count) = $sth->fetchrow_array;
{ table => $_->{table}, count => $count };
} map {
my $qt = 'SELECT COUNT(*) FROM __TABLE__';
my $id = $dbh->quote_identifier($_);
$qt =~ s/__TABLE__/$id/;
{ table => $_, query => $qt };
} @tables;
return $results;
}
=head2 load($major_version)
Loads the db schema for the major version requested.
=cut
sub load {
my ($self, $major_version) = @_;
( run in 2.224 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )