Steps to add a Field to Entities
-
Create a migration
cd backend && diesel migration generate my_new_migration
This will createup.sql
anddown.sql
inside a new migration folder under/backend/migrations/
up.sql
should create all necessary tables, columns, constraints as well as modify data if necessary
down.sql
should undo all changes fromup.sql
-
Run the migration
make migration
During development you can runmake migration-redo
to rundown.sql
andup.sql
of the most recent migration -
Add new field to Entity
e.g. extend thePlants
entity in entity.rs -
(Optional) Update the schema patch
If you see an error message similar toerror applying hunk #2
, you will have to update schema.patch -
Add field to DTOs (where applicable)
e.g. extendPlantsSummaryDto
in dto.rs -
Update usages and trait implementations of DTOs (where applicable)
e.g. implementation of theFrom
Trait forPlantsSummaryDto
in plants_impl.rs
IMPORTANT: The order of the fields in the DTOs must be the same as in the corresponding entity. -
Update database schema documentation
Review the documentation under /doc/database/schemata and make the necessary changes. -
Extend API documentation
Review the swagger API documentation under http://localhost:8080/doc/api/swagger/ui/
For better understanding of the API endpoints that uses the modified DTOs, consider adding an#[schema(example = "...")]
attribute macro to the DTO
For example:
pub struct TimelineDto {
#[schema(example = "{ \"2020\": { \"additions\": 7, \"removals\": 7 } }")]
pub years: HashMap<String, TimelineEntryDto>,
[...]
}