Skip to content

Conversation

@ftnext
Copy link
Contributor

@ftnext ftnext commented Dec 8, 2025

Thank you for helpful migrate_session_db sample.
I found small update needed in ADK v1.20.0, so send this pull request.

Link to Issue or Description of Change

Problem:
DatabaseSessionService did not work well with SQLite DB file

Solution:
Use SqliteSessionService instead of DatabaseSessionService, then run google.adk.sessions.migrate_from_sqlalchemy_sqlite

Testing Plan

manual only (it seems samples have not tests)

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

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

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end.
  • Any dependent changes have been merged and published in downstream modules.

Additional context

N/A

Updated migration instructions to backup the previous database and use the old database for migration.
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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 migrate_session_db sample to align with changes introduced in ADK v1.20.0. The primary goal is to fix an incompatibility issue with SQLite databases by replacing the generic DatabaseSessionService with the specialized SqliteSessionService and updating the sample's migration instructions to use a dedicated Python migration utility for SQLite.

Highlights

  • ADK v1.20.0 Compatibility: The migrate_session_db sample has been updated to ensure compatibility with ADK v1.20.0.
  • SQLite Database Fix: Resolved an issue where DatabaseSessionService was not functioning correctly with SQLite databases by switching to SqliteSessionService.
  • Migration Script Update: The README.md now includes updated instructions for database migration, incorporating a new Python script (migrate_from_sqlalchemy_sqlite) for SQLite-specific migrations.
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 services [Component] This issue is related to runtime services, e.g. sessions, memory, artifacts, etc label Dec 8, 2025
@adk-bot
Copy link
Collaborator

adk-bot commented Dec 8, 2025

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!

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 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.

Comment on lines +30 to +36
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
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The sequence of shell commands can be made more robust and secure.

  1. Security: Piping curl to sh executes remote code without inspection, which is a security risk. It's safer to download the script first, inspect it, and then execute it.
  2. Robustness: The commands are not chained. If one command fails, the subsequent commands will still be executed. For example, if the python migration script fails, rm sessions.db.old will 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.

Suggested change
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

@ryanaiagent ryanaiagent self-assigned this Dec 9, 2025
@ryanaiagent
Copy link
Collaborator

ryanaiagent commented Dec 11, 2025

Hi @ftnext ,Thank you for your work on this pull request. We appreciate the effort you've invested.
It looks like the test failures here are unrelated to your changes. They were caused by a temporary issue on our main branch that has since been fixed.
Could you please update your branch with the latest changes from main? This will pull in the fix and should get the tests to pass.

@ryanaiagent ryanaiagent added the request clarification [Status] The maintainer need clarification or more information from the author label Dec 11, 2025
@wuliang229
Copy link
Collaborator

@ftnext do you think commit 60e314a fixed the issue?

@ftnext
Copy link
Contributor Author

ftnext commented Dec 12, 2025

@wuliang229 On v1.20.0 tag, 60e314a causes ValueError in my environment, so I used SqliteSessionService.

ValueError: the greenlet library is required to use this function. No module named 'greenlet'

full: https://gist.github.com/ftnext/b913722aead0183e751a0b429bdc07b7

This is wired because greenlet is already installed with sqlalchemy (ref: uv tree)

@wuliang229
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

request clarification [Status] The maintainer need clarification or more information from the author services [Component] This issue is related to runtime services, e.g. sessions, memory, artifacts, etc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants