-
Notifications
You must be signed in to change notification settings - Fork 391
docs: add Database Migration Documentation #864
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
Merged
sokoliva
merged 10 commits into
a2aproject:1.0-dev
from
sokoliva:migration-documentation
Mar 19, 2026
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
924c3f9
docs: add Database Migration Documentation
sokoliva 7f9e179
Remove duplicated disclaimers
sokoliva 9f2e788
fix migration readme
sokoliva 645e6cd
refactor: fix typo 0.1 -> 1.0 and improve inter-consistency between t…
sokoliva d028b2d
refactor migration instructions to improve formating consistency
sokoliva b2ae765
remove trailing horizontal line in README.md file
sokoliva 0a63842
few small fixes
sokoliva 3ffaa03
Merge branch '1.0-dev' into migration-documentation
sokoliva f3a6562
Merge branch 'migration-documentation' of https://github.com/sokoliva…
sokoliva b2b75a7
Grammar improvements.
sokoliva File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| # Database Migration Guide: v0.3 to v1.0 | ||
|
|
||
| The A2A SDK v1.0 introduces significant updates to the database persistence layer, including a new schema for tracking task ownership and protocol versions. This guide provides the necessary steps to migrate your database from v0.3 to the v1.0 persistence model without data loss. | ||
|
|
||
| --- | ||
|
|
||
| ## ⚡ Choose Your Migration Strategy | ||
|
|
||
| Depending on your application's availability requirements, choose one of the following paths: | ||
|
|
||
| | Strategy | Downtime | Complexity | Best For | | ||
| | :--- | :--- | :--- | :--- | | ||
| | **[Simple Migration](simple_migration.md)** | Short (Restart) | Low | Single-instance apps, non-critical services. | | ||
| | **[Zero Downtime Migration](zero_downtime.md)** | None | Medium | Multi-instance, high-availability production environments. | | ||
|
|
||
| --- | ||
|
|
||
| ## 🏗️ Technical Overview | ||
|
|
||
| The v1.0 database migration involves: | ||
| 1. **Schema Updates**: Adding the `protocol_version`, `owner`, and `last_updated` columns to the `tasks` table, and the `protocol_version` and `owner` columns to the `push_notification_configs` table. | ||
| 2. **Storage Model**: Transitioning from Pydantic-based JSON to Protobuf-based JSON serialization for better interoperability and performance. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| # Simple Migration: v0.3 to v1.0 | ||
|
|
||
| This guide is for users who can afford a short period of downtime during the migration from A2A protocol v0.3 to v1.0. This is the recommended path for single-instance applications or non-critical services. | ||
|
|
||
| --- | ||
|
|
||
| > [!WARNING] | ||
| > **Safety First:** | ||
| > Before proceeding, ensure you have a backup of your database. | ||
|
|
||
| --- | ||
|
|
||
| ## 🛠 Prerequisites | ||
|
|
||
| ### Install Migration Tools | ||
| The migration CLI is not included in the base package. Install the `db-cli` extra: | ||
|
|
||
| ```bash | ||
| uv add "a2a-sdk[db-cli]" | ||
| # OR | ||
| pip install "a2a-sdk[db-cli]" | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## 🚀 Migration Steps | ||
|
|
||
| ### Step 1: Apply Schema Updates | ||
|
|
||
| Run the `a2a-db` migration tool to update your tables. This adds new columns (`owner`, `protocol_version`, `last_updated`) while leaving existing v0.3 data intact. | ||
|
|
||
| ```bash | ||
| # Run migration against your target database | ||
| uv run a2a-db --database-url "your-database-url" | ||
| ``` | ||
|
|
||
| > [!NOTE] | ||
| > | ||
| >For more details on the CLI migration tool, including flags, see the [A2A SDK Database Migrations README](../../../../src/a2a/migrations/README.md). | ||
|
|
||
| > [!NOTE] | ||
| > | ||
| > The v1.0 database stores are designed to be backward compatible by default. After this step, your new v1.0 code will be able to read existing v0.3 entries from the database using a built-in legacy parser. | ||
|
|
||
| ### Step 2: Verify the Migration | ||
|
|
||
| Confirm the schema is at the correct version: | ||
|
|
||
| ```bash | ||
| uv run a2a-db current | ||
| ``` | ||
| The output should show the latest revision ID (e.g., `38ce57e08137`). | ||
|
|
||
| ### Step 3: Update Your Application Code | ||
|
|
||
| Upgrade your application to use the v1.0 SDK. | ||
|
|
||
| --- | ||
|
|
||
| ## ↩️ Rollback Strategy | ||
|
|
||
| If your application fails to start or encounters errors after the migration: | ||
|
|
||
| 1. **Revert Application Code**: Revert your application code to use the v0.3 SDK. | ||
|
|
||
| > [!NOTE] | ||
| > Older SDKs are compatible with the new schema (as new columns are nullable). If something breaks, rolling back the application code is usually sufficient. | ||
|
|
||
| 2. **Revert Schema (Fallback)**: If you encounter database issues, use the `downgrade` command to step back to the v0.3 structure. | ||
| ```bash | ||
| uv run a2a-db downgrade -1 | ||
| ``` | ||
| 3. **Restart**: Resume operations using the v0.3 SDK. | ||
|
|
||
|
|
||
| --- | ||
|
|
||
| ## 🧩 Resources | ||
| - **[Zero Downtime Migration](zero_downtime.md)**: If you cannot stop your application. | ||
| - **[a2a-db CLI](../../../../src/a2a/migrations/README.md)**: The primary tool for executing schema migrations. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| # Zero Downtime Migration: v0.3 to v1.0 | ||
|
|
||
| This guide outlines the strategy for migrating your Agent application from A2A protocol v0.3 to v1.0 without service interruption, even when running multiple distributed instances sharing a single database. | ||
|
|
||
| --- | ||
|
|
||
| > [!WARNING] | ||
| > **Safety First:** | ||
| > Before proceeding, ensure you have a backup of your database. | ||
|
|
||
| --- | ||
|
|
||
| ## 🛠 Prerequisites | ||
|
|
||
| ### Install Migration Tools | ||
| The migration CLI is not included in the base package. Install the `db-cli` extra: | ||
|
|
||
| ```bash | ||
| uv add "a2a-sdk[db-cli]" | ||
| # OR | ||
| pip install "a2a-sdk[db-cli]" | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## 🏗️ The 3-Step Strategy | ||
|
|
||
| Zero-downtime migration requires an "Expand, Migrate, Contract" pattern. It means we first expand the schema, then migrate the code to coexist with the old format, and finally transition fully to the new v1.0 standards. | ||
|
|
||
| ### Step 1: Apply Schema Updates | ||
|
|
||
| Run the `a2a-db` migration tool to update your tables. This adds new columns (`owner`, `protocol_version`, `last_updated`) while leaving existing v0.3 data intact. | ||
|
|
||
| ```bash | ||
| # Run migration against your target database | ||
| uv run a2a-db --database-url "your-database-url" | ||
| ``` | ||
|
|
||
| > [!NOTE] | ||
| > | ||
| >For more details on the CLI migration tool, including flags, see the [A2A SDK Database Migrations README](../../../../src/a2a/migrations/README.md). | ||
|
|
||
| > [!NOTE] | ||
| > All new columns are nullable. Your existing v0.3 code will continue to work normally after this step is completed. | ||
| > | ||
| > The v1.0 database stores are designed to be backward compatible by default. After this step, your new v1.0 code will be able to read existing v0.3 entries from the database using a built-in legacy parser. | ||
|
|
||
| #### ✅ How to Verify | ||
| Confirm the schema is at the correct version: | ||
|
|
||
| ```bash | ||
| uv run a2a-db current | ||
| ``` | ||
| The output should show the latest revision ID (e.g., `38ce57e08137`). | ||
|
|
||
| ### Step 2: Rolling Deployment in Compatibility Mode | ||
|
|
||
| In this step, you deploy the v1.0 SDK code but configure it to **write** data in the legacy v0.3 format. This ensures that any v0.3 instances still running in your cluster can read data produced by the new v1.0 instances. | ||
|
|
||
| #### Update Initialization Code | ||
| Enable the v0.3 conversion utilities in your application entry point (e.g., `main.py`). | ||
|
|
||
| ```python | ||
| from a2a.server.tasks import DatabaseTaskStore, DatabasePushNotificationConfigStore | ||
| from a2a.compat.v0_3.conversions import ( | ||
| core_to_compat_task_model, | ||
| core_to_compat_push_notification_config_model, | ||
| ) | ||
|
|
||
| # Initialize stores with compatibility conversion | ||
| # The '... # other' represents your existing configuration (engine, table_name, etc.) | ||
| task_store = DatabaseTaskStore( | ||
| ... # other arguments | ||
| core_to_model_conversion=core_to_compat_task_model | ||
| ) | ||
|
|
||
| config_store = DatabasePushNotificationConfigStore( | ||
| ... # other arguments | ||
| core_to_model_conversion=core_to_compat_push_notification_config_model | ||
| ) | ||
| ``` | ||
|
|
||
| #### Perform a Rolling Restart | ||
| Deploy the new code by restarting your instances one by one. | ||
|
|
||
| #### ✅ How to Verify | ||
| Verify that v1.0 instances are successfully writing to the database. In the `tasks` and `push_notification_configs` tables, new rows created during this phase should have `protocol_version` set to `0.3`. | ||
|
|
||
| ### Step 3: Transition to v1.0 Mode | ||
|
|
||
| Once **100%** of your application instances are running v1.0 code (with compatibility mode enabled), you can switch to the v1.0 write format. | ||
|
|
||
| > [!CAUTION] | ||
| > **CRITICAL PRE-REQUISITE**: Do NOT start Step 3 until you have confirmed that no v0.3 instances remain. Old v0.3 code cannot parse the new v1.0 native database entries. | ||
|
|
||
| #### Disable Compatibility Logic | ||
| Remove the `core_to_model_conversion` arguments from your Store constructors. | ||
|
|
||
| ```python | ||
| # Revert to native v1.0 write behavior | ||
| task_store = DatabaseTaskStore(engine=engine, ...) | ||
| config_store = DatabasePushNotificationConfigStore(engine=engine, ...) | ||
| ``` | ||
|
|
||
| #### Perform a Final Rolling Restart | ||
|
|
||
| Restart your instances again. | ||
|
|
||
| #### ✅ How to Verify | ||
| Inspect the `tasks` and `push_notification_configs` tables. New entries should now show `protocol_version` as `1.0`. | ||
|
|
||
| --- | ||
|
|
||
| ## 🛠️ Why it Works | ||
|
|
||
| The A2A `DatabaseStore` classes follow a version-aware read/write pattern: | ||
|
|
||
| 1. **Write Logic**: If `core_to_model_conversion` is provided, it is used. Otherwise, it defaults to the v1.0 Protobuf JSON format. | ||
| 2. **Read Logic**: The store automatically inspects the `protocol_version` column for every row. | ||
| * If `NULL` or `0.3`, it uses the internal **v0.3 legacy parser**. | ||
| * If `1.0`, it uses the modern **Protobuf parser**. | ||
|
|
||
| This allows v1.0 instances to read *all* existing data regardless of when it was written. | ||
|
|
||
| --- | ||
|
|
||
| ## 🧩 Resources | ||
| - **[a2a-db CLI](../../../../src/a2a/migrations/README.md)**: The primary tool for executing schema migrations. | ||
| - **[Compatibility Conversions](../../../../src/a2a/compat/v0_3/conversions.py)**: Source for classes like `core_to_compat_task_model` used in Step 2. | ||
| - **[Task Store Implementation](../../../../src/a2a/server/tasks/database_task_store.py)**: The `DatabaseTaskStore` which handles the version-aware read/write logic. | ||
| - **[Push Notification Store Implementation](../../../../src/a2a/server/tasks/database_push_notification_config_store.py)**: The `DatabasePushNotificationConfigStore` which handles the version-aware read/write logic. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.