-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Update migrate_session_db sample for ADK v1.20.0 #3867
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
base: main
Are you sure you want to change the base?
Conversation
Updated migration instructions to backup the previous database and use the old database for migration.
Summary of ChangesHello @ftnext, 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 updates the Highlights
Using Gemini Code AssistThe 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
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 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
|
|
Response from ADK Triaging Agent Hello @ftnext, thank you for creating this PR! To help us review this PR more efficiently, could you please associate a GitHub issue with it? If one doesn't exist, please create one that describes the problem this PR is solving. Additionally, could you please provide either logs or a screenshot demonstrating the fix, as mentioned in the "Testing Plan" section of our contribution guidelines? Thank you for your contribution! |
There was a problem hiding this 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 updates the migrate_session_db sample for ADK v1.20.0, which is a helpful change. The main update involves switching from DatabaseSessionService to SqliteSessionService and adjusting the database migration steps accordingly. The code changes in main.py are correct. I've provided one suggestion for the README.md file to improve the security and robustness of the shell commands provided for the migration process.
| cp dnd_sessions.db sessions.db.old | ||
|
|
||
| # Download and run the migration script | ||
| curl -fsSL https://raw.githubusercontent.com/google/adk-python/main/scripts/db_migration.sh | sh -s -- "sqlite:///%(here)s/sessions.db" "google.adk.sessions.database_session_service" | ||
| curl -fsSL https://raw.githubusercontent.com/google/adk-python/main/scripts/db_migration.sh | sh -s -- "sqlite:///%(here)s/sessions.db.old" "google.adk.sessions.database_session_service" | ||
|
|
||
| python -m google.adk.sessions.migrate_from_sqlalchemy_sqlite --source_db_path ./sessions.db.old --dest_db_path ./sessions.db | ||
| rm sessions.db.old |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The sequence of shell commands can be made more robust and secure.
- Security: Piping
curltoshexecutes remote code without inspection, which is a security risk. It's safer to download the script first, inspect it, and then execute it. - Robustness: The commands are not chained. If one command fails, the subsequent commands will still be executed. For example, if the
pythonmigration script fails,rm sessions.db.oldwill still run, deleting the backup database file which might be needed for debugging.
I suggest chaining the commands with && to ensure that the script will stop if any command fails. This also combines the steps into a single, convenient copy-paste command.
| cp dnd_sessions.db sessions.db.old | |
| # Download and run the migration script | |
| curl -fsSL https://raw.githubusercontent.com/google/adk-python/main/scripts/db_migration.sh | sh -s -- "sqlite:///%(here)s/sessions.db" "google.adk.sessions.database_session_service" | |
| curl -fsSL https://raw.githubusercontent.com/google/adk-python/main/scripts/db_migration.sh | sh -s -- "sqlite:///%(here)s/sessions.db.old" "google.adk.sessions.database_session_service" | |
| python -m google.adk.sessions.migrate_from_sqlalchemy_sqlite --source_db_path ./sessions.db.old --dest_db_path ./sessions.db | |
| rm sessions.db.old | |
| cp dnd_sessions.db sessions.db.old && \ | |
| curl -fsSL -o db_migration.sh https://raw.githubusercontent.com/google/adk-python/main/scripts/db_migration.sh && \ | |
| sh db_migration.sh "sqlite:///%(here)s/sessions.db.old" "google.adk.sessions.database_session_service" && \ | |
| python -m google.adk.sessions.migrate_from_sqlalchemy_sqlite --source_db_path ./sessions.db.old --dest_db_path ./sessions.db && \ | |
| rm sessions.db.old db_migration.sh |
|
Hi @ftnext ,Thank you for your work on this pull request. We appreciate the effort you've invested. |
|
@wuliang229 On v1.20.0 tag, 60e314a causes ValueError in my environment, so I used
full: https://gist.github.com/ftnext/b913722aead0183e751a0b429bdc07b7 This is wired because greenlet is already installed with sqlalchemy (ref: |
|
On my local environment, using 1.20.0, greenlet is not installed with sqlalchemy. Not sure why it is the case, but if you do "uv pip install greenlet", things should work. |
Thank you for helpful
migrate_session_dbsample.I found small update needed in ADK v1.20.0, so send this pull request.
Link to Issue or Description of Change
Problem:
DatabaseSessionServicedid not work well with SQLite DB fileSolution:
Use
SqliteSessionServiceinstead ofDatabaseSessionService, then rungoogle.adk.sessions.migrate_from_sqlalchemy_sqliteTesting Plan
manual only (it seems samples have not tests)
Unit Tests:
Manual End-to-End (E2E) Tests:
My blog (in Japanese)
https://nikkie-ftnext.hatenablog.com/entry/agent-development-kit-python-change-database-table-destructively-need-run-mingration-script
Checklist
Additional context
N/A