Skip to content
Gerrit Uitslag edited this page Jun 16, 2023 · 1 revision

Doctrine

Makes from entities the database structure. https://symfony.com/doc/5.4/doctrine.html

Status:

  • bin/console doctrine:migrations:status shows status of the migrations

Create and apply migrations for changes:

  • bin/console make:migration symfony manner does doctrine:migrations:diff for making a migration file.

  • bin/console doctrine:migrations:diff create a database migration from the differences between entity mapping and database. Check the generated class. Especially if existing data should be moved/converted extra work is typically needed.

  • bin/console doctrine:migrations:migrate This command executes all migration files that have not already been run against your database. You should run this command on production when you deploy to keep your production database up-to-date.

  • bin/console doctrine:migrations:execute run a single migration

  • bin/console doctrine:migrations:migrate prev go to previous version, so uses down part of a migration Validate:

  • bin/console doctrine:schema:validate to validate the entity mapping is correct and in sync

Make migration for existing database or combine all previous migration in one:

Assumes that production is up-to-date.

  • bin/console doctrine:migrations:diff --from-empty-schema will generate a full migration as if your database was empty. You can then use the rollup command to synchronize the version table of your (already up-to-date) database. (note: do not use dump-schema, its output is based on the database not on the entities)
  • bin/console doctrine:migrations:rollup delete old versions from the database and replace it with the last one. Run this also on production, to reset the version table there. Execution of the one, new, migration is not needed at production because the database should be already up to date. Works only if there is one version in the migrations directory.

Query directly

Results of selects are automatic listed. For listing of results of other sql commands add the --force-fetch option.

  • php bin/console dbal:run-sql 'SELECT * FROM repository'
  • php bin/console dbal:run-sql 'SHOW TABLES' --force-fetch
  • php bin/console dbal:run-sql 'DESC repository' --force-fetch

Other:

  • bin/console doctrine:database:drop drops the database

  • bin/console doctrine:database:create creates the database

  • bin/console doctrine:schema:update dumps the difference between entities and database. Is used in bin/console doctrine:migrations:diff. Does not take care of existing data, therefore, in development environment that should be tested and included in the migrate class.

  • bin/console doctrine:migrations:generate creates empty Migration class which you can fill yourself

Backup

  • mysqldump -u translate -p translate > translate_db_backup_20230414.sql
  • or sometimes: mysqldump -u translate -p --no-tablespaces translate > translate_db_backup_20230414.sql

More readings:

Read more!

Process

Files

Maintenance/development

Documentation

Clone this wiki locally