adk-python
adk-python copied to clipboard
fix(migration): constrain alembic targets and reset version state.
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
- [x] I have read the CONTRIBUTING.md document.
- [x] I have performed a self-review of my changes.
- [x] I have commented my code, particularly in hard-to-understand areas.
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.
Summary of Changes
Hello @MasakiMu319, I'm Gemini Code Assist[^1]! 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_METADATASand aninclude_objectfilter inenv.py, preventing unintended modifications to unrelated database tables. - Dedicated Alembic Version Table: The migration process now uses a dedicated version table named
alembic_version_adkinstead of the defaultalembic_version. This isolates ADK session migrations and prevents conflicts or confusion with other potential migration systems. - Enhanced Migration Script Robustness: The
db_migration.shscript has been significantly refactored to dynamically generate a safeenv.pyfile, ensure proper cleanup of backup files, and proactively reset thealembic_version_adktable 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 :thumbsup: and :thumbsdown: 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.
[^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.
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!
Hi @MasakiMu319 ,Thank you for your contribution! We appreciate you taking the time to submit this pull request. Before we can proceed with the review can you fix the lint errors.
Hi @MasakiMu319 ,Thank you for your contribution! We appreciate you taking the time to submit this pull request. Before we can proceed with the review can you fix the lint errors.
Already done.