Command-line option --config is not applied when creating database connections in standalone mode

Open
#260 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
62/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
php, symfony
Domain
cli, database

Research direction

Start at the throw site named in the report, StandaloneDatabaseSessionRegistry.php line 40, and read what populates the registry before it is consulted. Then find the standalone anonymizer:run command class: check in which order it parses --config, loads the configuration and builds the session registry, since the connection is created too early. Done means running the command with --config pointing outside the project root reaches the anonymizer instead of raising "No connections were configured", with a test covering that ordering; the proposed --connection option is a follow-up decision, not part of the fix.

Written by the indexing model from the issue text.

Description

When running the standalone anonymizer:run command, the database connection is created before the configuration file specified via --config=... is loaded.

As a result, the --config command-line option is not taken into account when the database connection is initialized.

The command works when the configuration file is located in the project root, which is one of the default configuration locations. However, we would like to store configuration files alongside our anonymizer definitions in a custom location and provide the path using --config.

This results in the following error:

In StandaloneDatabaseSessionRegistry.php line 40:

No connections were configured.

A useful addition would be a --connection option that accepts a database connection string directly from the command line.

Besides being more flexible for standalone usage, this would avoid the dependency on loading a configuration file before creating the database connection. It would also make it easier to run the anonymizer in automated environments where connection details are provided through environment variables or deployment configuration rather than configuration files.

Dominant language
PHP
Stars
235
Forks
17
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from makinacorpus/DbToolsBundle

All issues in makinacorpus/DbToolsBundle

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.