You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
762 B
31 lines
762 B
package MJB::Web::Command::dbc;
|
|
use Mojo::Base 'Mojolicious::Command';
|
|
use DBIx::Class::Schema::Config;
|
|
|
|
use Mojo::Util qw( getopt );
|
|
|
|
has description => 'Connect to the DB as if running psql.';
|
|
has usage => "$0 dbc";
|
|
|
|
|
|
sub run {
|
|
my ( $self, @args ) = @_;
|
|
|
|
my $db_conf = DBIx::Class::Schema::Config->coerce_credentials_from_mojolike(
|
|
DBIx::Class::Schema::Config->_make_connect_attrs(
|
|
$self->app->config->{database}{mjb}
|
|
)
|
|
);
|
|
|
|
if ( $db_conf->{dsn} =~ /^dbi:Pg:dbname=([^;]+);host=([^;]+)$/ ) {
|
|
$db_conf->{dbname} = $1;
|
|
$db_conf->{hostname} = $2;
|
|
}
|
|
|
|
$ENV{PGPASSWORD} = $db_conf->{password};
|
|
exec 'psql', '-h', $db_conf->{hostname}, '-U', $db_conf->{user}, $db_conf->{dbname};
|
|
|
|
}
|
|
|
|
1;
|
|
|
|
|