Skip to content

Commit 1cfb6b8

Browse files
authored
feat(adk): Implement Google ADK Session Backend (#101)
Introduce a Google ADK session backend extension for SQLSpec. This enhances the framework's capabilities for managing sessions and events in applications using the Google Agent Development Kit.
1 parent 636954f commit 1cfb6b8

File tree

166 files changed

+32601
-1379
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

166 files changed

+32601
-1379
lines changed

.github/workflows/docs.yml

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Documentation Building
1+
name: Documentation Build
22

33
on:
44
release:
@@ -24,18 +24,26 @@ jobs:
2424
- name: Install dependencies
2525
run: uv sync --all-extras --dev
2626

27-
- name: Fetch gh pages
28-
run: git fetch origin gh-pages --depth=1
29-
30-
- name: Build release docs
27+
- name: Build documentation
3128
run: uv run python tools/build_docs.py docs-build
29+
30+
- name: Package documentation artifact
31+
run: tar -czvf docs-build.tar.gz docs-build
32+
33+
- name: Upload Release Asset
3234
if: github.event_name == 'release'
35+
uses: actions/upload-release-asset@v1
36+
env:
37+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38+
with:
39+
upload_url: ${{ github.event.release.upload_url }}
40+
asset_path: ./docs-build.tar.gz
41+
asset_name: docs-build-${{ github.ref_name }}.tar.gz
42+
asset_content_type: application/gzip
3343

34-
- name: Build dev docs
35-
run: uv run python tools/build_docs.py docs-build
44+
- name: Upload 'latest' docs artifact
3645
if: github.event_name == 'push'
37-
38-
- name: Deploy
39-
uses: JamesIves/github-pages-deploy-action@v4
46+
uses: actions/upload-artifact@v4
4047
with:
41-
folder: docs-build
48+
name: latest-docs
49+
path: docs-build.tar.gz

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ repos:
1717
- id: mixed-line-ending
1818
- id: trailing-whitespace
1919
- repo: https://github.com/charliermarsh/ruff-pre-commit
20-
rev: "v0.13.3"
20+
rev: "v0.14.0"
2121
hooks:
2222
- id: ruff
2323
args: ["--fix"]

NOTICE

Lines changed: 0 additions & 29 deletions
This file was deleted.

docs/changelog.rst

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,73 @@ All commits to this project will be documented in this file.
66

77
SQLSpec Changelog
88
==================
9+
10+
Recent Updates
11+
==============
12+
13+
Extension Migration Configuration
14+
----------------------------------
15+
16+
Extension migrations now receive automatic version prefixes and configuration has been simplified:
17+
18+
1. **Version Prefixing** (Automatic)
19+
20+
Extension migrations are automatically prefixed to prevent version collisions:
21+
22+
.. code-block:: text
23+
24+
# User migrations
25+
0001_initial.py → version: 0001
26+
27+
# Extension migrations (automatic prefix)
28+
0001_create_tables.py → version: ext_adk_0001
29+
0001_create_session.py → version: ext_litestar_0001
30+
31+
2. **Configuration Format** (Important)
32+
33+
Extension settings must be in ``extension_config`` only:
34+
35+
.. code-block:: python
36+
37+
# Incorrect format
38+
migration_config={
39+
"include_extensions": [
40+
{"name": "adk", "session_table": "custom"}
41+
]
42+
}
43+
44+
# Correct format
45+
extension_config={
46+
"adk": {"session_table": "custom"}
47+
},
48+
migration_config={
49+
"include_extensions": ["adk"] # Simple string list
50+
}
51+
52+
**Configuration Guide**: See :doc:`/migration_guides/extension_config`
53+
54+
Features
55+
--------
56+
57+
- Extension migrations now automatically prefixed (``ext_adk_0001``, ``ext_litestar_0001``)
58+
- Eliminated version collision between extension and user migrations
59+
- Simplified extension configuration API
60+
- Single source of truth for extension settings (``extension_config``)
61+
62+
Bug Fixes
63+
---------
64+
65+
- Fixed version collision when extension and user migrations had the same version number
66+
- Fixed duplicate key violation in ``ddl_migrations`` table when using extensions
67+
- Improved migration tracking with clear extension identification
68+
69+
Technical Changes
70+
-----------------
71+
72+
- ``_load_migration_metadata()`` now accepts optional ``version`` parameter
73+
- ``_parse_extension_configs()`` rewritten to read from ``extension_config`` only
74+
- Extension migration version prefixing handled in ``_get_migration_files_sync()``
75+
- Removed dict format support from ``include_extensions``
76+
77+
**Previous Versions**
78+
=====================

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@
155155
templates_path = ["_templates"]
156156
html_js_files = ["versioning.js"]
157157
html_css_files = ["custom.css"]
158-
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", "PYPI_README.md"]
158+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", "PYPI_README.md", "STYLE_GUIDE.md", "VOICE_AUDIT_REPORT.md"]
159159
html_show_sourcelink = True
160160
html_copy_source = True
161161

docs/examples/adbc_example.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1+
# /// script
2+
# dependencies = [
3+
# "sqlspec[adbc]",
4+
# "rich",
5+
# ]
6+
# requires-python = ">=3.10"
7+
# ///
18
"""Example demonstrating ADBC driver usage with query mixins.
29
310
This example shows how to use the ADBC (Arrow Database Connectivity) driver
411
with the development PostgreSQL container started by `make infra-up`.
512
"""
613

14+
from rich import print
15+
716
from sqlspec import SQLSpec, sql
817
from sqlspec.adapters.adbc import AdbcConfig
918

@@ -55,59 +64,59 @@ def adbc_example() -> None:
5564

5665
# Select all metrics using query mixin
5766
metrics = driver.select("SELECT * FROM analytics_data ORDER BY recorded_at")
58-
print(f"All metrics: {metrics}")
67+
print(f"[cyan]All metrics:[/cyan] {metrics}")
5968

6069
# Select one metric using query mixin
6170
revenue = driver.select_one("SELECT * FROM analytics_data WHERE metric_name = $1", "revenue")
62-
print(f"Revenue metric: {revenue}")
71+
print(f"[cyan]Revenue metric:[/cyan] {revenue}")
6372

6473
# Select one or none (no match) using query mixin
6574
nothing = driver.select_one_or_none("SELECT * FROM analytics_data WHERE metric_name = $1", "nothing")
66-
print(f"Nothing: {nothing}")
75+
print(f"[cyan]Nothing:[/cyan] {nothing}")
6776

6877
# Select scalar value using query mixin
6978
avg_value = driver.select_value("SELECT AVG(metric_value) FROM analytics_data WHERE metric_value > $1", 1.0)
70-
print(f"Average metric value: {avg_value:.2f}")
79+
print(f"[cyan]Average metric value:[/cyan] {avg_value:.2f}")
7180

7281
# Update
7382
result = driver.execute(
7483
"UPDATE analytics_data SET dimensions = $1::jsonb WHERE metric_name = $2",
7584
'{"updated": true}',
7685
"bounce_rate",
7786
)
78-
print(f"Updated {result.rows_affected} bounce rate records")
87+
print(f"[yellow]Updated {result.rows_affected} bounce rate records[/yellow]")
7988

8089
# Delete
8190
result = driver.execute("DELETE FROM analytics_data WHERE metric_value < $1", 1.0)
82-
print(f"Removed {result.rows_affected} low-value metrics")
91+
print(f"[yellow]Removed {result.rows_affected} low-value metrics[/yellow]")
8392

8493
# Use query builder with driver - this demonstrates the QueryBuilder parameter fix
8594
query = sql.select("*").from_("analytics_data").where("metric_name = $1")
8695
page_view_metrics = driver.select(query, "page_views")
87-
print(f"Page view metrics: {page_view_metrics}")
96+
print(f"[cyan]Page view metrics:[/cyan] {page_view_metrics}")
8897

8998
# JSON operations (PostgreSQL-specific) - using raw SQL due to SQLGlot JSON operator conversion
9099
mobile_metrics = driver.select(
91100
"SELECT metric_name, metric_value, dimensions->>'device' as device FROM analytics_data WHERE dimensions->>'device' = $1",
92101
"mobile",
93102
)
94-
print(f"Mobile metrics: {mobile_metrics}")
103+
print(f"[cyan]Mobile metrics:[/cyan] {mobile_metrics}")
95104

96105
# Demonstrate pagination
97106
page_metrics = driver.select("SELECT * FROM analytics_data ORDER BY metric_value DESC LIMIT $1 OFFSET $2", 2, 0)
98107
total_count = driver.select_value("SELECT COUNT(*) FROM analytics_data")
99-
print(f"Page 1: {page_metrics}, Total: {total_count}")
108+
print(f"[cyan]Page 1:[/cyan] {page_metrics}, [cyan]Total:[/cyan] {total_count}")
100109

101110

102111
def main() -> None:
103112
"""Run ADBC example."""
104-
print("=== ADBC (Arrow Database Connectivity) Driver Example ===")
113+
print("[bold cyan]=== ADBC (Arrow Database Connectivity) Driver Example ===[/bold cyan]")
105114
try:
106115
adbc_example()
107-
print("✅ ADBC example completed successfully!")
116+
print("[green]✅ ADBC example completed successfully![/green]")
108117
except Exception as e:
109-
print(f"❌ ADBC example failed: {e}")
110-
print("Make sure PostgreSQL is running with: make infra-up")
118+
print(f"[red]❌ ADBC example failed: {e}[/red]")
119+
print("[yellow]Make sure PostgreSQL is running with: make infra-up[/yellow]")
111120

112121

113122
if __name__ == "__main__":

0 commit comments

Comments
 (0)