Ideally, our Django models will support both v1 and v2. We'll achieve this mainly with use of null=True
, but in some cases more may be required.
If you need to add something new, you can directly edit the model files (in bc_obps/registration/models
):
- If you're creating a new table, create a new file for it
- If you're adding a column to an existing table, it needs to be nullable so that v1 can continue to use the existing table. Set
(null=True)
and(blank=True)
(null is for the db and blank is for django forms) - Create and run migrations
- Add tests to the v2 test folder. The testing commands in test.md run the tests for both v1 and v2
If data is no longer necessary for v2 but existed in v1:
- Set the column to nullable and blank in the model file
- Run migrations
- Check if that field is being referenced anywhere in the codebase. If it is, we must remove that reference to avoid breaking the app
- No test updates needed--we don't test if fields are mandatory or not
If you need to change something:
- See if it's possible to make the change in a way to make the existing models work for both v1 and v2. For example, in v1 we have
operation_type
as aCharField
, and in v2 it will be a foreign key field to anOperationType
models. We can add the v1 types (they were selected via dropdown so only a few options) to to theOperationType
model so that both v1 and v2 can use the foreign key table. - If it's not possible to use the same models, we'll have to look into field or model versioning. E.g. of field versioning: We have
data_field
. We createdata_field_1
. Once we are done with v2, we can removedata_field
and renamedata_field_1
todata_field
.