Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Issue #1697] add more foreign table models and update setup_foreign_tables.py #1769

Merged
merged 15 commits into from
Apr 25, 2024

Conversation

jamesbursa
Copy link
Collaborator

Summary

Fixes #1697

Time to review: 10 mins

Changes proposed

  • Add src.db.foreign module defining the foreign tables as SQLAlchemy models.
  • Place the tables in a separate database schema.
  • Update setup_foreign_tables.py to use the new models instead of its own definition.
  • Update copy_oracle_data.py to use the new database schema.
  • Update unit tests.

Context for reviewers

Currently we only have one table from the source database available as a foreign table. This change adds the remaining tables, and also moves them into a separate schema.

Additional information

api/src/constants/schema.py Outdated Show resolved Hide resolved
@@ -55,19 +55,21 @@ def copy_oracle_data(db_session: db.Session) -> None:

try:
with db_session.begin():
_run_copy_commands(db_session, Schemas.API)
_run_copy_commands(db_session, Schemas.API, Schemas.FOREIGN)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want to make a new script - we don't want to break the v0 opportunity setup.

api/src/data_migration/setup_foreign_tables.py Outdated Show resolved Hide resolved
api/src/db/foreign/base.py Outdated Show resolved Hide resolved
@jamesbursa jamesbursa marked this pull request as ready for review April 24, 2024 17:10
chouinar
chouinar previously approved these changes Apr 24, 2024
Copy link
Collaborator

@chouinar chouinar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - just some linting issues

from . import foreignbase


class Tforecast(foreignbase.ForeignBase):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we name the classes Foreign... otherwise if we follow this pattern for the staging tables, we'll have two sets of classes with identical names which might be confusing / get imported incorrectly. I can also just aim to name the staging tables as StagingTopportunity and we leave these as-is.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depending how the staging code works, could it be useful to have the names match? Could imagine something like:

from src.db import foreign, staging

tables = (foreign.Tforecast, foreign.TforecastHist, ...)  # all 18 tables

for foreign_table in tables:
    staging_table = getattr(staging, foreign_table.__name__)
    do_staging_copy(foreign_table, staging_table, ...)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fair - might make configuring / maintaining the copy portion of the process simpler - just need to match up the modules.

class ForeignTableDDLCompiler(sqlalchemy.sql.compiler.DDLCompiler):
"""SQLAlchemy compiler for creating foreign tables."""

def create_table_constraints(self, _table, _include_foreign_key_constraints=None, **kw):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing type definitions on a few of these. FIne to just set them to Any if they're complex internal types to SQLAlchemy and not just str/bool or similar. A quick check of the base class, it doesn't look to type them inline, so not a lot to go on.

@github-actions github-actions bot added the ci/cd label Apr 25, 2024
Copy link
Collaborator

@chouinar chouinar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@jamesbursa jamesbursa merged commit 043ed8c into main Apr 25, 2024
10 checks passed
@jamesbursa jamesbursa deleted the jamesbursa/1697-foreign-tables branch April 25, 2024 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Task]: Add Foreign Tables in setup_foreign_tables.py for the new tables
2 participants