Skip to content

Move database layer to SQLAlchemy and Alembic - #7

Merged
MomoSolaris8 merged 27 commits into
mainfrom
sqlalchemy-orm
Oct 29, 2026
Merged

MomoSolaris8 merged 27 commits into
mainfrom
sqlalchemy-orm

Conversation

@MomoSolaris8

@MomoSolaris8 MomoSolaris8 commented Oct 23, 2026 •

Copy link
Copy Markdown
Owner

This PR moves the database code from psycopg and handwritten SQL to SQLAlchemy,
and makes Alembic migrations the only thing that creates or changes tables.

What changed

  • SQLAlchemy models for all 20 tables in db/models/: auth, memory, MCP, claims, RAG chunks, uploads
  • Migrations:
    • baseline: creates every table
    • seed: adds the default MCP servers and tool policies
    • HNSW index on chunks.embedding (vector_cosine_ops)
  • Every store module now uses SQLAlchemy sessions: uploads, auth, MCP, memory, claims, RAG
  • Removed all ensure_*_schema functions, so the app no longer runs DDL at startup or on every request
  • Fix: a user could take over another user's thread by sending its thread_id
  • Requires Python 3.11

Testing

  • 70 integration tests run against a real Postgres (pgvector) in CI
  • Each module got its tests before the swap. They passed on the old code and on the new code.
  • test_migrations checks that the migrations create every table and that the models and migrations are in sync
  • HNSW benchmark on 100k vectors (1024 dims): 307 ms (seq scan) → 4.6 ms (index scan)

Deployment

  • Existing database (Supabase): checked that its schema matched the models
    except for the HNSW index, stamped it at the baseline, then ran alembic upgrade head
  • Every deploy now runs alembic upgrade head before updating the Container App
  • New database: just run alembic upgrade head

Follow-ups (not in this PR)

  • Move the database to Azure Postgres and the files to Azure Blob Storage
  • Clean up repo-wide lint (ruff, import order, B008)
  • Fix with tests:
    • MCP credentials are stored in plaintext
    • any user can register a stdio MCP server
    • claim audit events can have ordering ties
    • a claim review run can be started twice

@vercel

vercel Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
support-agent-one-coyl Ready Ready Preview Oct 29, 2026 5:08pm UTC

@MomoSolaris8
MomoSolaris8 marked this pull request as ready for review October 29, 2026 21:03
@MomoSolaris8
MomoSolaris8 merged commit 587c39c into main Oct 29, 2026
6 checks passed
@MomoSolaris8
MomoSolaris8 deleted the sqlalchemy-orm branch October 29, 2026 21:07

This branch was successfully deployed

1 active deployment
Preview — ac87cd69 Deployed Oct 29, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant