Skip to content

Commit

Permalink
fix: adapt ARRAY type for SQLite in unit tests
Browse files Browse the repository at this point in the history
Co-Authored-By: Chris Weaver <chris@onyx.app>
  • Loading branch information
devin-ai-integration[bot] and Chris Weaver committed Jan 30, 2025
1 parent da8f8ed commit 931fb0e
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion backend/tests/unit/onyx/db/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,31 @@
import pytest
from sqlalchemy import create_engine
from sqlalchemy import event
from sqlalchemy.dialects.postgresql import ARRAY
from sqlalchemy.dialects.postgresql import JSONB
from sqlalchemy.orm import Session
from sqlalchemy.orm import sessionmaker
from sqlalchemy.types import JSON
from sqlalchemy.types import String
from sqlalchemy.types import Text

from onyx.db.models import Base


@event.listens_for(Base.metadata, "before_create")
def adapt_jsonb_for_sqlite(target, connection, **kw):
"""Replace JSONB with JSON for SQLite."""
"""Replace PostgreSQL-specific types with SQLite-compatible types."""
for table in target.tables.values():
for column in table.columns:
if isinstance(column.type, JSONB):
# Create a new JSON type that SQLite can handle
json_type = JSON()
json_type.should_evaluate_none = True
column.type = json_type
elif isinstance(column.type, ARRAY):
# Convert ARRAY types to TEXT for SQLite
# We'll store arrays as JSON strings
column.type = Text()


@pytest.fixture
Expand Down

0 comments on commit 931fb0e

Please sign in to comment.