[Collector] Update DB to support eCAPRIS funding sync#1694
Conversation
…ject_statuses table since it isn't read by users
…nding with ecapris id instead
✅ Deploy Preview for atd-moped-main ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
This is cleanup from the eCAPRIS statuses work. We don't select directly from this table. eCAPRIS statuses are selected through the combined_project_notes_view so we don't use these permissions.
| ADD COLUMN is_legacy_funding_record BOOLEAN DEFAULT FALSE, | ||
| ADD COLUMN is_editable BOOLEAN GENERATED ALWAYS AS (ecapris_funding_id IS NULL) STORED, |
There was a problem hiding this comment.
These two columns intend to:
is_legacy_funding_recordwill be used to track before/after state of funding records since we are changing the upstream data source for eCAPRIS information when this new feature launchesis_editablewill be used in frontend code to determine when to show the edit UI or not (eCAPRIS synced or imported records should use eCAPRIS numbers as the source of truth and any need to modify the funding in a project should be covered by manually entering data in the funding DataGrid table)
But, I am looking for feedback on them. Using a generated column to provide the UI code with information about whether or not to allow editing made sense to me, but I am open to other ideas if this doesn't seem like it will be clear in the future.
There was a problem hiding this comment.
I'm following the logic in your design here, and I think your choice with the generated column is better than the alternative of putting the logic controlling editing in the front-end application. This feels self-documenting and explicit, and has zero performance cost, so 👍 in my book.
There was a problem hiding this comment.
yeah i agree w frank, i think the generated column is good!
There was a problem hiding this comment.
I agree — this looks very good. One alternative would be to store the ecapris funding records in a separate but similar table, following the pattern of the ecapris project statuses. That might be a cleaner way to do it if the ecapris records are truly intended to be read-only, because you can clamp the edit permissions down on them. Again, what you have looks very good and I don't know the full picture of where this feature is headed.
There was a problem hiding this comment.
thanks, y'all! I'm taking another look at the schema today. On Friday, I made progress on an ETL that populates synced records in the moped_proj_funding, and I am now concerned that having the ETL and users operating on the same table could create issues down the line - particularly the is_deleted status of rows becoming de-synced.
Today, I am going to test a separate table for the synced records so we handle the three sources of funding info like:
- Manually created funding records stored in
moped_proj_funding(just like today) - Imported records from eCAPRIS data source stored in
moped_proj_funding(just like today but we also have the unique fao_id to tie back to eCAPRIS if ever needed) This also covers the need to override eCAPRIS amounts if an FDU is split between multiple Moped projects which was a new need that came up in the last MUG meeting. - Synced records stored in separate table (like eCAPRIS subproject statuses). This is the only table that the ETL would operate on and would provide un-editable eCAPRIS data.
| ADD COLUMN ecapris_funding_id INTEGER, | ||
| ADD COLUMN is_legacy_funding_record BOOLEAN DEFAULT FALSE, | ||
| ADD COLUMN is_editable BOOLEAN GENERATED ALWAYS AS (ecapris_funding_id IS NULL) STORED, | ||
| ADD COLUMN fdu TEXT DEFAULT NULL, |
There was a problem hiding this comment.
We currently have a generated column called fund_dept_unit that pulls the F and DU parts out of fund and dept_unit jsonb columns, but this new fdu column will store the FDU string that we can tie back to eCAPRIS by the unique ecapris_funding_id.
| UPDATE moped_proj_funding | ||
| SET | ||
| fdu = fund_dept_unit, | ||
| unit_long_name = (dept_unit ->> 'unit_long_name') | ||
| WHERE fund_dept_unit IS NOT NULL; |
There was a problem hiding this comment.
This last part is important to carry over existing data captured from the Socrata jega-nqf6 and bgrt-2m2z datasets into the new schema that can be tied back to eCAPRIS by an id.
Last in this migration, we need to update the database view that powers some Power BI dashboards to use our new FDU column instead of the generated one that stitched data from the fund and dept_unit columns together.
Create ETL to sync FDUs from eCAPRIS EDP dataset to Moped DB
Associated issues
Closes cityofaustin/atd-data-tech#24593
This PR updates the
moped_proj_fundingschema to enable syncing eCAPRIS funding information on projects linked to a eCAPRIS subproject. It also adds columns to the project funding table that will help us differentiate records created in Moped and records created from eCAPRIS data which we can't currently do. There is also a new column that will be important for tracking records that were created prior to the new funding enhancements.Testing
URL to test:
Local please 🙏
Steps to test:
For this test, we will be updating the following project that is linked to the following eCAPRIS id:
is_legacy_funding_recordset to false while the rest that were created using our current (legacy) UI have it set to trueis_editableshould also be false for any record that hasecapris_funding_idsince synced and imported records will be updated by the ETL. The MVP will not enable overrides.fduandunit_long_namecolumns populatedproject_funding_viewdatabase view which is available in the Power BI data flow and selects frommoped_proj_fundingand joins in lookup values.Ship list