Skip to content

Commit

Permalink
Make Service.desc nullable and optional
Browse files Browse the repository at this point in the history
Signed-off-by: Aurélien Bompard <[email protected]>
  • Loading branch information
abompard committed Aug 22, 2024
1 parent 9ef7a8c commit f38facb
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 9 deletions.
12 changes: 6 additions & 6 deletions webhook_to_fedora_messaging/endpoints/models/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ServiceBase(BaseModel, ABC):
uuid: str
name: str
type: ServiceType
desc: str
desc: str | None = None
token: str
creation_date: datetime

Expand All @@ -52,7 +52,7 @@ class ServiceRequestMain(BaseModel):
model_config = ConfigDict(extra="forbid")
name: str
type: ServiceType
desc: Optional[str]
desc: Optional[str] = None


class ServiceRequest(BaseModel):
Expand All @@ -61,10 +61,10 @@ class ServiceRequest(BaseModel):

class ServiceUpdateMain(BaseModel):
model_config = ConfigDict(extra="forbid")
name: Optional[str] = ""
type: Optional[str] = ""
desc: Optional[str] = ""
username: Optional[str] = ""
name: Optional[str] = None
type: Optional[str] = None
desc: Optional[str] = None
username: Optional[str] = None


class ServiceUpdate(BaseModel):
Expand Down
4 changes: 2 additions & 2 deletions webhook_to_fedora_messaging/endpoints/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ async def update_service(
Update the service with the specified UUID
"""
for attr in ("name", "type", "desc"):
data = getattr(body.data, attr).strip()
data = getattr(body.data, attr)
if not data:
continue
setattr(service, attr, data)

if body.data.username.strip() != "":
if body.data.username:
query = select(User).filter_by(name=body.data.username)
result = await session.execute(query)
try:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# SPDX-FileCopyrightText: Contributors to the Fedora Project
#
# SPDX-License-Identifier: GPL-3.0-or-later

"""Service.desc can be null
Revision ID: 4f1f49d72fa8
Revises: 6c01198723a8
Create Date: 2024-08-22 11:29:19.880261
"""
import sqlalchemy as sa
from alembic import op
from sqlalchemy_helpers.manager import is_sqlite


# revision identifiers, used by Alembic.
revision = "4f1f49d72fa8"
down_revision = "6c01198723a8"
branch_labels = None
depends_on = None


def upgrade():
connection = op.get_bind()
if is_sqlite(connection):
connection.execute(sa.text("PRAGMA foreign_keys=OFF"))
with op.batch_alter_table("services") as batch_op:
batch_op.alter_column("desc", existing_type=sa.TEXT(), nullable=True)


def downgrade():
connection = op.get_bind()
if is_sqlite(connection):
connection.execute(sa.text("PRAGMA foreign_keys=OFF"))
with op.batch_alter_table("services") as batch_op:
batch_op.alter_column("desc", existing_type=sa.TEXT(), nullable=False)
2 changes: 1 addition & 1 deletion webhook_to_fedora_messaging/models/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Service(Base, UUIDCreatableMixin, CreatableMixin):
token = Column(UnicodeText, unique=False, nullable=False, default=uuid4().hex)
name = Column(UnicodeText, nullable=False)
type = Column(UnicodeText, nullable=False)
desc = Column(UnicodeText, nullable=False)
desc = Column(UnicodeText, nullable=True)
disabled = Column(Boolean, nullable=False, default=False)
sent = Column(Integer, nullable=False, default=0)
users = relationship("User", secondary=owners_table, back_populates="services")

0 comments on commit f38facb

Please sign in to comment.