Skip to content

feat(database): add support for table name prefixing for shared database compatibility #689

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

triangle-z
Copy link

Summary:
This PR addresses #688 by introducing automatic support for table name prefixing in SQLAlchemy models using a custom metaclass. All model __tablename__ values are now prefixed with "adk_".

Details:

  • Implement a custom DeclarativeMeta (PrefixerMeta) to prepend a prefix to all SQLAlchemy model table names.

  • Currently, the prefix is hardcoded as adk_. If you want, we can make it configurable by replacing:

    table_prefix = "adk_"

    with:

    table_prefix = os.getenv("DB_TABLE_PREFIX", "adk_")  # or os.getenv("DB_TABLE_PREFIX", "") if no default
  • Adjusted ForeignKeyConstraint definitions to dynamically reference StorageSession.__tablename__ instead of hardcoding "sessions".

Testing:

  • Verified against pytest with no regressions:

    • No new test failures
    • No added skips or warnings
    • All tests match results from the main branch (screenshots attached)
  • Below are the screenshots of test results:

This branch:
image

Main branch (baseline):
image

Please let me know your thoughts on this PR, I’m happy to iterate on this implementation or adapt it to better align with the project’s design principles.

@ankursharmas ankursharmas requested a review from DeanChensj May 13, 2025 01:12
@hangfei hangfei added bot_triaged tracing otel tracing issues labels Jun 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot_triaged tracing otel tracing issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants