Installation
Add the bundle to your composer.json:
composer require dbal-util/cli-bundle
Enable it in config/bundles.php:
return [
// ...
Doctrine\DBALUtil\CLIBundle\CLIBundle::class => ['all' => true],
];
First Command
Register the bundle’s commands via AppKernel (Symfony <5.0) or autoload them (Symfony ≥5.0). Run:
php bin/console list
Look for dbal:util:* commands (e.g., dbal:util:schema:inspect).
Basic Usage Inspect a database schema:
php bin/console dbal:util:schema:inspect --connection=default
Outputs raw schema metadata (tables, columns, constraints) in JSON.
Schema Validation
Use dbal:util:schema:validate to compare a database schema against a reference (e.g., migrations or YAML):
php bin/console dbal:util:schema:validate --connection=default --reference=./schema/reference.yml
jq for readability:
php bin/console dbal:util:schema:validate ... | jq
Data Migration Prep Generate SQL diffs for schema changes:
php bin/console dbal:util:schema:diff --connection=default --from=./schema/old.yml --to=./schema/new.yml > migration.sql
CI/CD Hooks Embed commands in deployment scripts to enforce schema consistency:
# Example: Fail build if schema drifts
php bin/console dbal:util:schema:validate --connection=production || exit 1
Doctrine\DBALUtil\CLIBundle\Command\AbstractCommand to add logic (e.g., custom schema filters).config/packages/doctrine.yaml:
doctrine:
dbal:
connections:
custom:
url: '%env(DATABASE_URL)%'
driver: 'pdo_mysql'
Symfony Version Mismatch
--env=dev to debug autowiring issues.src/Kernel.php if autoloading fails:
$commands = [
new \Doctrine\DBALUtil\CLIBundle\Command\SchemaInspectCommand(),
];
$this->registerCommands($commands);
Connection Handling
default connection. Specify explicitly:
--connection=custom
php bin/console debug:container | grep connection
Output Parsing
grep. Use --format=text (if available) or post-process:
php bin/console dbal:util:schema:inspect | jq -r '.tables[] | "Table: \(.name)"'
Combine with DBAL Directly
Leverage the underlying Doctrine\DBAL\Connection for programmatic access:
$connection = $this->getContainer()->get('dbal.connection');
$schemaManager = $connection->createSchemaManager();
$tables = $schemaManager->listTables(); // Use in custom commands
Schema Snapshots Save schema outputs to version-control:
php bin/console dbal:util:schema:inspect --connection=default > schema/$(date +%Y-%m-%d).json
Performance
--tables="table1,table2".Testing
Mock Doctrine\DBAL\Connection in unit tests:
$connection = $this->createMock(Connection::class);
$connection->method('getSchemaManager')->willReturn($schemaManager);
$this->container->set('dbal.connection', $connection);
How can I help you explore Laravel packages today?