Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

[Issue #125] Setup agency tables for transformation #127

Merged
merged 60 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
71e6cf2
WIP
chouinar Apr 18, 2024
cfc8076
WIP
chouinar Apr 18, 2024
65d9785
Merge branch 'main' into chouinar/1745-setup-transformations
chouinar Apr 19, 2024
6ccd8e6
More organization
chouinar Apr 19, 2024
345e65e
Merge branch 'main' into chouinar/1745-setup-transformations
chouinar Apr 19, 2024
3741df5
Adding more implementation
chouinar Apr 22, 2024
afb077b
Merge branch 'main' into chouinar/1745-setup-transformations
chouinar Apr 23, 2024
2520062
Cleanup, still a WIP
chouinar Apr 23, 2024
5d4639e
adding a comment
chouinar Apr 24, 2024
9dbbc1c
Merge branch 'main' into chouinar/1745-setup-transformations
chouinar Apr 26, 2024
44abd4f
Switching to the staging tables
chouinar Apr 26, 2024
703672e
WIP
chouinar Apr 26, 2024
68f3968
Merge branch 'main' into chouinar/1745-setup-transformations
chouinar Apr 26, 2024
b5e1ebe
WIP
chouinar Apr 26, 2024
94032b2
Merge branch 'main' into chouinar/1745-setup-transformations
chouinar Apr 26, 2024
38ad477
Final tests and cleanup
chouinar Apr 29, 2024
e1dfff0
Minor adjustment
chouinar Apr 29, 2024
fda6a89
Merge branch 'main' into chouinar/1745-setup-transformations
chouinar Apr 29, 2024
54774fd
[Issue #1746] Add transformations for assistance listing table
chouinar Apr 29, 2024
7954c59
trim
chouinar Apr 29, 2024
fce4caf
Adding more tests, cleanup, fixing warnings
chouinar Apr 30, 2024
588ec11
[Issue #1747] Add transformations for the opportunity summary table
chouinar May 1, 2024
fcf16ca
Adding a lot of implementation
chouinar May 2, 2024
f81f891
More tests and cleanup
chouinar May 2, 2024
f73b97f
WIP
chouinar May 2, 2024
2e00840
Merge branch 'main' into chouinar/1747-opportunity-summary-transform
chouinar May 3, 2024
a60d72e
Cleanup
chouinar May 3, 2024
52e2534
Adding a few final tests
chouinar May 3, 2024
4bba72b
remove extra code
chouinar May 3, 2024
fdb33c4
remove unused bit
chouinar May 3, 2024
c2f2966
[Issue #1749] Add transformations for the one-to-many lookup tables
chouinar May 7, 2024
2ee74db
Merge branch 'main' into chouinar/1749-one-to-many
chouinar May 7, 2024
14e09ac
WIP
chouinar May 7, 2024
ee5ab99
Cleanup and final tests
chouinar May 7, 2024
b114774
Minor adjustment
chouinar May 7, 2024
870189e
A few final fixes
chouinar May 7, 2024
9e958a2
Merge branch 'main' into chouinar/1749-one-to-many
chouinar May 7, 2024
979fc7a
Fix issues regarding transforms of one-to-many tables, cleanup
chouinar May 9, 2024
c1a7426
Adjust nesting structure of if-statements
chouinar May 9, 2024
0e90364
Merge branch 'main' into chouinar/1749-one-to-many
chouinar May 9, 2024
20abd51
[Issue #1977] Adjust transformation logic to handle orphaned history …
chouinar May 10, 2024
8b67199
Merge branch 'main' into chouinar/1977-transform-hist-fix
chouinar May 10, 2024
e49fdf4
Update database ERD diagrams
nava-platform-bot May 10, 2024
b9a2059
Merge branch 'main' into chouinar/1977-transform-hist-fix
chouinar May 13, 2024
5cf45f5
[Issue #1983] Adjust transformation deletes to handle cascading deletes
chouinar May 13, 2024
a674cb9
Merge branch 'main' into chouinar/1983-cascade-deletes
chouinar May 13, 2024
1192b23
spacing
chouinar May 13, 2024
5e2f0ff
Merge branch 'main' into chouinar/1983-cascade-deletes
chouinar Jun 25, 2024
fe95c67
[Issue #104] Refactor/restructure the transformation code
chouinar Jun 27, 2024
8ffcc6a
Removing a few more things that aren't needed anymore
chouinar Jun 27, 2024
1bf2814
[Issue #125] Setup agency tables for transformation
chouinar Jun 28, 2024
b004466
Update erd diagrams
chouinar Jun 28, 2024
11586ea
Merge branch 'main' into chouinar/104-cleanup-transformations
chouinar Jul 8, 2024
819e629
Merge branch 'chouinar/104-cleanup-transformations' into chouinar/125…
chouinar Jul 8, 2024
1648b09
Cleanup
chouinar Jul 8, 2024
a21f46d
Merge branch 'main' into chouinar/104-cleanup-transformations
chouinar Jul 29, 2024
27a79d9
Merge branch 'chouinar/104-cleanup-transformations' into chouinar/125…
chouinar Jul 29, 2024
880dfd2
Update database ERD diagrams
nava-platform-bot Jul 29, 2024
3a7a128
Merge branch 'main' into chouinar/125-agency-table
chouinar Aug 2, 2024
9fe7ba4
Merge branch 'main' into chouinar/125-agency-table
chouinar Sep 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions api/bin/create_erds.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import src.db.models.staging.opportunity as staging_opportunity_models
import src.db.models.staging.synopsis as staging_synopsis_models
import src.logging
from src.db.models import opportunity_models
from src.db.models import agency_models, opportunity_models
from src.db.models.transfer import topportunity_models

logger = logging.getLogger(__name__)
Expand All @@ -23,7 +23,10 @@
ERD_FOLDER = pathlib.Path(__file__).parent.resolve()

# If we want to generate separate files for more specific groups, we can set that up here
API_MODULES = (opportunity_models,)
API_MODULES = (
opportunity_models,
agency_models,
)
STAGING_TABLE_MODULES = (
staging_opportunity_models,
staging_forecast_models,
Expand Down
11 changes: 11 additions & 0 deletions api/src/constants/lookup_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,14 @@ class FundingInstrument(StrEnum):
GRANT = "grant" # G
PROCUREMENT_CONTRACT = "procurement_contract" # PC
OTHER = "other" # O


class AgencyDownloadFileType(StrEnum):
XML = "xml"
PDF = "pdf"


class AgencySubmissionNotificationSetting(StrEnum):
NEVER = "never"
FIRST_APPLICATION_ONLY = "first_application_only"
ALWAYS = "always"
4 changes: 2 additions & 2 deletions api/src/db/foreign/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# SQLAlchemy models for foreign tables.
#

from . import forecast, foreignbase, opportunity, synopsis
from . import forecast, foreignbase, opportunity, synopsis, tgroups

metadata = foreignbase.metadata

__all__ = ["metadata", "forecast", "opportunity", "synopsis"]
__all__ = ["metadata", "forecast", "opportunity", "synopsis", "tgroups"]
14 changes: 14 additions & 0 deletions api/src/db/foreign/tgroups.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#
# SQLAlchemy models for foreign tables.
#
# The order of the columns must match the remote Oracle database. The names are not required to
# match by oracle_fdw, but we are matching them for maintainability.
#

from src.db.legacy_mixin import tgroups_mixin

from . import foreignbase


class Tgroups(foreignbase.ForeignBase, tgroups_mixin.TGroupsMixin):
__tablename__ = "tgroups"
20 changes: 20 additions & 0 deletions api/src/db/legacy_mixin/tgroups_mixin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#
# SQLAlchemy models for foreign tables.
#
# The order of the columns must match the remote Oracle database. The names are not required to
# match by oracle_fdw, but we are matching them for maintainability.
#

import datetime

from sqlalchemy.orm import Mapped, declarative_mixin, mapped_column


@declarative_mixin
class TGroupsMixin:
keyfield: Mapped[str] = mapped_column(primary_key=True)
value: Mapped[str | None]
created_date: Mapped[datetime.datetime | None]
last_upd_date: Mapped[datetime.datetime | None]
creator_id: Mapped[str | None]
last_upd_id: Mapped[str | None]
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
"""Add agency related tables

Revision ID: 4f7acbb61548
Revises: 61c58638e56b
Create Date: 2024-07-08 12:43:45.240782

"""
import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "4f7acbb61548"
down_revision = "61c58638e56b"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table(
"agency_contact_info",
sa.Column("agency_contact_info_id", sa.BigInteger(), nullable=False),
sa.Column("contact_name", sa.Text(), nullable=False),
sa.Column("address_line_1", sa.Text(), nullable=False),
sa.Column("address_line_2", sa.Text(), nullable=True),
sa.Column("city", sa.Text(), nullable=False),
sa.Column("state", sa.Text(), nullable=False),
sa.Column("zip_code", sa.Text(), nullable=False),
sa.Column("phone_number", sa.Text(), nullable=False),
sa.Column("primary_email", sa.Text(), nullable=False),
sa.Column("secondary_email", sa.Text(), nullable=True),
sa.Column(
"created_at",
sa.TIMESTAMP(timezone=True),
server_default=sa.text("now()"),
nullable=False,
),
sa.Column(
"updated_at",
sa.TIMESTAMP(timezone=True),
server_default=sa.text("now()"),
nullable=False,
),
sa.PrimaryKeyConstraint("agency_contact_info_id", name=op.f("agency_contact_info_pkey")),
schema="api",
)
op.create_table(
"lk_agency_download_file_type",
sa.Column("agency_download_file_type_id", sa.Integer(), nullable=False),
sa.Column("description", sa.Text(), nullable=False),
sa.Column(
"created_at",
sa.TIMESTAMP(timezone=True),
server_default=sa.text("now()"),
nullable=False,
),
sa.Column(
"updated_at",
sa.TIMESTAMP(timezone=True),
server_default=sa.text("now()"),
nullable=False,
),
sa.PrimaryKeyConstraint(
"agency_download_file_type_id", name=op.f("lk_agency_download_file_type_pkey")
),
schema="api",
)
op.create_table(
"lk_agency_submission_notification_setting",
sa.Column("agency_submission_notification_setting_id", sa.Integer(), nullable=False),
sa.Column("description", sa.Text(), nullable=False),
sa.Column(
"created_at",
sa.TIMESTAMP(timezone=True),
server_default=sa.text("now()"),
nullable=False,
),
sa.Column(
"updated_at",
sa.TIMESTAMP(timezone=True),
server_default=sa.text("now()"),
nullable=False,
),
sa.PrimaryKeyConstraint(
"agency_submission_notification_setting_id",
name=op.f("lk_agency_submission_notification_setting_pkey"),
),
schema="api",
)
op.create_table(
"agency",
sa.Column("agency_id", sa.BigInteger(), nullable=False),
sa.Column("agency_name", sa.Text(), nullable=False),
sa.Column("agency_code", sa.Text(), nullable=False),
sa.Column("sub_agency_code", sa.Text(), nullable=True),
sa.Column("assistance_listing_number", sa.Text(), nullable=False),
sa.Column("agency_submission_notification_setting_id", sa.Integer(), nullable=False),
sa.Column("agency_contact_info_id", sa.BigInteger(), nullable=True),
sa.Column("is_test_agency", sa.Boolean(), nullable=False),
sa.Column("ldap_group", sa.Text(), nullable=False),
sa.Column("description", sa.Text(), nullable=False),
sa.Column("label", sa.Text(), nullable=False),
sa.Column("is_multilevel_agency", sa.Boolean(), nullable=False),
sa.Column("is_multiproject", sa.Boolean(), nullable=False),
sa.Column("has_system_to_system_certificate", sa.Boolean(), nullable=False),
sa.Column("can_view_packages_in_grace_period", sa.Boolean(), nullable=False),
sa.Column("is_image_workspace_enabled", sa.Boolean(), nullable=False),
sa.Column("is_validation_workspace_enabled", sa.Boolean(), nullable=False),
sa.Column(
"created_at",
sa.TIMESTAMP(timezone=True),
server_default=sa.text("now()"),
nullable=False,
),
sa.Column(
"updated_at",
sa.TIMESTAMP(timezone=True),
server_default=sa.text("now()"),
nullable=False,
),
sa.ForeignKeyConstraint(
["agency_contact_info_id"],
["api.agency_contact_info.agency_contact_info_id"],
name=op.f("agency_agency_contact_info_id_agency_contact_info_fkey"),
),
sa.ForeignKeyConstraint(
["agency_submission_notification_setting_id"],
[
"api.lk_agency_submission_notification_setting.agency_submission_notification_setting_id"
],
name=op.f(
"agency_agency_submission_notification_setting_id_lk_agency_submission_notification_setting_fkey"
),
),
sa.PrimaryKeyConstraint("agency_id", name=op.f("agency_pkey")),
schema="api",
)
op.create_index(
op.f("agency_agency_code_idx"), "agency", ["agency_code"], unique=True, schema="api"
)
op.create_table(
"link_agency_download_file_type",
sa.Column("agency_id", sa.BigInteger(), nullable=False),
sa.Column("agency_download_file_type_id", sa.Integer(), nullable=False),
sa.Column(
"created_at",
sa.TIMESTAMP(timezone=True),
server_default=sa.text("now()"),
nullable=False,
),
sa.Column(
"updated_at",
sa.TIMESTAMP(timezone=True),
server_default=sa.text("now()"),
nullable=False,
),
sa.ForeignKeyConstraint(
["agency_download_file_type_id"],
["api.lk_agency_download_file_type.agency_download_file_type_id"],
name=op.f(
"link_agency_download_file_type_agency_download_file_type_id_lk_agency_download_file_type_fkey"
),
),
sa.ForeignKeyConstraint(
["agency_id"],
["api.agency.agency_id"],
name=op.f("link_agency_download_file_type_agency_id_agency_fkey"),
),
sa.PrimaryKeyConstraint(
"agency_id",
"agency_download_file_type_id",
name=op.f("link_agency_download_file_type_pkey"),
),
schema="api",
)
op.create_table(
"tgroups",
sa.Column("keyfield", sa.Text(), nullable=False),
sa.Column("value", sa.Text(), nullable=True),
sa.Column("created_date", sa.TIMESTAMP(timezone=True), nullable=True),
sa.Column("last_upd_date", sa.TIMESTAMP(timezone=True), nullable=True),
sa.Column("creator_id", sa.Text(), nullable=True),
sa.Column("last_upd_id", sa.Text(), nullable=True),
sa.Column("is_deleted", sa.Boolean(), nullable=False),
sa.Column("transformed_at", sa.TIMESTAMP(timezone=True), nullable=True),
sa.Column(
"created_at",
sa.TIMESTAMP(timezone=True),
server_default=sa.text("now()"),
nullable=False,
),
sa.Column(
"updated_at",
sa.TIMESTAMP(timezone=True),
server_default=sa.text("now()"),
nullable=False,
),
sa.Column("deleted_at", sa.TIMESTAMP(timezone=True), nullable=True),
sa.Column("transformation_notes", sa.Text(), nullable=True),
sa.PrimaryKeyConstraint("keyfield", name=op.f("tgroups_pkey")),
schema="staging",
)
op.create_index(
op.f("tgroups_transformed_at_idx"),
"tgroups",
["transformed_at"],
unique=False,
schema="staging",
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f("tgroups_transformed_at_idx"), table_name="tgroups", schema="staging")
op.drop_table("tgroups", schema="staging")
op.drop_table("link_agency_download_file_type", schema="api")
op.drop_index(op.f("agency_agency_code_idx"), table_name="agency", schema="api")
op.drop_table("agency", schema="api")
op.drop_table("lk_agency_submission_notification_setting", schema="api")
op.drop_table("lk_agency_download_file_type", schema="api")
op.drop_table("agency_contact_info", schema="api")
# ### end Alembic commands ###
10 changes: 8 additions & 2 deletions api/src/db/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging

from . import base, lookup_models, opportunity_models
from . import agency_models, base, lookup_models, opportunity_models
from .transfer import topportunity_models

logger = logging.getLogger(__name__)
Expand All @@ -9,4 +9,10 @@
# This is used by tests to create the test database.
metadata = base.metadata

__all__ = ["metadata", "opportunity_models", "lookup_models", "topportunity_models"]
__all__ = [
"metadata",
"opportunity_models",
"lookup_models",
"topportunity_models",
"agency_models",
]
Loading
Loading