Rename metadata column to metadata_ to avoid SQLAlchemy reserved keyword conflict
Add explicit column name mapping using mapped_column("metadata") while using metadata_ as Python attribute name in Notification and Secret models. Update Pydantic schemas to use validation_alias for proper serialization. Update service layer to use metadata_ attribute when creating and updating records.
This commit is contained in:
@@ -19,7 +19,7 @@ class Notification(Base):
|
||||
type: Mapped[str] = mapped_column(String(50), nullable=False) # info, success, warning, error
|
||||
is_read: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False)
|
||||
link: Mapped[str | None] = mapped_column(String(500))
|
||||
metadata: Mapped[dict] = mapped_column(JSONB, default=dict, nullable=False)
|
||||
metadata_: Mapped[dict] = mapped_column("metadata", JSONB, default=dict, nullable=False)
|
||||
read_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True))
|
||||
|
||||
user: Mapped["User"] = relationship()
|
||||
|
||||
@@ -17,6 +17,6 @@ class Secret(Base):
|
||||
encrypted_value: Mapped[str] = mapped_column(Text, nullable=False)
|
||||
secret_type: Mapped[str] = mapped_column(String(50), nullable=False) # api_token, password, etc.
|
||||
scope: Mapped[str] = mapped_column(String(100), nullable=False) # plugin, system, user
|
||||
metadata: Mapped[dict] = mapped_column(JSONB, default=dict, nullable=False)
|
||||
metadata_: Mapped[dict] = mapped_column("metadata", JSONB, default=dict, nullable=False)
|
||||
|
||||
service_connections: Mapped[list["ServiceConnection"]] = relationship(back_populates="credentials")
|
||||
|
||||
@@ -2,7 +2,7 @@ import uuid
|
||||
from datetime import datetime
|
||||
from typing import Any
|
||||
|
||||
from pydantic import BaseModel
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
class NotificationBase(BaseModel):
|
||||
@@ -25,6 +25,7 @@ class NotificationResponse(NotificationBase):
|
||||
id: uuid.UUID
|
||||
user_id: uuid.UUID
|
||||
is_read: bool
|
||||
metadata: dict[str, Any] = Field(default_factory=dict, validation_alias="metadata_")
|
||||
read_at: datetime | None
|
||||
created_at: datetime
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import uuid
|
||||
from datetime import datetime
|
||||
from typing import Any
|
||||
|
||||
from pydantic import BaseModel
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
class SecretBase(BaseModel):
|
||||
@@ -24,6 +24,7 @@ class SecretUpdate(BaseModel):
|
||||
|
||||
class SecretResponse(SecretBase):
|
||||
id: uuid.UUID
|
||||
metadata: dict[str, Any] = Field(default_factory=dict, validation_alias="metadata_")
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ async def create_notification(
|
||||
message=message,
|
||||
type=type,
|
||||
link=link,
|
||||
metadata=metadata or {},
|
||||
metadata_=metadata or {},
|
||||
)
|
||||
db.add(notif)
|
||||
await db.commit()
|
||||
|
||||
@@ -17,7 +17,7 @@ async def create_secret(db: AsyncSession, data: schemas.SecretCreate, owner: Use
|
||||
encrypted_value=encrypt_secret(data.value),
|
||||
secret_type=data.secret_type,
|
||||
scope=data.scope,
|
||||
metadata=data.metadata,
|
||||
metadata_=data.metadata,
|
||||
)
|
||||
db.add(secret)
|
||||
await db.commit()
|
||||
@@ -44,7 +44,7 @@ async def update_secret(db: AsyncSession, secret_id: uuid.UUID, data: schemas.Se
|
||||
if data.value is not None:
|
||||
secret.encrypted_value = encrypt_secret(data.value)
|
||||
if data.metadata is not None:
|
||||
secret.metadata = data.metadata
|
||||
secret.metadata_ = data.metadata
|
||||
await db.commit()
|
||||
await db.refresh(secret)
|
||||
return secret
|
||||
|
||||
Reference in New Issue
Block a user