Schema migrations - ecamp/ecamp3 GitHub Wiki
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.
- Make sure the api and the database is running on your local machine.
docker compose up -d
- Generate the migrations with
docker compose exec php bin/console doctrine:migrations:diff
- Modify the generated migration:
- Describe what your migration does in
getDescription()
- 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.
- Modify the down migration. The down migration should reverse the up migration. At least delete the
$this->addSql('CREATE SCHEMA public');
.
- Describe what your migration does in
- Execute your migration with
docker compose exec php bin/console doctrine:migrations:migrate
- Validate that the schema is up to date with:
docker compose exec php bin/console doctrine:schema:validate