Categories
Web Development

Using doctrine commands in the console with Symfony Framework

Here is the issue. If you follow along the docs for Doctrine when working on a Symfony framework, you will get issues every once and a while.

./vendor/bin/doctrine-migrations status --show-versions

Something missing or not configured correctly etc. That line is copied and pasted directly from the Doctrine documentation . To use Doctrine this way with Symfony, you must do some further configurations to Doctrine.

If you are using Symfony there is an easier way, unless you must absolutely use Doctrine like that. As programmers we love the easier way right…

sweet meme
Symfony makes it easier to work with Doctrine

What I like to do is use Doctrine with the plain php bin/console. But first I had to figure out how to do that.

Step 1, show console commands

To show the console commands available type the following while in the main directory for you app( the one with public, src, var, etc.)

php bin/console list

This will output a long list of all of the commands you can use in the console with php bin/console xxx-name-of-command.
Here is what mine output.

 

As you can see there are a lot of commands and a lot of them for doctrine.

doctrine
  doctrine:cache:clear-collection-region     Clear a second-level cache collection region
  doctrine:cache:clear-entity-region         Clear a second-level cache entity region
  doctrine:cache:clear-metadata              Clears all metadata cache for an entity manager
  doctrine:cache:clear-query                 Clears all query cache for an entity manager
  doctrine:cache:clear-query-region          Clear a second-level cache query region
  doctrine:cache:clear-result                Clears result cache for an entity manager
  doctrine:database:create                   Creates the configured database
  doctrine:database:drop                     Drops the configured database
  doctrine:database:import                   Import SQL file(s) directly to Database.
  doctrine:ensure-production-settings        Verify that Doctrine is properly configured for a production environment
  doctrine:fixtures:load                     Load data fixtures to your database
  doctrine:mapping:convert                   [orm:convert:mapping] Convert mapping information between supported formats
  doctrine:mapping:import                    Imports mapping information from an existing database
  doctrine:mapping:info                      
  doctrine:migrations:current                [current] Outputs the current version
  doctrine:migrations:diff                   [diff] Generate a migration by comparing your current database to your mapping information.
  doctrine:migrations:dump-schema            [dump-schema] Dump the schema for your database to a migration.
  doctrine:migrations:execute                [execute] Execute one or more migration versions up or down manually.
  doctrine:migrations:generate               [generate] Generate a blank migration class.
  doctrine:migrations:latest                 [latest] Outputs the latest version
  doctrine:migrations:list                   [list-migrations] Display a list of all available migrations and their status.
  doctrine:migrations:migrate                [migrate] Execute a migration to a specified version or the latest available version.
  doctrine:migrations:rollup                 [rollup] Rollup migrations by deleting all tracked versions and insert the one version that exists.
  doctrine:migrations:status                 [status] View the status of a set of migrations.
  doctrine:migrations:sync-metadata-storage  [sync-metadata-storage] Ensures that the metadata storage is at the latest version.
  doctrine:migrations:up-to-date             [up-to-date] Tells you if your schema is up-to-date.
  doctrine:migrations:version                [version] Manually add and delete migration versions from the version table.
  doctrine:query:dql                         Executes arbitrary DQL directly from the command line
  doctrine:query:sql                         Executes arbitrary SQL directly from the command line.
  doctrine:schema:create                     Executes (or dumps) the SQL needed to generate the database schema
  doctrine:schema:drop                       Executes (or dumps) the SQL needed to drop the current database schema
  doctrine:schema:update                     Executes (or dumps) the SQL needed to update the database schema to match the current mapping metadata
  doctrine:schema:validate                   Validate the mapping files

I believe the replacement for the failed show-versions command above is this

 php bin/console doctrine:migrations:list

Which will output information in the following format.

doctrine migration list output
Output of the command php bin/console doctrine:migrations:list

If I had migrations they would be listed and those values shown would be in rows.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.