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

Allow configuring database connection via config file #2

Open
preaction opened this issue Nov 22, 2016 · 1 comment
Open

Allow configuring database connection via config file #2

preaction opened this issue Nov 22, 2016 · 1 comment

Comments

@preaction
Copy link
Member

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 cpan-testers/cpantesters-schema#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:

  • database, which is either a name of a database in the DBIx::Class::Schema::Config configuration file or a full DBI data source name (DSN)
  • user, which is the user to connect with (or override the DBIC::Schema::Config user with)
  • password, which is the password to connect with (or override the DBIC::Schema::Config password with)
  • args, which is a hash reference of additional arguments to DBI (things like PrintError => 0 and the like), and which will likely be rarely used except to get some better debug logging

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
Copy link
Member Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant