Skip to content

Commit b23d607

Browse files
MementoRCclaude
andcommitted
fix: resolve database initialization failures
- Add alembic>=1.12.0 to main dependencies (was only in dev deps) - Update PostgreSQL connector to use psycopg (v3) driver instead of psycopg2 - Fix SQLAlchemy 2.0 compatibility by using text() instead of Text() for queries ✅ Quality: Database initialization now works with uv ✅ Tests: Connection and schema creation verified 📋 TaskMaster: Database infrastructure fixes complete 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 0d4961c commit b23d607

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ dependencies = [
3939
"psutil>=5.9.0",
4040
"SQLAlchemy>=2.0.0", # Added for PostgreSQL ORM
4141
"psycopg[binary]>=3.1.0", # Added for PostgreSQL driver
42+
"alembic>=1.12.0", # Added for database migrations
4243
]
4344

4445
[project.optional-dependencies]

src/uckn/storage/postgresql_connector.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from typing import Any, Dict, List, Optional
33
from datetime import datetime
44

5-
from sqlalchemy import create_engine, Column, String, Text, DateTime, Float, ForeignKey
5+
from sqlalchemy import create_engine, Column, String, Text, DateTime, Float, ForeignKey, text
66
from sqlalchemy.orm import sessionmaker, declarative_base, relationship
77
from sqlalchemy.exc import SQLAlchemyError
88
from sqlalchemy.pool import QueuePool
@@ -122,8 +122,13 @@ def __init__(self, db_url: str = "postgresql://user:password@localhost:5432/uckn
122122
def _connect_to_db(self) -> None:
123123
"""Initializes the SQLAlchemy engine and session factory."""
124124
try:
125+
# Ensure we use psycopg (version 3) driver instead of psycopg2
126+
db_url = self.db_url
127+
if db_url.startswith("postgresql://"):
128+
db_url = db_url.replace("postgresql://", "postgresql+psycopg://", 1)
129+
125130
self.engine = create_engine(
126-
self.db_url,
131+
db_url,
127132
poolclass=QueuePool,
128133
pool_size=self.pool_size,
129134
max_overflow=self.max_overflow,
@@ -159,7 +164,7 @@ def is_available(self) -> bool:
159164
return False
160165
try:
161166
with self.get_db_session() as session:
162-
session.execute(Text("SELECT 1"))
167+
session.execute(text("SELECT 1"))
163168
return True
164169
except SQLAlchemyError as e:
165170
self._logger.error(f"PostgreSQL connection check failed: {e}")

0 commit comments

Comments
 (0)