bcgov / cas-reporting

This is for the Clean Growth Digital Services team for work related to reporting.
Apache License 2.0
0 stars 0 forks source link

Saving activity data to the database #332

Open dleard opened 1 week ago

dleard commented 1 week ago

The purpose of this ticket is to implement saving of activity data to the database. Currently the "submit" button just console logs the contents of the form. We have created (most of) the database objects necessary to save activity data:

The form json follows a standard structure, so we can traverse that structure to deconstruct the contents into the above tables. We should probably add a report_raw_data model to save the full contents of the form before it is disaggregated.

report_raw_data table:

Saving activity data could go like this: 1 save the raw form json data to the report_raw_data table 2 create or update a report_activity record 3 create or update a source_type record (fkey to report_activity) 4 (may not be necessary) create or update an unit record (fkey to report_source_type) 5 (may not be necessary) create or update a fuel record (fkey to report_source_type & report_unit (if exists)) 6 create or update an emission record (fkey to report_source_type & report_fuel (if exists)) 7 create or update a methodology record (fkey to report_emission)

Things to Consider (Attn: Developer):

Acceptance Criteria

As a reporter When I click save or continue Then my data is saved to the database

As a developer When data is saved Then I want the raw form json data saved to the report_raw_data table

As a developer When the data is saved Then I want the disaggregated form data to be saved to the tables above

Development Checklist

pbastia commented 6 days ago

When dealing with arrays:

If form_data does not contain an ID Save record returning ID Add ID to the form_data If form_data contains ID Update record If set of objects does not contain an ID that we have in the db, mark db record ‘deleted’

...and this applies to Units, fuels, emissions. If we (soft)delete a unit, we cascade soft-delete dependent fuels and emissions

dleard commented 1 day ago

@pbastia Something I've just noticed that will likely have an effect on this card: The methodolgy name & related fields are all contained within the emission object which will probably make it hard to differentiate between emission data & methodology data. We may want to consider changing methodology to an object that has the name & any dependent data fields inside of it.