-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…s to staging tables (#1894) ## Summary Part of #1686 (separate for easier review) ### Time to review: __2 mins__ ## Changes proposed - Add `created_at`, `updated_at`, and `deleted_at` columns to staging tables - Better logging of migrate queries ## Context for reviewers These columns will provide helpful metadata for understanding or troubleshooting the load process. The `created_at` and `updated_at` columns are set automatically by SQLAlchemy. For `deleted_at`, I will update #1852 after this is merged. ## Additional information Example from local testing: 
- Loading branch information
1 parent
7f65c79
commit 355f9d3
Showing
6 changed files
with
138 additions
and
0 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
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
73 changes: 73 additions & 0 deletions
73
api/src/db/migrations/versions/2024_05_01_add_created_at_updated_at_and_deleted_.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,73 @@ | ||
"""Add created_at, updated_at, and deleted_at columns to staging tables | ||
Revision ID: 1ddd1d051a99 | ||
Revises: e3a1be603d26 | ||
Create Date: 2024-05-01 11:14:34.332661 | ||
""" | ||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "1ddd1d051a99" | ||
down_revision = "e3a1be603d26" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
TABLES = ( | ||
"tapplicanttypes_forecast", | ||
"tapplicanttypes_forecast_hist", | ||
"tapplicanttypes_synopsis", | ||
"tapplicanttypes_synopsis_hist", | ||
"tforecast", | ||
"tforecast_hist", | ||
"tfundactcat_forecast", | ||
"tfundactcat_forecast_hist", | ||
"tfundactcat_synopsis", | ||
"tfundactcat_synopsis_hist", | ||
"tfundinstr_forecast", | ||
"tfundinstr_forecast_hist", | ||
"tfundinstr_synopsis", | ||
"tfundinstr_synopsis_hist", | ||
"topportunity", | ||
"topportunity_cfda", | ||
"tsynopsis", | ||
"tsynopsis_hist", | ||
) | ||
|
||
|
||
def upgrade(): | ||
for table_name in TABLES: | ||
op.add_column( | ||
table_name, | ||
sa.Column( | ||
"created_at", | ||
sa.TIMESTAMP(timezone=True), | ||
server_default=sa.text("now()"), | ||
nullable=False, | ||
), | ||
schema="staging", | ||
) | ||
op.add_column( | ||
table_name, | ||
sa.Column( | ||
"updated_at", | ||
sa.TIMESTAMP(timezone=True), | ||
server_default=sa.text("now()"), | ||
nullable=False, | ||
), | ||
schema="staging", | ||
) | ||
op.add_column( | ||
table_name, | ||
sa.Column("deleted_at", sa.TIMESTAMP(timezone=True), nullable=True), | ||
schema="staging", | ||
) | ||
|
||
|
||
def downgrade(): | ||
for table_name in TABLES: | ||
op.drop_column(table_name, "deleted_at", schema="staging") | ||
op.drop_column(table_name, "updated_at", schema="staging") | ||
op.drop_column(table_name, "created_at", schema="staging") |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.