{"id":50759034,"url":"https://github.com/kraz/doctrine-context-bundle","last_synced_at":"2026-06-11T08:01:57.832Z","repository":{"id":350274097,"uuid":"1205789303","full_name":"kraz/doctrine-context-bundle","owner":"kraz","description":"Symfony bundle for working with more than one doctrine entity manager or connection.","archived":false,"fork":false,"pushed_at":"2026-04-09T17:25:33.000Z","size":31,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-09T17:33:05.860Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kraz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-04-09T09:24:57.000Z","updated_at":"2026-04-09T17:23:20.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/kraz/doctrine-context-bundle","commit_stats":null,"previous_names":["kraz/doctrine-context-bundle"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/kraz/doctrine-context-bundle","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kraz%2Fdoctrine-context-bundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kraz%2Fdoctrine-context-bundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kraz%2Fdoctrine-context-bundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kraz%2Fdoctrine-context-bundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kraz","download_url":"https://codeload.github.com/kraz/doctrine-context-bundle/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kraz%2Fdoctrine-context-bundle/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34188272,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-11T02:00:06.485Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-06-11T08:01:54.158Z","updated_at":"2026-06-11T08:01:57.813Z","avatar_url":"https://github.com/kraz.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Doctrine Context Bundle\n\n[![CI](https://github.com/kraz/doctrine-context-bundle/actions/workflows/ci.yml/badge.svg)](https://github.com/kraz/doctrine-context-bundle/actions/workflows/ci.yml)\n[![Packagist Version](https://img.shields.io/packagist/v/kraz/doctrine-context-bundle)](https://packagist.org/packages/kraz/doctrine-context-bundle)\n[![GitHub license](https://img.shields.io/github/license/kraz/doctrine-context-bundle)](LICENSE)\n\nA Symfony bundle that makes working with multiple Doctrine entity managers or DBAL connections painless. It wraps the standard Doctrine commands so that a single command can target one specific context or fan out across all of them automatically. The only hard dependency is `doctrine/dbal` - ORM and Migrations support are both optional.\n\n## The problem\n\nWhen a project has more than one entity manager or DBAL connection, running the same operation across all of them requires repeating the command manually once per context:\n\n```bash\nphp bin/console doctrine:migrations:migrate --em=shop\nphp bin/console doctrine:migrations:migrate --em=analytics\nphp bin/console doctrine:migrations:migrate --em=audit\n```\n\nThere is also a subtle schema-pollution problem: after running migrations, `doctrine:schema:update` and `doctrine:schema:validate` see the migration metadata table (e.g. `doctrine_migration_versions`) as an unmanaged table and report it as something to drop or as a validation error.\n\n## What this bundle does\n\n- ### Database command integration\n\n    The command `doctrine:database:create` fans out across all registered contexts. Works with DBAL alone - no ORM or Migrations required. Accepts `--connection` / `--conn` to target a single context and `--connections` / `--conns` to target a specific subset.\n\n- ### Migrations command integration\n    \u003e *requires `doctrine/doctrine-migrations-bundle`*\n\n    Every `doctrine:migrations:*` command gains `--em` / `--ems` and `--conn` / `--conns` options. Pass one to target a single context or a subset, or omit all to run across every registered context in sequence.\n\n- ### ORM command integration\n    \u003e *requires `doctrine/orm`*\n\n    The `doctrine:schema:create`, `doctrine:schema:validate`, and `doctrine:mapping:info` receive the same fan-out behaviour, including `--em` / `--ems` for subset selection.\n\n- ### Schema filter\n\n    The migration metadata table remains hidden for commands like `doctrine:schema:update` and `doctrine:schema:validate`, so those commands never see it as unmanaged.\n\n- ### Additional command options for every wrapped command\n\n  - **`--ctx-isolation`**: When set, a failure in one context does not abort the remaining contexts.\n  - **`--ctx-all`**: Explicitly runs the command over all registered contexts. Required when `explicit_context` is enabled and no specific context is given.\n  - **`--ctx-output-style`**: Control how the context name is being printed to the output.\n\n- ### Bundle configurations about commands execution behavior\n  - **`explicit_context`**: When `true`, every wrapped command requires an explicit context via `--em`, `--ems`, `--conn`, `--conns`, `--connection`, `--connections`, or `--ctx-all`. Prevents accidental fan-out in production environments.\n\n## Requirements\n\n| Dependency                            | Version              |\n|---------------------------------------|----------------------|\n| PHP                                   | `\u003e= 8.4`             |\n| `doctrine/doctrine-bundle`            | `^3.2`               |\n| `doctrine/doctrine-migrations-bundle` | `^4.0` *(optional)*  |\n| `doctrine/orm`                        | `^3.6` *(optional)*  |\n\n## Installation\n\n```bash\ncomposer require kraz/doctrine-context-bundle\n```\n\nRegister the bundle in `config/bundles.php` if you are not using Symfony Flex:\n\n```php\nreturn [\n    // ...\n    Kraz\\DoctrineContextBundle\\DoctrineContextBundle::class =\u003e ['all' =\u003e true],\n];\n```\n\n## Configuration\n\nRegister each entity manager or connection that should be treated as a named context. You may use `entity_managers` (requires `doctrine/orm`) or `connections`, but not both for the same name.\n\nThe migration-related options (`migrations_paths`, `storage`, `services`, etc.) are only available when `doctrine/doctrine-migrations-bundle` is installed. Without it, a context is configured with just its name.\n\n### DBAL only (no ORM, no Migrations)\n\n```yaml\n# config/packages/doctrine_context.yaml\ndoctrine_context:\n    connections:\n        default: ~\n        shop: ~\n        analytics: ~\n```\n\n### With DBAL connections and Migrations\n\n```yaml\ndoctrine_context:\n    connections:\n        default:\n            migrations_paths:\n                App\\Migrations\\Default: '%kernel.project_dir%/migrations/default'\n            storage:\n                table_storage:\n                    table_name: doctrine_migration_versions\n        shop:\n            migrations_paths:\n                App\\Migrations\\Shop: '%kernel.project_dir%/migrations/shop'\n            storage:\n                table_storage:\n                    table_name: doctrine_migration_versions\n```\n\n### With entity managers (ORM) and Migrations\n\n```yaml\ndoctrine_context:\n    entity_managers:\n        default:\n            migrations_paths:\n                App\\Migrations\\Default: '%kernel.project_dir%/migrations/default'\n            storage:\n                table_storage:\n                    table_name: doctrine_migration_versions\n        shop:\n            migrations_paths:\n                App\\Migrations\\Shop: '%kernel.project_dir%/migrations/shop'\n            storage:\n                table_storage:\n                    table_name: doctrine_migration_versions\n        analytics:\n            migrations_paths:\n                App\\Migrations\\Analytics: '%kernel.project_dir%/migrations/analytics'\n            storage:\n                table_storage:\n                    table_name: doctrine_migration_versions\n```\n\n### With entity managers (ORM), no Migrations\n\n```yaml\ndoctrine_context:\n    entity_managers:\n        default: ~\n        shop: ~\n        analytics: ~\n```\n\n### Requiring explicit context selection\n\nSet `explicit_context: true` to prevent any wrapped command from fanning out over all contexts unless the caller deliberately opts in with `--ctx-all`. Every invocation must target a specific context or pass `--ctx-all` explicitly, making accidental mass operations impossible.\n\n```yaml\ndoctrine_context:\n    explicit_context: true\n    entity_managers:\n        default: ~\n        shop: ~\n        analytics: ~\n```\n\nWith this option active, the following is an error:\n\n```bash\n# Error: Explicit context is required. Specify a context via --em, --ems, --conn, --conns, or use --ctx-all to run over all contexts.\nphp bin/console doctrine:migrations:migrate --no-interaction\n```\n\nProvide a context or opt into all:\n\n```bash\n# Single context\nphp bin/console doctrine:migrations:migrate --em=shop --no-interaction\n\n# Subset of contexts\nphp bin/console doctrine:migrations:migrate --ems=shop,analytics --no-interaction\n\n# All contexts, intentionally\nphp bin/console doctrine:migrations:migrate --ctx-all --no-interaction\n```\n\n### Full configuration reference\n\nThe migration-related keys below are only accepted when `doctrine/doctrine-migrations-bundle` is installed.\n\n```yaml\ndoctrine_context:\n    explicit_context: false     # when true, --em/--ems/--conn/--conns/--connection/--connections or --ctx-all is required\n    entity_managers:           # or connections:\n        \u003cname\u003e:\n            migrations_paths:\n                \u003cNamespace\u003e: \u003cpath\u003e\n            migrations:        # individual migration classes to load\n                - App\\Migrations\\SpecialMigration\n            storage:\n                table_storage:\n                    table_name: doctrine_migration_versions\n                    version_column_name: ~\n                    version_column_length: ~\n                    executed_at_column_name: ~\n                    execution_time_column_name: ~\n            services:          # override doctrine/migrations services\n                Doctrine\\Migrations\\SomeService: my_symfony_service_id\n            factories:         # override doctrine/migrations services via callables\n                Doctrine\\Migrations\\SomeService: my_factory_service_id\n            all_or_nothing: false\n            check_database_platform: true\n            custom_template: ~\n            organize_migrations: false  # false | BY_YEAR | BY_YEAR_AND_MONTH\n```\n\n## Usage\n\n### Run migrations for all contexts\n\nOmitting `--em` / `--conn` fans the command out across every registered context:\n\n```bash\nphp bin/console doctrine:migrations:migrate --no-interaction\n```\n\nOutput will be grouped by context:\n\n```\nEntity Manager: default\n-----------------------\n\n [notice] Migrating up to ...\n  \nEntity Manager: shop\n--------------------\n\n [notice] Migrating up to ...\n\nEntity Manager: analytics\n-------------------------\n \n [notice] No migrations to execute.\n```\n\n### Target a specific context\n\n```bash\n# entity manager\nphp bin/console doctrine:migrations:migrate --em=shop --no-interaction\n\n# DBAL connection\nphp bin/console doctrine:migrations:migrate --conn=shop --no-interaction\n```\n\n### Target a subset of contexts\n\nUse the plural form of each option to pass multiple context names. Values can be supplied as separate arguments or as a comma-separated list - both forms are equivalent and may be combined:\n\n```bash\n# Separate arguments\nphp bin/console doctrine:migrations:migrate --ems=shop --ems=analytics --no-interaction\n\n# Comma-separated (same result)\nphp bin/console doctrine:migrations:migrate --ems=shop,analytics --no-interaction\n\n# DBAL connections\nphp bin/console doctrine:migrations:migrate --conns=shop,analytics --no-interaction\n\n# ORM schema commands\nphp bin/console doctrine:schema:create --ems=shop,analytics\n```\n\n| Option         | Plural / multi-value form | Applicable commands             |\n|----------------|---------------------------|---------------------------------|\n| `--em`         | `--ems`                   | ORM and migration commands      |\n| `--conn`       | `--conns`                 | Migration and database commands |\n| `--connection` | `--connections`           | Database commands               |\n\n### Continue past failures with `--ctx-isolation`\n\nBy default, a failure in one context stops execution when executed in non-interactive mode. Use `--ctx-isolation` to continue with the remaining contexts regardless:\n\n```bash\nphp bin/console doctrine:migrations:migrate --no-interaction --ctx-isolation\n```\n\n### Run over all contexts explicitly with `--ctx-all`\n\n`--ctx-all` behaves identically to omitting a specific context (fans out over every registered context), but makes the intent explicit. It is required when `explicit_context: true` is configured and no specific context is given:\n\n```bash\nphp bin/console doctrine:migrations:migrate --ctx-all --no-interaction\nphp bin/console doctrine:database:create --ctx-all\n```\n\n### Create databases\n\n```bash\n# All contexts\nphp bin/console doctrine:database:create\n\n# All contexts, explicitly\nphp bin/console doctrine:database:create --ctx-all\n\n# Specific context – all four flags are equivalent\nphp bin/console doctrine:database:create --connection=shop\nphp bin/console doctrine:database:create --conn=shop\n\n# Subset of contexts – all four flags are equivalent\nphp bin/console doctrine:database:create --connections=shop,analytics\nphp bin/console doctrine:database:create --conns=shop,analytics\n```\n\n### All supported commands\n\nAlways available (DBAL only):\n\n| Command                      | Description                                         |\n|------------------------------|-----------------------------------------------------|\n| `doctrine:database:create`   | Create the database for each registered context     |\n\nWhen `doctrine/doctrine-migrations-bundle` is installed:\n\n| Command                                     | Description                                 |\n|---------------------------------------------|---------------------------------------------|\n| `doctrine:migrations:migrate`               | Execute migrations                          |\n| `doctrine:migrations:diff`                  | Generate a migration by diffing the schema  |\n| `doctrine:migrations:generate`              | Generate a blank migration class            |\n| `doctrine:migrations:execute`               | Execute or revert a specific migration      |\n| `doctrine:migrations:status`                | Show the migration status                   |\n| `doctrine:migrations:list`                  | List available migrations                   |\n| `doctrine:migrations:current`               | Show the current migration version          |\n| `doctrine:migrations:latest`                | Show the latest available version           |\n| `doctrine:migrations:up-to-date`            | Check if the schema is up to date           |\n| `doctrine:migrations:rollup`                | Roll up migrations into a single version    |\n| `doctrine:migrations:version`               | Manually add/delete versions from the table |\n| `doctrine:migrations:dump-schema`           | Dump the schema for a mapping               |\n| `doctrine:migrations:sync-metadata-storage` | Sync the metadata storage                   |\n\nWhen `doctrine/orm` is installed:\n\n| Command                    | Description                                  |\n|----------------------------|----------------------------------------------|\n| `doctrine:schema:create`   | Create schema across all entity managers     |\n| `doctrine:schema:validate` | Validate schema across all entity managers   |\n| `doctrine:mapping:info`    | Show mapping info across all entity managers |\n\n### Schema filter\n\nWhen `doctrine/doctrine-migrations-bundle` is installed, the bundle automatically registers a DBAL schema filter per context that hides the migration metadata table from `doctrine:schema:update` and `doctrine:schema:validate`. This prevents those commands from flagging the migration table as an unmanaged or extra table.\n\nThe filter activates only during schema update/validate commands and is otherwise transparent.\n\n## Acknowledgements\n\nThe idea behind this bundle is credited to [DoctrineMigrationsMultipleDatabaseBundle](https://github.com/AvaiBookSports/DoctrineMigrationsMultipleDatabaseBundle) which was heavily refactored to support Symfony 8 and some functional enhancements.\n## License\n\nThis bundle is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkraz%2Fdoctrine-context-bundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkraz%2Fdoctrine-context-bundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkraz%2Fdoctrine-context-bundle/lists"}