From d1e3078abcb863e58a3b8ccc018d8796b0bfcd58 Mon Sep 17 00:00:00 2001 From: Don Armstrong Date: Mon, 29 Aug 2016 09:40:23 -0700 Subject: [PATCH] allow specifying the database using the DSN --- Debbugs/Config.pm | 4 +++- Debbugs/DB.pm | 10 ++++++++++ bin/debbugs-loadsql | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Debbugs/Config.pm b/Debbugs/Config.pm index e0ad78e..1811631 100644 --- a/Debbugs/Config.pm +++ b/Debbugs/Config.pm @@ -1033,7 +1033,9 @@ set_default(\%config,'libravatar_blacklist',[]); =item debbugs_db -Name of debbugs PostgreSQL database service +Name of debbugs PostgreSQL database service. If you wish to not use a service +file, provide a full DBD::Pg compliant data-source, for example: +C<"dbi:Pg:dbname=dbname"> =back diff --git a/Debbugs/DB.pm b/Debbugs/DB.pm index c164636..313bfbb 100644 --- a/Debbugs/DB.pm +++ b/Debbugs/DB.pm @@ -20,4 +20,14 @@ __PACKAGE__->load_namespaces; our $VERSION=2; # You can replace this text with custom code or comments, and it will be preserved on regeneration + +# override connect to handle just passing a bare service +sub connect { + my ($self,@rem) = @_; + if ($rem[0] !~ /:/) { + $rem[0] = 'dbi:Pg:service='.$rem[0]; + } + $self->clone->connection(@rem); +} + 1; diff --git a/bin/debbugs-loadsql b/bin/debbugs-loadsql index 20f5722..a8839e3 100755 --- a/bin/debbugs-loadsql +++ b/bin/debbugs-loadsql @@ -603,7 +603,7 @@ sub db_connect { my ($options) = @_; # connect to the database; figure out how to handle errors # properly here. - my $s = Debbugs::DB->connect('dbi:Pg:service='.$options->{service}) or + my $s = Debbugs::DB->connect($options->{service}) or die "Unable to connect to database: "; } -- 2.39.2