Closed andrea-williams closed 1 week ago
Notes:
Andrea will be creating an additional ticket related to this work.
Ticket to be updated following dev discussion tomorrow
My thoughts:
Pros:
Structured Data: Each type of event can have dedicated columns in the database table, allowing for a well-defined schema. This makes the data easier to query, index, and understand.
Validation: Django models provide built-in validation for each field, which can be enhanced with custom validation methods using Pydantic. This ensures data integrity at the model level.
Ease of Use: When querying the database, you don’t need to parse a JSON field to access specific pieces of information; everything is already well-structured and accessible. Cons:
Scalability: As the number of event types and associated data fields grows, the number of nullable columns can increase, leading to a bloated and less normalized table structure.
Maintenance: Adding new event types may require schema migrations, which can be cumbersome and increase the risk of errors. It also requires careful planning to avoid introducing too many nullable fields.
Data Integrity: Even though you can use validation to enforce rules, having many nullable fields can lead to data sparsity, making it harder to ensure that the right fields are filled for each event type.
Pros:
Cons:
Each event type would have its own model inheriting from a base Event model. This allows each event type to have its own fields but still be treated as a type of Event. Pros:
Cons:
Describe the task
Create database migration with the models needed for the Sales & Transfers epic for Registration Part 2.
UPDATE Aug 14: we've chosen to switch to the Polymorphic Models approach, thus abandoning our earlier decision to store data as json.
Blocked - #1616 Blocking - #1709
Acceptance Criteria
[x] our existing
Event
model will be used as the abstract "parent" model for all event types. Remove theadditional_data
andtype
columns from this model (and from the relevant fixtures). Replace thefacility_id
column with a many-to-many relationship offacilities
.Event
model will have the standard audit fields andeffective_date
(required, date),operation_id
(optional, only populated if the event is at the operation-level), andstatus
[x] create new model
Restart(Event)
[x] create new model
Closure(Event)
with optional string field fordescription
[x] create new model
TemporaryShutdown(Event)
with optional string field fordescription
[x] create new model
Transfer(Event)
with fields:description
(required, freeform text field)future_designated_operator
(required, with Enum of {MY_OPERATOR
,OTHER_OPERATOR
,NOT_SURE
})other_operator
(required, FK to Operator table)other_operator_contact
(required, FK to Contact table viaoperator_contacts
table using id from other_operator field)status
(required, with Enums of {COMPLETE
,PENDING
,TRANSFERRED
}, default value 'PENDING')[x] models included in tests (
test_<model_name>.py
)[x] add/edit fixtures for mock data for each of the affected models
Additional context