-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Issue #1977] Adjust transformation logic to handle orphaned history …
…records (#1982) ## Summary Fixes #1977 ### Time to review: __10 mins__ ## Changes proposed Handle orphaned history records when the opportunity (and consequently) opportunity summary objects do not exist Add a `transformation_notes` column for us to put whatever info regarding the transformation into - in this case marking that we skipped a record for a particular reason. ## Context for reviewers A record in the `tsynopsis_hist` or `tforecast_hist` table connects with an opportunity, however that opportunity may not be in the `topportunity` table as it was deleted, and its record only remains in the `topportunity_hist` table - a table we aren't yet importing. Because of this, we can't actually import these records. While we may want to import the historical opportunities, we're not going to do that at this time, instead we'll mark these records as processed For the three sets of one-to-many lookup tables, we also need to add a check because if we couldn't import the historical synopsis/forecast into our `opportunity_summary` table - it'll also cause those to fail. Important detail - historical data isn't technically required right now, and as far as I can tell this _should_ only apply to deleted opportunities (something that wouldn't ever be visible in our next few features) ## Additional information Testing this with a snapshot of prod data, I was able to run through the full dataset locally and get the following metrics ``` total_records_processed=1484400 total_records_deleted=0 total_records_inserted=1338467 total_records_updated=0 total_records_orphaned=2305 total_duplicate_records_skipped=977 total_historical_orphans_skipped=142650 total_error_count=1 task_duration_sec=615.295 app.name=src.app ``` Note that the error is unrelated to this work and will be addressed separately (boolean with an invalid value) --------- Co-authored-by: nava-platform-bot <platform-admins@navapbc.com>
- Loading branch information
1 parent
9e843a5
commit aa4d15f
Showing
10 changed files
with
434 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
api/src/db/migrations/versions/2024_05_09_add_transformation_notes_to_staging_.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
"""add transformation notes to staging tables | ||
Revision ID: 61c58638e56b | ||
Revises: f97987d087b5 | ||
Create Date: 2024-05-09 15:06:48.010975 | ||
""" | ||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "61c58638e56b" | ||
down_revision = "f97987d087b5" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.add_column( | ||
"tapplicanttypes_forecast", | ||
sa.Column("transformation_notes", sa.Text(), nullable=True), | ||
schema="staging", | ||
) | ||
op.add_column( | ||
"tapplicanttypes_forecast_hist", | ||
sa.Column("transformation_notes", sa.Text(), nullable=True), | ||
schema="staging", | ||
) | ||
op.add_column( | ||
"tapplicanttypes_synopsis", | ||
sa.Column("transformation_notes", sa.Text(), nullable=True), | ||
schema="staging", | ||
) | ||
op.add_column( | ||
"tapplicanttypes_synopsis_hist", | ||
sa.Column("transformation_notes", sa.Text(), nullable=True), | ||
schema="staging", | ||
) | ||
op.add_column( | ||
"tforecast", sa.Column("transformation_notes", sa.Text(), nullable=True), schema="staging" | ||
) | ||
op.add_column( | ||
"tforecast_hist", | ||
sa.Column("transformation_notes", sa.Text(), nullable=True), | ||
schema="staging", | ||
) | ||
op.add_column( | ||
"tfundactcat_forecast", | ||
sa.Column("transformation_notes", sa.Text(), nullable=True), | ||
schema="staging", | ||
) | ||
op.add_column( | ||
"tfundactcat_forecast_hist", | ||
sa.Column("transformation_notes", sa.Text(), nullable=True), | ||
schema="staging", | ||
) | ||
op.add_column( | ||
"tfundactcat_synopsis", | ||
sa.Column("transformation_notes", sa.Text(), nullable=True), | ||
schema="staging", | ||
) | ||
op.add_column( | ||
"tfundactcat_synopsis_hist", | ||
sa.Column("transformation_notes", sa.Text(), nullable=True), | ||
schema="staging", | ||
) | ||
op.add_column( | ||
"tfundinstr_forecast", | ||
sa.Column("transformation_notes", sa.Text(), nullable=True), | ||
schema="staging", | ||
) | ||
op.add_column( | ||
"tfundinstr_forecast_hist", | ||
sa.Column("transformation_notes", sa.Text(), nullable=True), | ||
schema="staging", | ||
) | ||
op.add_column( | ||
"tfundinstr_synopsis", | ||
sa.Column("transformation_notes", sa.Text(), nullable=True), | ||
schema="staging", | ||
) | ||
op.add_column( | ||
"tfundinstr_synopsis_hist", | ||
sa.Column("transformation_notes", sa.Text(), nullable=True), | ||
schema="staging", | ||
) | ||
op.add_column( | ||
"topportunity", | ||
sa.Column("transformation_notes", sa.Text(), nullable=True), | ||
schema="staging", | ||
) | ||
op.add_column( | ||
"topportunity_cfda", | ||
sa.Column("transformation_notes", sa.Text(), nullable=True), | ||
schema="staging", | ||
) | ||
op.add_column( | ||
"tsynopsis", sa.Column("transformation_notes", sa.Text(), nullable=True), schema="staging" | ||
) | ||
op.add_column( | ||
"tsynopsis_hist", | ||
sa.Column("transformation_notes", sa.Text(), nullable=True), | ||
schema="staging", | ||
) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_column("tsynopsis_hist", "transformation_notes", schema="staging") | ||
op.drop_column("tsynopsis", "transformation_notes", schema="staging") | ||
op.drop_column("topportunity_cfda", "transformation_notes", schema="staging") | ||
op.drop_column("topportunity", "transformation_notes", schema="staging") | ||
op.drop_column("tfundinstr_synopsis_hist", "transformation_notes", schema="staging") | ||
op.drop_column("tfundinstr_synopsis", "transformation_notes", schema="staging") | ||
op.drop_column("tfundinstr_forecast_hist", "transformation_notes", schema="staging") | ||
op.drop_column("tfundinstr_forecast", "transformation_notes", schema="staging") | ||
op.drop_column("tfundactcat_synopsis_hist", "transformation_notes", schema="staging") | ||
op.drop_column("tfundactcat_synopsis", "transformation_notes", schema="staging") | ||
op.drop_column("tfundactcat_forecast_hist", "transformation_notes", schema="staging") | ||
op.drop_column("tfundactcat_forecast", "transformation_notes", schema="staging") | ||
op.drop_column("tforecast_hist", "transformation_notes", schema="staging") | ||
op.drop_column("tforecast", "transformation_notes", schema="staging") | ||
op.drop_column("tapplicanttypes_synopsis_hist", "transformation_notes", schema="staging") | ||
op.drop_column("tapplicanttypes_synopsis", "transformation_notes", schema="staging") | ||
op.drop_column("tapplicanttypes_forecast_hist", "transformation_notes", schema="staging") | ||
op.drop_column("tapplicanttypes_forecast", "transformation_notes", schema="staging") | ||
# ### end Alembic commands ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,3 +72,5 @@ class StagingParamMixin: | |
default=None, | ||
server_default=None, | ||
) | ||
|
||
transformation_notes: Mapped[str | None] |
Oops, something went wrong.