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 => ( ...@@ -60,6 +60,10 @@ use constant LOCALCONFIG_VARS => (
default => 0, default => 0,
}, },
{ {
name => 'db_from_env',
default => 0,
},
{
name => 'db_driver', name => 'db_driver',
default => 'sqlite', default => 'sqlite',
}, },
...@@ -198,6 +202,25 @@ sub read_localconfig { ...@@ -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; return \%localconfig;
} }
...@@ -233,6 +256,7 @@ sub update_localconfig { ...@@ -233,6 +256,7 @@ sub update_localconfig {
my $output = $params->{output} || 0; my $output = $params->{output} || 0;
my $answer = Bugzilla->installation_answers; my $answer = Bugzilla->installation_answers;
my $localconfig = read_localconfig('include deprecated'); my $localconfig = read_localconfig('include deprecated');
my $db_from_env = Bugzilla->localconfig->{db_from_env};
my @new_vars; my @new_vars;
foreach my $var (LOCALCONFIG_VARS) { foreach my $var (LOCALCONFIG_VARS) {
...@@ -258,7 +282,7 @@ sub update_localconfig { ...@@ -258,7 +282,7 @@ sub update_localconfig {
# an answer file, then we don't notify about site_wide_secret # an answer file, then we don't notify about site_wide_secret
# because we assume the intent was to auto-generate it anyway. # because we assume the intent was to auto-generate it anyway.
if (!scalar(keys %$answer) || $name ne 'site_wide_secret') { 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}; $localconfig->{$name} = $var->{default};
} }
...@@ -298,6 +322,9 @@ sub update_localconfig { ...@@ -298,6 +322,9 @@ sub update_localconfig {
foreach my $var (LOCALCONFIG_VARS) { foreach my $var (LOCALCONFIG_VARS) {
my $name = $var->{name}; my $name = $var->{name};
my $desc = $var->{desc}; my $desc = $var->{desc};
next if $db_from_env && $name =~ /^db_(?!from_env)/;
if(!length $desc){ if(!length $desc){
$desc = install_string("localconfig_$name", { root => ROOT_USER }); $desc = install_string("localconfig_$name", { root => ROOT_USER });
chomp($desc); chomp($desc);
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
"Bugzilla Developers <developers@bugzilla.org>" "Bugzilla Developers <developers@bugzilla.org>"
], ],
"dynamic_config" : 1, "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" : [ "license" : [
"unknown" "unknown"
], ],
...@@ -61,6 +61,16 @@ ...@@ -61,6 +61,16 @@
} }
} }
}, },
"db_from_env" : {
"description" : "Support for using $ENV{DATABASE_URL}",
"prereqs" : {
"runtime" : {
"requires" : {
"URI::db" : "0.17"
}
}
}
},
"detect_charset" : { "detect_charset" : {
"description" : "Automatic charset detection for text attachments", "description" : "Automatic charset detection for text attachments",
"prereqs" : { "prereqs" : {
...@@ -387,5 +397,6 @@ ...@@ -387,5 +397,6 @@
} }
}, },
"release_status" : "stable", "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: ...@@ -12,7 +12,7 @@ build_requires:
configure_requires: configure_requires:
ExtUtils::MakeMaker: '6.55' ExtUtils::MakeMaker: '6.55'
dynamic_config: 1 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 license: unknown
meta-spec: meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html url: http://module-build.sourceforge.net/META-spec-v1.4.html
...@@ -40,6 +40,10 @@ optional_features: ...@@ -40,6 +40,10 @@ optional_features:
requires: requires:
MooX::StrictConstructor: '0.008' MooX::StrictConstructor: '0.008'
Type::Tiny: '1' Type::Tiny: '1'
db_from_env:
description: 'Support for using $ENV{DATABASE_URL}'
requires:
URI::db: '0.17'
detect_charset: detect_charset:
description: 'Automatic charset detection for text attachments' description: 'Automatic charset detection for text attachments'
requires: requires:
...@@ -190,3 +194,4 @@ requires: ...@@ -190,3 +194,4 @@ requires:
URI: '1.55' URI: '1.55'
perl: '5.014000' perl: '5.014000'
version: v5.1.1+ version: v5.1.1+
x_serialization_backend: 'CPAN::Meta::YAML version 0.018'
...@@ -298,6 +298,14 @@ my %optional_features = ( ...@@ -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") ) { for my $file ( glob("extensions/*/Config.pm") ) {
......
...@@ -566,7 +566,7 @@ ...@@ -566,7 +566,7 @@
[% ELSIF error == "feature_disabled" %] [% ELSIF error == "feature_disabled" %]
The [% feature_description(feature) FILTER html %] feature is not available in this Bugzilla. 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 If you would like to enable this feature, please run
<kbd>cpanm -l local --installdeps --with-feature [% feature FILTER html %] "."</kbd> <kbd>cpanm -l local --installdeps --with-feature [% feature FILTER html %] "."</kbd>
[% END %] [% END %]
...@@ -1350,6 +1350,10 @@ ...@@ -1350,6 +1350,10 @@
the results of your last search. I'm afraid you will have to start the results of your last search. I'm afraid you will have to start
again from the <a href="query.cgi">search page</a>. 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" %] [% ELSIF error == "missing_datasets" %]
[% title = "No Datasets Selected" %] [% title = "No Datasets Selected" %]
[% docslinks = {'using/reports-and-charts.html' => 'Reporting'} %] [% docslinks = {'using/reports-and-charts.html' => 'Reporting'} %]
......
...@@ -129,6 +129,11 @@ With some combinations of database servers/Perl modules/moonphase this ...@@ -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 doesn't work, and so you can try setting this to 0 to make checksetup.pl
run. run.
END 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', localconfig_db_driver => <<'END',
What SQL database to use. Default is mysql. List of supported databases What SQL database to use. Default is mysql. List of supported databases
can be obtained by listing Bugzilla/DB directory - every module corresponds 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