Skip to content

Add local Postgres schema and swellsense db init - #42

Merged
xquantize merged 3 commits into
developfrom
agent/stage-3-db-init
Oct 28, 2026
Merged

xquantize merged 3 commits into
developfrom
agent/stage-3-db-init

Conversation

@xquantize

Copy link
Copy Markdown
Owner

XQU-25: Slice 4 local Postgres schema, compose, and swellsense db init.

Acceptance criteria:

  • Unit test covers the SQL file contents (tables documents and chunks, vector(768), HNSW chunks_embedding_hnsw / vector_cosine_ops, IF NOT EXISTS / CREATE EXTENSION) with no DB
  • init_schema calls conn.commit() after applying schema.sql, the dimension check, and register_vector
  • _db_init calls conn.commit() before conn.close() (order is commit then close; do not switch to autocommit)
  • Unit test (no DB): after mocking connect/init_schema, main(["db", "init"]) records ["commit", "close"]
  • Integration tests are marked db and skipped unless DATABASE_URL is set
  • Marked db: main(["db", "init"]), close, reconnect, SELECT to_regclass('public.chunks') is chunks and same for documents
  • Existing idempotent + vector round-trip test reconnects after init, calls register_vector (or swellsense.db.connect()) on the new connection before the Vector INSERT, and still rolls back DML
  • swellsense db init exists; a connection failure prints one stderr line and exits 1
  • docker-compose.yml uses pgvector/pgvector:pg17, localhost-only port (127.0.0.1:5432:5432), named volume
  • pyproject.toml / uv.lock add only psycopg[binary] and pgvector
  • docs/plans/stage-3.md has the Slice 4 box ticked and no other change; AGENTS.md roadmap is not ticked; AGENTS.md has a db/ layout line and compose/db init commands
  • bash scripts/check.sh prints CHECK PASSED (integration tests skipped unless DATABASE_URL is set)
  • Only the allowed files changed vs develop
  • The new commit fed5f7e touches only tests/test_db_schema.py

Review: all checks passed. check.sh: CHECK PASSED locally.

Post-merge smoke test (not a merge gate): docker compose up -d && uv run swellsense db init.

Made with Cursor

xquantize and others added 3 commits October 28, 2026 16:11
Docker Compose runs pgvector on localhost; init applies idempotent SQL
and checks embedding dimension against settings.

Co-authored-by: Cursor <cursoragent@cursor.com>
Psycopg 3 does not commit on close; persist init_schema and CLI db init
with explicit commits and tests that reconnect after init.

Co-authored-by: Cursor <cursoragent@cursor.com>
init_schema only registers Vector on the connection it receives; a fresh
psycopg.connect needs register_vector before INSERT can adapt embeddings.

Co-authored-by: Cursor <cursoragent@cursor.com>
@xquantize
xquantize merged commit 56e5a70 into develop Oct 28, 2026
1 check passed
@xquantize
xquantize deleted the agent/stage-3-db-init branch October 28, 2026 03:25
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