Skip to content

Commit

Permalink
[2216] setup staging foreign tables (#3313)
Browse files Browse the repository at this point in the history
## Summary
Fixes #{[2216](#2216)}

### Time to review: __5 mins__

## Changes proposed
Mixin, Staging and Foreign attachment models created 
Migration file created

## Context for reviewers
Run migration. new table should be created in staging schema

---------

Co-authored-by: nava-platform-bot <[email protected]>
  • Loading branch information
babebe and nava-platform-bot authored Dec 19, 2024
1 parent e72c729 commit 2fbc3d8
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
"""add_attachment_table_staging_and_foreign
Revision ID: f8058a6c0a66
Revises: 6a23520d2c3c
Create Date: 2024-12-19 19:27:50.327943
"""

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "f8058a6c0a66"
down_revision = "6a23520d2c3c"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table(
"tsynopsisattachment",
sa.Column("syn_att_id", sa.BigInteger(), nullable=False),
sa.Column("opportunity_id", sa.BigInteger(), nullable=False),
sa.Column("att_revision_number", sa.BigInteger(), nullable=True),
sa.Column("att_type", sa.Text(), nullable=True),
sa.Column("mime_type", sa.Text(), nullable=True),
sa.Column("link_url", sa.Text(), nullable=True),
sa.Column("file_name", sa.Text(), nullable=True),
sa.Column("file_desc", sa.Text(), nullable=True),
sa.Column("file_lob", sa.LargeBinary(), nullable=True),
sa.Column("file_lob_size", sa.BigInteger(), nullable=True),
sa.Column("create_date", sa.TIMESTAMP(timezone=True), 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("syn_att_folder_id", sa.BigInteger(), 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("syn_att_id", name=op.f("tsynopsisattachment_pkey")),
schema="staging",
)
op.create_index(
op.f("tsynopsisattachment_transformed_at_idx"),
"tsynopsisattachment",
["transformed_at"],
unique=False,
schema="staging",
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(
op.f("tsynopsisattachment_transformed_at_idx"),
table_name="tsynopsisattachment",
schema="staging",
)
op.drop_table("tsynopsisattachment", schema="staging")
# ### end Alembic commands ###
4 changes: 2 additions & 2 deletions api/src/db/models/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, tgroups
from . import attachment, forecast, foreignbase, opportunity, synopsis, tgroups

metadata = foreignbase.metadata

__all__ = ["metadata", "forecast", "opportunity", "synopsis", "tgroups"]
__all__ = ["metadata", "forecast", "opportunity", "synopsis", "tgroups", "attachment"]
14 changes: 14 additions & 0 deletions api/src/db/models/foreign/attachment.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.models.legacy_mixin import synopsis_mixin

from . import foreignbase


class tsynopsisattachment(foreignbase.ForeignBase, synopsis_mixin.TsynopsisAttachmentMixin):
__tablename__ = "tsynopsisattachment"
19 changes: 19 additions & 0 deletions api/src/db/models/legacy_mixin/synopsis_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,22 @@ class TfundinstrSynopsisHistMixin:
last_upd_date: Mapped[datetime.datetime | None]
creator_id: Mapped[str | None]
last_upd_id: Mapped[str | None]


class TsynopsisAttachmentMixin:
syn_att_id: Mapped[int] = mapped_column(primary_key=True)
opportunity_id: Mapped[int]
att_revision_number: Mapped[int | None]
att_type: Mapped[str | None]
mime_type: Mapped[str | None]
link_url: Mapped[str | None]
file_name: Mapped[str | None]
file_desc: Mapped[str | None]
file_lob: Mapped[bytes | None]
file_lob_size: Mapped[int | None]
create_date: Mapped[datetime.datetime | 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]
syn_att_folder_id: Mapped[int | None]
4 changes: 2 additions & 2 deletions api/src/db/models/staging/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from . import forecast, opportunity, staging_base, synopsis, tgroups
from . import attachment, forecast, opportunity, staging_base, synopsis, tgroups

metadata = staging_base.metadata

__all__ = ["metadata", "opportunity", "forecast", "synopsis", "tgroups"]
__all__ = ["metadata", "opportunity", "forecast", "synopsis", "tgroups", "attachment"]
6 changes: 6 additions & 0 deletions api/src/db/models/staging/attachment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from src.db.models.legacy_mixin import synopsis_mixin
from src.db.models.staging.staging_base import StagingBase, StagingParamMixin


class TsynopsisAttachment(StagingBase, synopsis_mixin.TsynopsisAttachmentMixin, StagingParamMixin):
__tablename__ = "tsynopsisattachment"
Binary file modified documentation/api/database/erds/staging-schema.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2fbc3d8

Please sign in to comment.