Steps to add a Field to Entities
-
Create a migration
cd backend && diesel migration generate my_new_migration
This will createup.sqlanddown.sqlinside a new migration folder under/backend/migrations/
up.sqlshould create all necessary tables, columns, constraints as well as modify data if necessary
down.sqlshould undo all changes fromup.sql -
Run the migration
make migrations
During development you can runmake migrations-redoto rundown.sqlandup.sqlof the most recent migration -
Add new field to Entity
e.g. extend thePlantsentity 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. extendPlantsSummaryDtoin dto.rs -
Update usages and trait implementations of DTOs (where applicable)
e.g. implementation of theFromTrait forPlantsSummaryDtoin plants_impl.rs
IMPORTANT: The order of the fields in the DTOs and corresponding entity must be the same as in the generatedschema.rs. -
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>,
[...]
}