cpan-testers / cpantesters-api

An API in to data held by CPAN Testers: Test reports and CPAN uploads
Other
4 stars 4 forks source link

Allow configuring database connection via config file #2

Open preaction opened 7 years ago

preaction commented 7 years ago

Often we will want to change which database the API is pointing to. This could be for development or emergency management purposes. With the Schema module using [DBIx::Class::Schema::Config]() for configuration (see https://github.com/cpan-testers/cpantesters-schema/issues/3), we have an easy way to refer to known databases with a simple string. But, we should also provide a way to override the global database configs with our own local ones for flexibility and in case of emergency.

Using the Mojolicious Config plugin, create a section in the config called schema. This section should be a hash reference and contain the keys:

Since we install the API application via CPAN, we will need to either use the MOJO_CONFIG environment variable to point to the config file, or set the MOJO_HOME to control where Mojolicious::Plugin::Config looks for configuration files. We will also likely need to set the moniker of the CPAN::Testers::API application to something friendly like cpantesters-api so that our configuration file name is cpantesters-api.conf and/or cpantesters-api.$MOJO_MODE.conf.

preaction commented 7 years ago

The configuration file was added as part of e683dce68626b62fa1fb55fb7ba534ccf94599fd. The schema key should be added to that, and documented in the lib/CPAN/Testers/API.pm file.