Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Cli Bundle Laravel Package

dbal-util/cli-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. 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],
    ];
    
  2. 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).

  3. Basic Usage Inspect a database schema:

    php bin/console dbal:util:schema:inspect --connection=default
    

    Outputs raw schema metadata (tables, columns, constraints) in JSON.


Implementation Patterns

Workflow Integration

  1. 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
    
    • Tip: Pipe output to jq for readability:
      php bin/console dbal:util:schema:validate ... | jq
      
  2. 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
    
  3. 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
    

Customization

  • Extend Commands: Subclass Doctrine\DBALUtil\CLIBundle\Command\AbstractCommand to add logic (e.g., custom schema filters).
  • Configuration: Override default DBAL connections in config/packages/doctrine.yaml:
    doctrine:
        dbal:
            connections:
                custom:
                    url: '%env(DATABASE_URL)%'
                    driver: 'pdo_mysql'
    

Gotchas and Tips

Pitfalls

  1. Symfony Version Mismatch

    • The bundle lacks explicit Symfony 5+ support. Use --env=dev to debug autowiring issues.
    • Fix: Manually register commands in src/Kernel.php if autoloading fails:
      $commands = [
          new \Doctrine\DBALUtil\CLIBundle\Command\SchemaInspectCommand(),
      ];
      $this->registerCommands($commands);
      
  2. Connection Handling

    • Commands default to default connection. Specify explicitly:
      --connection=custom
      
    • Debug: List available connections:
      php bin/console debug:container | grep connection
      
  3. Output Parsing

    • Raw JSON output may break tools like grep. Use --format=text (if available) or post-process:
      php bin/console dbal:util:schema:inspect | jq -r '.tables[] | "Table: \(.name)"'
      

Tips

  1. 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
    
  2. Schema Snapshots Save schema outputs to version-control:

    php bin/console dbal:util:schema:inspect --connection=default > schema/$(date +%Y-%m-%d).json
    
  3. Performance

    • For large schemas, limit output with --tables="table1,table2".
    • Cache schema metadata in a service to avoid repeated DB calls.
  4. Testing Mock Doctrine\DBAL\Connection in unit tests:

    $connection = $this->createMock(Connection::class);
    $connection->method('getSchemaManager')->willReturn($schemaManager);
    $this->container->set('dbal.connection', $connection);
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky