Skip to content

Schema migrations

Bacluc edited this page May 20, 2023 · 1 revision

Change the Schema of the Database

If you change the Schema of the Database (add or remove a field of an Entity), you also need to add schema migration.

  1. Make sure the api and the database is running on your local machine. docker compose up -d
  2. Generate the migrations with docker compose exec php bin/console doctrine:migrations:diff
  3. Modify the generated migration:
    1. Describe what your migration does in getDescription()
    2. Modify the up migration if you need to do something manually (like migrating data into the changed schema). If you do something manually, delete the comment that it was auto generated.
    3. Modify the down migration. The down migration should reverse the up migration. At least delete the $this->addSql('CREATE SCHEMA public');.
  4. Execute your migration with docker compose exec php bin/console doctrine:migrations:migrate
  5. Validate that the schema is up to date with: docker compose exec php bin/console doctrine:schema:validate