Skip to content

Commit fb6b8da

Browse files
authored
Enhance EmailAttachment model and update project configuration (#68)
- Added a unique constraint to the EmailAttachment model for the combination of 'webhook', 'email_id', and 'attachment_id'. - Updated pyproject.toml to include the 'task' module in py-modules and adjusted the pyright include paths accordingly. - Introduced a new Alembic migration script to apply the changes to the database schema.
1 parent 16808f2 commit fb6b8da

3 files changed

Lines changed: 56 additions & 17 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""Fix EmailAttachment model.
2+
3+
Revision ID: deffbec94147
4+
Revises: cc1fb6b21dc7
5+
Create Date: 2026-04-22 05:45:13.102115
6+
7+
"""
8+
from typing import Sequence, Union
9+
10+
from alembic import op
11+
import sqlalchemy as sa
12+
import sqlmodel
13+
14+
15+
# revision identifiers, used by Alembic.
16+
revision: str = 'deffbec94147'
17+
down_revision: Union[str, Sequence[str], None] = 'cc1fb6b21dc7'
18+
branch_labels: Union[str, Sequence[str], None] = None
19+
depends_on: Union[str, Sequence[str], None] = None
20+
21+
22+
def upgrade() -> None:
23+
"""Upgrade schema."""
24+
# ### commands auto generated by Alembic - please adjust! ###
25+
op.create_unique_constraint('uq_email_attachment_webhook_email_id_attachment_id', 'email_attachment', ['webhook', 'email_id', 'attachment_id'])
26+
# ### end Alembic commands ###
27+
28+
29+
def downgrade() -> None:
30+
"""Downgrade schema."""
31+
# ### commands auto generated by Alembic - please adjust! ###
32+
op.drop_constraint('uq_email_attachment_webhook_email_id_attachment_id', 'email_attachment', type_='unique')
33+
# ### end Alembic commands ###

app/db_models.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from typing import Any
66

77
from pydantic import EmailStr, StrictBool, field_serializer, field_validator
8-
from sqlmodel import JSON, Column, Field, SQLModel
8+
from sqlmodel import JSON, Column, Field, SQLModel, UniqueConstraint
99

1010
from app.settings import get_settings
1111

@@ -78,8 +78,14 @@ class EmailAttachment(SQLModel, table=True):
7878
s3_bucket: str = Field(max_length=64)
7979
s3_key: str = Field(max_length=256)
8080

81-
class Config: # pyright: ignore[reportIncompatibleVariableOverride]
82-
unique_together = [('webhook', 'email_id', 'attachment_id')]
81+
__table_args__ = (
82+
UniqueConstraint(
83+
'webhook',
84+
'email_id',
85+
'attachment_id',
86+
name='uq_email_attachment_webhook_email_id_attachment_id',
87+
),
88+
)
8389

8490
@field_serializer('created_at')
8591
def serialize_created_at(self, value: datetime) -> str:

pyproject.toml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ urls = { Repository = "https://github.com/lucas-six/fastapi-template/" }
5757
dev = ["mypy>=1.18.2", "ruff>=0.14.6"]
5858

5959
[tool.setuptools]
60-
py-modules = ["app"]
60+
py-modules = ["app", "task"]
6161

6262
# [[tool.uv.index]]
6363
# url = "https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple"
@@ -170,19 +170,19 @@ module = "redis.*"
170170
ignore_missing_imports = true
171171

172172
[tool.pyright]
173-
include = ["app/**/*.py"]
174-
exclude = [
175-
".git",
176-
"**/__pycache__",
177-
".venv",
178-
"**/*.egg-info",
179-
".ruff_cache",
180-
".mypy_cache",
181-
".pytest_cache",
182-
".tox",
183-
"alembic/env.py",
184-
"alembic/versions/*",
185-
]
173+
include = ["app", "task"]
174+
# exclude = [
175+
# ".git",
176+
# "**/__pycache__",
177+
# ".venv",
178+
# "**/*.egg-info",
179+
# ".ruff_cache",
180+
# ".mypy_cache",
181+
# ".pytest_cache",
182+
# ".tox",
183+
# "alembic/env.py",
184+
# "alembic/versions/*",
185+
# ]
186186
reportGeneralTypeIssues = "none"
187187
reportUnboundVariable = "none"
188188
reportFunctionMemberAccess = "none"

0 commit comments

Comments
 (0)