Bug 1284263 - Add optional support for $DATABASE_URL instead of localconfig for…

Bug 1284263 - Add optional support for $DATABASE_URL instead of localconfig for db_* connection params.
parent c61b7ce7
......@@ -60,6 +60,10 @@ use constant LOCALCONFIG_VARS => (
default => 0,
},
{
name => 'db_from_env',
default => 0,
},
{
name => 'db_driver',
default => 'sqlite',
},
......@@ -198,6 +202,25 @@ sub read_localconfig {
}
}
}
require Bugzilla::Error;
if ($localconfig{db_from_env}) {
if (Bugzilla->has_feature('db_from_env')) {
require URI::db;
unless ($ENV{DATABASE_URL}) {
Bugzilla::Error::ThrowUserError('missing_database_url');
}
my $uri = URI::db->new($ENV{DATABASE_URL});
$localconfig{db_driver} = $uri->canonical_engine;
$localconfig{db_name} = $uri->dbname;
$localconfig{db_host} = $uri->host;
$localconfig{db_user} = $uri->user;
$localconfig{db_pass} = $uri->password;
$localconfig{db_port} = $uri->port // 0;
}
else {
Bugzilla::Error::ThrowUserError('feature_disabled', { feature => 'db_from_env' });
}
}
return \%localconfig;
}
......@@ -233,6 +256,7 @@ sub update_localconfig {
my $output = $params->{output} || 0;
my $answer = Bugzilla->installation_answers;
my $localconfig = read_localconfig('include deprecated');
my $db_from_env = Bugzilla->localconfig->{db_from_env};
my @new_vars;
foreach my $var (LOCALCONFIG_VARS) {
......@@ -258,7 +282,7 @@ sub update_localconfig {
# an answer file, then we don't notify about site_wide_secret
# because we assume the intent was to auto-generate it anyway.
if (!scalar(keys %$answer) || $name ne 'site_wide_secret') {
push(@new_vars, $name);
push(@new_vars, $name) unless $db_from_env && $name =~ /^db_(?!from_env)/;
}
$localconfig->{$name} = $var->{default};
}
......@@ -298,6 +322,9 @@ sub update_localconfig {
foreach my $var (LOCALCONFIG_VARS) {
my $name = $var->{name};
my $desc = $var->{desc};
next if $db_from_env && $name =~ /^db_(?!from_env)/;
if(!length $desc){
$desc = install_string("localconfig_$name", { root => ROOT_USER });
chomp($desc);
......
......@@ -4,7 +4,7 @@
"Bugzilla Developers <developers@bugzilla.org>"
],
"dynamic_config" : 1,
"generated_by" : "ExtUtils::MakeMaker version 7.18, CPAN::Meta::Converter version 2.143240",
"generated_by" : "ExtUtils::MakeMaker version 7.24, CPAN::Meta::Converter version 2.150005",
"license" : [
"unknown"
],
......@@ -61,6 +61,16 @@
}
}
},
"db_from_env" : {
"description" : "Support for using $ENV{DATABASE_URL}",
"prereqs" : {
"runtime" : {
"requires" : {
"URI::db" : "0.17"
}
}
}
},
"detect_charset" : {
"description" : "Automatic charset detection for text attachments",
"prereqs" : {
......@@ -387,5 +397,6 @@
}
},
"release_status" : "stable",
"version" : "v5.1.1+"
"version" : "v5.1.1+",
"x_serialization_backend" : "JSON::PP version 2.27300"
}
......@@ -12,7 +12,7 @@ build_requires:
configure_requires:
ExtUtils::MakeMaker: '6.55'
dynamic_config: 1
generated_by: 'ExtUtils::MakeMaker version 7.18, CPAN::Meta::Converter version 2.143240'
generated_by: 'ExtUtils::MakeMaker version 7.24, CPAN::Meta::Converter version 2.150005'
license: unknown
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
......@@ -40,6 +40,10 @@ optional_features:
requires:
MooX::StrictConstructor: '0.008'
Type::Tiny: '1'
db_from_env:
description: 'Support for using $ENV{DATABASE_URL}'
requires:
URI::db: '0.17'
detect_charset:
description: 'Automatic charset detection for text attachments'
requires:
......@@ -190,3 +194,4 @@ requires:
URI: '1.55'
perl: '5.014000'
version: v5.1.1+
x_serialization_backend: 'CPAN::Meta::YAML version 0.018'
......@@ -298,6 +298,14 @@ my %optional_features = (
}
}
},
db_from_env => {
description => 'Support for using $ENV{DATABASE_URL}',
prereqs => {
runtime => {
requires => { 'URI::db' => '0.17' },
},
},
},
);
for my $file ( glob("extensions/*/Config.pm") ) {
......
......@@ -566,7 +566,7 @@
[% ELSIF error == "feature_disabled" %]
The [% feature_description(feature) FILTER html %] feature is not available in this Bugzilla.
[% IF user.in_group('admin') %]
[% IF user.in_group('admin') || Bugzilla.usage_mode != constants.USAGE_MODE_BROWSER %]
If you would like to enable this feature, please run
<kbd>cpanm -l local --installdeps --with-feature [% feature FILTER html %] "."</kbd>
[% END %]
......@@ -1350,6 +1350,10 @@
the results of your last search. I'm afraid you will have to start
again from the <a href="query.cgi">search page</a>.
[% ELSIF error == "missing_database_url" %]
[% title = "Missing \$DATABASE_URL" %]
$DATABASE_URL must be defined when localconfig "db_from_env" option is enabled.
[% ELSIF error == "missing_datasets" %]
[% title = "No Datasets Selected" %]
[% docslinks = {'using/reports-and-charts.html' => 'Reporting'} %]
......
......@@ -129,6 +129,11 @@ With some combinations of database servers/Perl modules/moonphase this
doesn't work, and so you can try setting this to 0 to make checksetup.pl
run.
END
localconfig_db_from_env => <<'END',
If this is set, the other db_* values will be ignored and instead the $DATABASE_URL
will be used to provide the database connection information.
Note this requires the 'db_from_env' feature to be enabled.
END
localconfig_db_driver => <<'END',
What SQL database to use. Default is mysql. List of supported databases
can be obtained by listing Bugzilla/DB directory - every module corresponds
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment