Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
2d2d31e
feat(server): implement `resource scoping` for `tasks` and `push noti…
sokoliva Feb 18, 2026
6093f7f
fix: add poolclass to allow.txt
sokoliva Feb 18, 2026
ce1a305
Merge branch '1.0-dev' of https://github.com/a2aproject/a2a-python in…
sokoliva Feb 19, 2026
6600b47
fix: test_inmemory_task_store.py merge caused error
sokoliva Feb 19, 2026
a212da7
Merge branch '1.0-dev' into resource-scoping
sokoliva Feb 19, 2026
ea89bbb
fix: - add alembic to dev field in pyproject.toml
sokoliva Feb 19, 2026
9301b8c
fix: update uv.lock
sokoliva Feb 19, 2026
62dce31
fix:
sokoliva Feb 19, 2026
86d769e
Merge branch '1.0-dev' into resource-scoping
sokoliva Feb 19, 2026
99cf89f
fix: fix linter issues
sokoliva Feb 19, 2026
a11d6de
Merge branch 'resource-scoping' of https://github.com/sokoliva/a2a-py…
sokoliva Feb 19, 2026
feb5033
Fix: fix some more linter errors
sokoliva Feb 19, 2026
212ad37
fix: more linter errors fixed
sokoliva Feb 19, 2026
f7b5c1c
fix: make parameter `ServerCallContext` non-optional in `PushNotifica…
sokoliva Feb 20, 2026
179b21a
Merge branch '1.0-dev' into resource-scoping
sokoliva Feb 20, 2026
38d7df6
fix: add ServerCallContext to tests/e2e/push_notifications/agent_app.py
sokoliva Feb 20, 2026
5eeb89d
Merge branch 'resource-scoping' of https://github.com/sokoliva/a2a-py…
sokoliva Feb 20, 2026
c4b282a
fix: small fix
sokoliva Feb 20, 2026
0090ecc
fix: fix unit test error
sokoliva Feb 20, 2026
0f51ef3
fi: fix
sokoliva Feb 20, 2026
00e5eac
fix: fix
sokoliva Feb 20, 2026
5d65aa6
chore: distribute alembic migration files. Add helper _get_owner_push…
sokoliva Feb 23, 2026
cbadd5b
Merge branch '1.0-dev' of https://github.com/a2aproject/a2a-python in…
sokoliva Feb 23, 2026
163c8c2
Merge branch '1.0-dev' into resource-scoping
sokoliva Feb 23, 2026
44ad799
fix: linter issues
sokoliva Feb 23, 2026
213ebb2
Merge branch 'resource-scoping' of https://github.com/sokoliva/a2a-py…
sokoliva Feb 23, 2026
5bfccf9
fix: uv run ruff format
sokoliva Feb 23, 2026
bde88f1
refactor: add an edge case to test_database_task_store
sokoliva Feb 24, 2026
db3d050
fix: uv run ruff format
sokoliva Feb 24, 2026
a37efe1
fix: typo
sokoliva Feb 24, 2026
782fcf7
chore: add migration for `push_notification_configs` table
sokoliva Feb 24, 2026
b77a4f6
Merge branch '1.0-dev' into resource-scoping
sokoliva Feb 24, 2026
3428956
fix: rename README to README.md
sokoliva Feb 24, 2026
d90b360
feat: enhance migration CLI with table and verbose options; add owner…
sokoliva Feb 24, 2026
efc54a9
Merge branch '1.0-dev' into resource-scoping
sokoliva Feb 25, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/actions/spelling/allow.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ openapiv2
opensource
otherurl
pb2
poolclass
postgres
POSTGRES
postgresql
Expand Down
15 changes: 15 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ style = "pep440"

[dependency-groups]
dev = [
"alembic>=1.14.0",
"mypy>=1.15.0",
"PyJWT>=2.0.0",
"pytest>=8.3.5",
Expand Down Expand Up @@ -347,3 +348,17 @@ docstring-code-format = true
docstring-code-line-length = "dynamic"
quote-style = "single"
indent-style = "space"


[tool.alembic]

# path to migration scripts.
script_location = "src/a2a/migrations"

# additional paths to be prepended to sys.path. defaults to the current working directory.
prepend_sys_path = [
"src"
]

[project.scripts]
a2a-db = "a2a.cli:run_migrations"
35 changes: 35 additions & 0 deletions src/a2a/alembic.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# A generic, single database configuration.

[loggers]
keys = root,sqlalchemy,alembic

[handlers]
keys = console

[formatters]
keys = generic

[logger_root]
level = WARNING
handlers = console
qualname =

[logger_sqlalchemy]
level = WARNING
handlers =
qualname = sqlalchemy.engine

[logger_alembic]
level = INFO
handlers =
qualname = alembic

[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic

[formatter_generic]
format = %(levelname)-5.5s [%(name)s] %(message)s
datefmt = %H:%M:%S
148 changes: 148 additions & 0 deletions src/a2a/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
import argparse
import os

from importlib.resources import files

from alembic import command
from alembic.config import Config


def run_migrations() -> None:
"""CLI tool to manage database migrations."""
parser = argparse.ArgumentParser(description='A2A Database Migration Tool')

# Global options
parser.add_argument(
'-o',
'--owner',
help="Value for the 'owner' column (used in specific migrations). If not set defaults to 'unknown'",
)
parser.add_argument(
'-u',
'--database-url',
help='Database URL to use for the migrations. If not set, the DATABASE_URL environment variable will be used.',
)
parser.add_argument(
'-t',
'--table',
help="Specific table to update. If not set, both 'tasks' and 'push_notification_configs' are updated.",
action='append',
)
parser.add_argument(
'-v',
'--verbose',
help='Enable verbose output (sets sqlalchemy.engine logging to INFO)',
action='store_true',
)

subparsers = parser.add_subparsers(dest='cmd', help='Migration command')

# Upgrade command
up_parser = subparsers.add_parser(
'upgrade', help='Upgrade to a later version'
)
up_parser.add_argument(
'revision',
nargs='?',
default='head',
help='Revision target (default: head)',
)
up_parser.add_argument(
'-o', '--owner', dest='sub_owner', help='Alias for top-level --owner'
)
up_parser.add_argument(
'-u',
'--database-url',
dest='sub_database_url',
help='Alias for top-level --database-url',
)
up_parser.add_argument(
'-t',
'--table',
dest='sub_table',
help='Alias for top-level --table',
action='append',
)
up_parser.add_argument(
'-v',
'--verbose',
dest='sub_verbose',
help='Enable verbose output (sets sqlalchemy.engine logging to INFO)',
action='store_true',
)

# Downgrade command
down_parser = subparsers.add_parser(
'downgrade', help='Revert to a previous version'
)
down_parser.add_argument(
'revision',
nargs='?',
default='base',
help='Revision target (e.g., -1, base or a specific ID)',
)
down_parser.add_argument(
'-u',
'--database-url',
dest='sub_database_url',
help='Alias for top-level --database-url',
)
down_parser.add_argument(
'-t',
'--table',
dest='sub_table',
help='Alias for top-level --table',
action='append',
)
down_parser.add_argument(
'-v',
'--verbose',
dest='sub_verbose',
help='Enable verbose output (sets sqlalchemy.engine logging to INFO)',
action='store_true',
)

args = parser.parse_args()

# Default to upgrade head if no command is provided
if not args.cmd:
args.cmd = 'upgrade'
args.revision = 'head'

# Locate the bundled alembic.ini
ini_path = files('a2a').joinpath('alembic.ini')
cfg = Config(str(ini_path))

# Dynamically set the script location
migrations_path = files('a2a').joinpath('migrations')
cfg.set_main_option('script_location', str(migrations_path))

# Consolidate owner, db_url, tables and verbose values
owner = args.owner or getattr(args, 'sub_owner', None)
db_url = args.database_url or getattr(args, 'sub_database_url', None)
tables = args.table or getattr(args, 'sub_table', None)
verbose = args.verbose or getattr(args, 'sub_verbose', False)

# Pass custom arguments to the migration context
if owner:
if args.cmd == 'downgrade':
parser.error(
"The --owner option is not supported for the 'downgrade' command."
)
cfg.set_main_option('owner', owner)
if db_url:
os.environ['DATABASE_URL'] = db_url
if tables:
cfg.set_main_option('tables', ','.join(tables))
if verbose:
cfg.set_main_option('verbose', 'true')

# Execute the requested command
if args.cmd == 'upgrade':
print(f'Upgrading database to {args.revision}...')
command.upgrade(cfg, args.revision)
elif args.cmd == 'downgrade':
print(f'Downgrading database to {args.revision}...')
command.downgrade(cfg, args.revision)

print('Done.')
88 changes: 88 additions & 0 deletions src/a2a/migrations/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# A2A SDK Database Migrations

This directory handles the database schema updates for the A2A SDK. It uses a bundled CLI tool to simplify the migration process for both users and developers of the SDK.

## User Guide (For Integrators)

When you install the `a2a-sdk`, you get a built-in command `a2a-db` which updates tables 'tasks' and 'push_notification_configs' in your database to make it compatible with the latest version of the SDK.

### 1. Recommended: Backup your database

Before running migrations, it is recommended to backup your database.

### 2. Set your Database URL
Migrations require the `DATABASE_URL` environment variable to be set with an **async-compatible** driver or you can use the `-u` flag to specify the database URL for a single command.

```bash
# SQLite example
export DATABASE_URL="sqlite+aiosqlite://user:pass@host:port/your_database_name"

# PostgreSQL example
export DATABASE_URL="postgresql+asyncpg://user:pass@localhost/your_database_name"

# MySQL example
export DATABASE_URL="mysql+aiomysql://user:pass@localhost/your_database_name"
```

### 3. Apply Migrations
Always run this command after installing or upgrading the SDK to ensure your database matches the required schema.

```bash
# Bring the database to the latest version
a2a-db
Copy link
Member

Choose a reason for hiding this comment

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

Running this command in a fresh environment will fail with alembic package missing error. alembic is a dev dependency currently so for package users it won't be installed.

You can reproduce it by creating a "fake" consumer project and installing whl there:

uv build

which is going to output something like dist/a2a_python-*.whl.

And in the new folder

uv venv
uv pip install <whl path from uv build>
uv run a2a-db

I believe we have two options:

  1. Instruct users to manually install alembic as their dev dependency if they want to use this CLI.
  2. Create a separate "extra" which will be used for this.

```

### 4. Customizing Defaults
Add owner to tasks migration allows you to pass custom values for the new `owner` column. For example, to set a specific default owner for existing tasks:

```bash
a2a-db -o "admin_user"
```

### 5. Rolling Back
If you need to revert a change:

```bash
# Step back one version
a2a-db downgrade -1
```

```bash
# Downgrade to a specific revision ID
a2a-db downgrade <revision_id>
```

```bash
# Revert all migrations
a2a-db downgrade base
```

---

## Developer Guide (For SDK Contributors)

If you are modifying the SDK models and need to generate new migration files, use the following workflow.

### Creating a New Migration
Developers should use the raw `alembic` command locally to generate migrations. Ensure you are in the project root.

```bash
# Detect changes in models.py and generate a script
uv run alembic revision --autogenerate -m "describe your changes"
```

### Internal Layout
- `env.py`: Configures the migration engine and applies the mandatory `DATABASE_URL` check.
- `versions/`: Contains the migration history.
- `script.py.mako`: The template for all new migration files.

## Troubleshooting

### "Duplicate column name"
If your database already has the required tables (e.g., created via `Base.metadata.create_all()` in a legacy script), you may need to "stamp" the database to tell the SDK that it is already up to date:

```bash
# Stamp the database without running SQL commands
# (Requires raw alembic command for developer use)
uv run alembic stamp head
```
1 change: 1 addition & 0 deletions src/a2a/migrations/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"Alembic database migration package."
Loading
Loading