Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 1913500:Add support for PostgreSQL named service connection #138

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions Bugzilla/DB/Pg.pm
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,33 @@ use constant BLOB_TYPE => {pg_type => DBD::Pg::PG_BYTEA};

sub BUILDARGS {
my ($class, $params) = @_;
my ($user, $pass, $host, $dbname, $port)
= @$params{qw(db_user db_pass db_host db_name db_port)};
my ($user, $pass, $host, $dbname, $port, $dbservice)
= @$params{qw(db_user db_pass db_host db_name db_port db_service)};

# The default database name for PostgreSQL. We have
# to connect to SOME database, even if we have
# no $dbname parameter.
$dbname ||= 'template1';

# construct the DSN from the parameters we got
my $dsn = "dbi:Pg:dbname=$dbname";
$dsn .= ";host=$host" if $host;
$dsn .= ";port=$port" if $port;
my $dsn;
if ($dbservice) {
$dsn = "dbi:Pg:service=$dbservice";
}
elsif ($ENV{PGSERVICE}) {
$dbservice = $ENV{PGSERVICE};
$dsn = "dbi:Pg:service=$dbservice";
}
else {
$dsn = "dbi:Pg:dbname=$dbname";
$dsn .= ";host=$host" if $host;
$dsn .= ";port=$port" if $port;
}

# This stops Pg from printing out lots of "NOTICE" messages when
# creating tables.
$dsn .= ";options='-c client_min_messages=warning'";
$dsn .= ";options='-c client_min_messages=warning'"
unless $dbservice or $ENV{PGSERVICE};

my $attrs = {pg_enable_utf8 => Bugzilla->params->{'utf8'}};

Expand Down
1 change: 1 addition & 0 deletions Bugzilla/Install/Localconfig.pm
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ use constant LOCALCONFIG_VARS => (
{name => 'webservergroup', default => \&_sensible_group,},
{name => 'use_suexec', default => 0,},
{name => 'db_driver', default => 'mysql',},
{name => 'db_service', default => '',},
{name => 'db_host', default => 'localhost',},
{name => 'db_name', default => 'bugs',},
{
Expand Down
4 changes: 4 additions & 0 deletions template/en/default/setup/strings.txt.pl
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ END
can be obtained by listing Bugzilla/DB directory - every module corresponds
to one supported database and the name of the module (before ".pm")
corresponds to a valid value for this variable.
END
localconfig_db_service => <<'END',
The name of the service defining the database connection
parameters. Replaces db_host, db_user, db_name.
END
localconfig_db_host => <<'END',
The DNS name or IP address of the host that the database server runs on.
Expand Down
Loading