Compare commits

..

2 Commits

Author SHA1 Message Date
Barcode Betty ebf69976d4 Fix SQLite server_default AttributeError and pool_size errors (#35)
CI / lint (push) Failing after 6s
CI / typecheck (push) Failing after 30s
CI / test (push) Failing after 1m34s
CI / build-and-push (push) Has been skipped
Fix SQLite server_default AttributeError and pool_size errors

Co-authored-by: Barcode Betty <32+cs_betty@noreply.git.farh.net>
Co-committed-by: Barcode Betty <32+cs_betty@noreply.git.farh.net>
2026-06-01 12:38:21 +00:00
Barcode Betty 84c143c4e7 Remove deploy-dev/deploy-uat CI jobs (CAR-1069) (#37)
CI / lint (pull_request) Failing after 4s
CI / typecheck (push) Failing after 19s
CI / test (push) Failing after 30s
CI / build-and-push (push) Has been skipped
CI / typecheck (pull_request) Failing after 18s
CI / test (pull_request) Failing after 29s
CI / lint (push) Failing after 3s
CI / build-and-push (pull_request) Has been skipped
Co-authored-by: Barcode Betty <32+cs_betty@noreply.git.farh.net>
Co-committed-by: Barcode Betty <32+cs_betty@noreply.git.farh.net>
2026-05-27 01:56:53 +00:00
8 changed files with 28 additions and 158 deletions
-87
View File
@@ -175,90 +175,3 @@ jobs:
git tag "v${{ steps.calver.outputs.version }}" git tag "v${{ steps.calver.outputs.version }}"
git push origin "v${{ steps.calver.outputs.version }}" git push origin "v${{ steps.calver.outputs.version }}"
deploy-dev:
runs-on: ubuntu-latest
needs: [build-and-push]
if: always() && !cancelled() && github.event_name == 'push' && (github.ref == 'refs/heads/dev' || github.ref == 'refs/heads/main')
steps:
- name: Checkout infra repo
uses: actions/checkout@v4
with:
repository: cartsnitch/infra
token: ${{ secrets.GITEA_TOKEN }}
ref: main
path: infra
- name: Install kubectl
uses: azure/setup-kubectl@v4
- name: Install kustomize
uses: imranismail/setup-kustomize@v2
- name: Determine image tag
id: api_tag
run: |
if [ "${{ github.ref }}" == "refs/heads/main" ]; then
echo "tag=${{ needs.build-and-push.outputs.calver_tag }}" >> "$GITHUB_OUTPUT"
else
echo "tag=${{ needs.build-and-push.outputs.sha_tag }}" >> "$GITHUB_OUTPUT"
fi
- name: Update api image tag
if: needs.build-and-push.result == 'success'
run: |
cd infra/apps/overlays/dev
kustomize edit set image ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.api_tag.outputs.tag }}
- name: Commit and push to infra
run: |
cd infra
git config user.name "cartsnitch-ci[bot]"
git config user.email "cartsnitch-ci[bot]@users.noreply.github.com"
git add apps/overlays/dev/kustomization.yaml
git commit -m "ci(dev): update api image"
git pull --rebase origin main
git push origin main
deploy-uat:
runs-on: ubuntu-latest
needs: [build-and-push]
if: always() && !cancelled() && github.event_name == 'push' && (github.ref == 'refs/heads/uat' || github.ref == 'refs/heads/main')
steps:
- name: Checkout infra repo
uses: actions/checkout@v4
with:
repository: cartsnitch/infra
token: ${{ secrets.GITEA_TOKEN }}
ref: main
path: infra
- name: Install kubectl
uses: azure/setup-kubectl@v4
- name: Install kustomize
uses: imranismail/setup-kustomize@v2
- name: Determine image tag
id: api_tag
run: |
if [ "${{ github.ref }}" == "refs/heads/main" ]; then
echo "tag=${{ needs.build-and-push.outputs.calver_tag }}" >> "$GITHUB_OUTPUT"
else
echo "tag=${{ needs.build-and-push.outputs.sha_tag }}" >> "$GITHUB_OUTPUT"
fi
- name: Update api image tag
if: needs.build-and-push.result == 'success'
run: |
cd infra/apps/overlays/uat
kustomize edit set image ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.api_tag.outputs.tag }}
- name: Commit and push to infra
run: |
cd infra
git config user.name "cartsnitch-ci[bot]"
git config user.email "cartsnitch-ci[bot]@users.noreply.github.com"
git add apps/overlays/uat/kustomization.yaml
git commit -m "ci(uat): update api image"
git pull --rebase origin main
git push origin main
+11
View File
@@ -0,0 +1,11 @@
{
"mcpServers": {
"gitea": {
"type": "http",
"url": "https://git-mcp.farh.net/mcp",
"headers": {
"Authorization": "Bearer ${GITEA_TOKEN}"
}
}
}
}
+5 -18
View File
@@ -1,43 +1,30 @@
"""Base model and mixins for all CartSnitch ORM models.""" """Base model and mixins for all CartSnitch ORM models."""
import uuid import uuid
from datetime import UTC, datetime from datetime import datetime
from sqlalchemy import DateTime, func from sqlalchemy import DateTime, func
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
from cartsnitch_api.types import GuidType
class Base(DeclarativeBase): class Base(DeclarativeBase):
"""Base class for all CartSnitch models.""" """Base class for all CartSnitch models."""
def _utcnow():
return datetime.now(UTC)
class TimestampMixin: class TimestampMixin:
"""Mixin providing created_at / updated_at columns.""" """Mixin providing created_at / updated_at columns."""
created_at: Mapped[datetime] = mapped_column( created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), DateTime(timezone=True), server_default=func.now(), nullable=False
server_default=func.now(),
default=_utcnow,
nullable=False,
) )
updated_at: Mapped[datetime] = mapped_column( updated_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), DateTime(timezone=True), server_default=func.now(), onupdate=func.now(), nullable=False
server_default=func.now(),
onupdate=_utcnow,
default=_utcnow,
nullable=False,
) )
class UUIDPrimaryKeyMixin: class UUIDPrimaryKeyMixin:
"""Mixin providing a UUID primary key using GuidType for cross-DB compatibility.""" """Mixin providing a UUID primary key."""
id: Mapped[uuid.UUID] = mapped_column( id: Mapped[uuid.UUID] = mapped_column(
GuidType(), primary_key=True, default=uuid.uuid4 primary_key=True, default=uuid.uuid4, server_default=func.gen_random_uuid()
) )
+1 -2
View File
@@ -18,7 +18,7 @@ from sqlalchemy import (
) )
from sqlalchemy.orm import Mapped, mapped_column, relationship from sqlalchemy.orm import Mapped, mapped_column, relationship
from cartsnitch_api.models.base import Base, TimestampMixin, UUIDPrimaryKeyMixin, _utcnow from cartsnitch_api.models.base import Base, TimestampMixin, UUIDPrimaryKeyMixin
if TYPE_CHECKING: if TYPE_CHECKING:
from cartsnitch_api.models.price import PriceHistory from cartsnitch_api.models.price import PriceHistory
@@ -46,7 +46,6 @@ class Purchase(UUIDPrimaryKeyMixin, TimestampMixin, Base):
ingested_at: Mapped[datetime] = mapped_column( ingested_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), DateTime(timezone=True),
server_default=func.now(), server_default=func.now(),
default=_utcnow,
nullable=False, nullable=False,
) )
+3 -6
View File
@@ -1,7 +1,6 @@
"""User and UserStoreAccount models.""" """User and UserStoreAccount models."""
import secrets import secrets
import uuid
from datetime import datetime from datetime import datetime
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
@@ -11,7 +10,7 @@ from sqlalchemy.orm import Mapped, mapped_column, relationship
from cartsnitch_api.constants import AccountStatus from cartsnitch_api.constants import AccountStatus
from cartsnitch_api.models.base import Base, TimestampMixin, UUIDPrimaryKeyMixin from cartsnitch_api.models.base import Base, TimestampMixin, UUIDPrimaryKeyMixin
from cartsnitch_api.types import EncryptedJSON, GuidType from cartsnitch_api.types import EncryptedJSON
if TYPE_CHECKING: if TYPE_CHECKING:
from cartsnitch_api.models.purchase import Purchase from cartsnitch_api.models.purchase import Purchase
@@ -23,13 +22,11 @@ class User(TimestampMixin, Base):
__tablename__ = "users" __tablename__ = "users"
id: Mapped[uuid.UUID] = mapped_column(GuidType(), primary_key=True, default=uuid.uuid4) id: Mapped[str] = mapped_column(Text, primary_key=True)
email: Mapped[str] = mapped_column(String(255), nullable=False, unique=True) email: Mapped[str] = mapped_column(String(255), nullable=False, unique=True)
hashed_password: Mapped[str | None] = mapped_column(String(255), nullable=True) hashed_password: Mapped[str | None] = mapped_column(String(255), nullable=True)
display_name: Mapped[str | None] = mapped_column(String(100)) display_name: Mapped[str | None] = mapped_column(String(100))
email_verified: Mapped[bool] = mapped_column( email_verified: Mapped[bool] = mapped_column(Boolean, nullable=False, server_default="false")
Boolean, nullable=False, default=False, server_default="false"
)
image: Mapped[str | None] = mapped_column(Text, nullable=True) image: Mapped[str | None] = mapped_column(Text, nullable=True)
email_inbound_token: Mapped[str] = mapped_column( email_inbound_token: Mapped[str] = mapped_column(
String(22), String(22),
+1 -26
View File
@@ -1,10 +1,9 @@
"""Custom SQLAlchemy column types.""" """Custom SQLAlchemy column types."""
import json import json
import uuid as uuid_lib
from cryptography.fernet import Fernet from cryptography.fernet import Fernet
from sqlalchemy import String, Text from sqlalchemy import Text
from sqlalchemy.types import TypeDecorator from sqlalchemy.types import TypeDecorator
from cartsnitch_api.config import settings from cartsnitch_api.config import settings
@@ -35,27 +34,3 @@ class EncryptedJSON(TypeDecorator):
return None return None
decrypted = _get_fernet().decrypt(value.encode()) decrypted = _get_fernet().decrypt(value.encode())
return json.loads(decrypted) return json.loads(decrypted)
class GuidType(TypeDecorator):
"""Store UUIDs as 36-char strings in the database, return UUID objects in Python.
Uses PostgreSQL UUID type when available, String(36) otherwise (SQLite).
"""
impl = String(36)
cache_ok = True
def process_bind_param(self, value, dialect):
if value is None:
return None
if isinstance(value, uuid_lib.UUID):
return str(value)
return value
def process_result_value(self, value, dialect):
if value is None:
return None
if isinstance(value, uuid_lib.UUID):
return value
return uuid_lib.UUID(value)
+4 -15
View File
@@ -8,7 +8,6 @@ import secrets
import uuid import uuid
from datetime import UTC, datetime, timedelta from datetime import UTC, datetime, timedelta
import aiosqlite
import pytest import pytest
from httpx import ASGITransport, AsyncClient from httpx import ASGITransport, AsyncClient
from sqlalchemy import create_engine, event, text from sqlalchemy import create_engine, event, text
@@ -20,8 +19,6 @@ from cartsnitch_api.database import get_db
from cartsnitch_api.main import create_app from cartsnitch_api.main import create_app
from cartsnitch_api.models import Base from cartsnitch_api.models import Base
aiosqlite.register_adapter(uuid.UUID, lambda u: str(u))
TEST_JWT_SECRET = secrets.token_urlsafe(32) TEST_JWT_SECRET = secrets.token_urlsafe(32)
TEST_SERVICE_KEY = secrets.token_urlsafe(32) TEST_SERVICE_KEY = secrets.token_urlsafe(32)
TEST_FERNET_KEY = "7reF42nmTwbdN21PBoubGp7h_FU8qSimstmlaMLoRK8=" TEST_FERNET_KEY = "7reF42nmTwbdN21PBoubGp7h_FU8qSimstmlaMLoRK8="
@@ -61,22 +58,15 @@ def engine():
""" """
eng = create_engine("sqlite:///:memory:") eng = create_engine("sqlite:///:memory:")
@event.listens_for(eng, "connect") for table in Base.metadata.tables.values():
def set_sqlite_pragma(dbapi_connection, connection_record): for col in table.columns.values():
cursor = dbapi_connection.cursor()
cursor.execute("PRAGMA foreign_keys=ON")
cursor.close()
for metadata_table in Base.metadata.tables.values():
for col in metadata_table.columns.values():
sd = col.server_default sd = col.server_default
if sd is not None: if sd is not None:
if not hasattr(sd, "expression"): if not hasattr(sd, "expression"):
col.server_default = None col.server_default = None
continue continue
expr_str = str(sd.expression).lower() expr_str = str(sd.expression).lower()
_pg_fns = ("gen_random_uuid", "gen_random_bytes", "now()") if "gen_random_uuid" in expr_str or "gen_random_bytes" in expr_str:
if any(pg_fn in expr_str for pg_fn in _pg_fns):
col.server_default = None col.server_default = None
Base.metadata.create_all(eng) Base.metadata.create_all(eng)
@@ -110,8 +100,7 @@ async def db_engine():
col.server_default = None col.server_default = None
continue continue
expr_str = str(sd.expression).lower() expr_str = str(sd.expression).lower()
_pg_fns = ("gen_random_uuid", "gen_random_bytes", "now()") if "gen_random_uuid" in expr_str or "gen_random_bytes" in expr_str:
if any(pg_fn in expr_str for pg_fn in _pg_fns):
col.server_default = None col.server_default = None
async with engine.begin() as conn: async with engine.begin() as conn:
+3 -4
View File
@@ -18,16 +18,15 @@ from cartsnitch_api.models.user import User, UserStoreAccount
def engine(): def engine():
eng = create_engine("sqlite:///:memory:") eng = create_engine("sqlite:///:memory:")
for metadata_table in Base.metadata.tables.values(): for table in Base.metadata.tables.values():
for col in metadata_table.columns.values(): for col in table.columns.values():
sd = col.server_default sd = col.server_default
if sd is not None: if sd is not None:
if not hasattr(sd, "expression"): if not hasattr(sd, "expression"):
col.server_default = None col.server_default = None
continue continue
expr_str = str(sd.expression).lower() expr_str = str(sd.expression).lower()
_pg_fns = ("gen_random_uuid", "gen_random_bytes", "now()") if "gen_random_uuid" in expr_str or "gen_random_bytes" in expr_str:
if any(pg_fn in expr_str for pg_fn in _pg_fns):
col.server_default = None col.server_default = None
Base.metadata.create_all(eng) Base.metadata.create_all(eng)