Skip to content

Conversation

@MasakiMu319
Copy link

Link to Issue or Description of Change

  • Closes: N/A
  • Related: N/A

Problem:

In production, leaving Alembic unconstrained is extremely dangerous—autogenerated migrations could drop or alter unrelated business tables. The migration script also left stale alembic_version state and did not scope tables to ADK session metadata.

Solution:

Constrain Alembic to ADK session tables via targeted metadata and an include_object filter, using a dedicated alembic_version_adk as alembic version table. Rewrite the migration script to emit this safe env.py, clean backups, and reset any old version table before autogeneration—here we only need the DB tables to align with the latest Base metadata—keeping migrations isolated and idempotent.

Testing Plan

  • Unit Tests: Not run (no code-level changes).
  • Manual Verification: Ran the migration flow locally and confirmed the Alembic version table matched expectations.

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my changes.
  • I have commented my code, particularly in hard-to-understand areas.

@google-cla
Copy link

google-cla bot commented Nov 22, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @MasakiMu319, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly improves the safety and isolation of database migrations for ADK session tables. It addresses critical production concerns by ensuring that Alembic only interacts with its intended schema objects and by providing a robust, idempotent migration script. The changes prevent accidental data loss or schema corruption by strictly scoping migration operations and cleaning up previous states, thereby enhancing the overall stability and predictability of database updates.

Highlights

  • Constrained Alembic Migrations: Alembic migrations are now strictly constrained to only operate on tables defined within the ADK session metadata. This is achieved by introducing TARGET_METADATAS and an include_object filter in env.py, preventing unintended modifications to unrelated database tables.
  • Dedicated Alembic Version Table: The migration process now uses a dedicated version table named alembic_version_adk instead of the default alembic_version. This isolates ADK session migrations and prevents conflicts or confusion with other potential migration systems.
  • Enhanced Migration Script Robustness: The db_migration.sh script has been significantly refactored to dynamically generate a safe env.py file, ensure proper cleanup of backup files, and proactively reset the alembic_version_adk table before autogenerating migrations. This makes the migration process more idempotent and reliable.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@adk-bot adk-bot added the tools [Component] This issue is related to tools label Nov 22, 2025
@adk-bot
Copy link
Collaborator

adk-bot commented Nov 22, 2025

Response from ADK Triaging Agent

Hello @MasakiMu319, thank you for creating this PR!

This PR is a bug fix, could you please associate a GitHub issue with this PR? If there is no existing issue, could you please create one?

In addition, could you please provide logs or a screenshot after the fix is applied?

This information will help reviewers to review your PR more efficiently. Thanks!

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request significantly improves the safety and reliability of the database migration script. By constraining Alembic's scope to specific tables using include_object and a dedicated version table, it effectively prevents accidental changes to unrelated business tables. The move from using sed to a cat heredoc to generate the env.py file is a much more robust and maintainable approach. Additionally, resetting the version table ensures the script is idempotent. I have a couple of suggestions to further improve the generated Python code for better adherence to best practices.

@ryanaiagent ryanaiagent self-assigned this Nov 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tools [Component] This issue is related to tools

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants