diff --git a/migrations/versions/2025_05_01_1917-736fb0c10480_update_empty_provider_endpoint_names_.py b/migrations/versions/2025_05_01_1917-736fb0c10480_update_empty_provider_endpoint_names_.py new file mode 100644 index 000000000..1be3748e8 --- /dev/null +++ b/migrations/versions/2025_05_01_1917-736fb0c10480_update_empty_provider_endpoint_names_.py @@ -0,0 +1,39 @@ +"""Update empty provider endpoint names with placeholders + +Revision ID: 736fb0c10480 +Revises: e4c05d7591a8 +Create Date: 2025-05-01 19:17:41.766575 + +""" + +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision: str = "736fb0c10480" +down_revision: Union[str, None] = "e4c05d7591a8" +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.execute( + """ + UPDATE provider_endpoints + SET name = 'placeholder_' || id + WHERE name = '' + """ + ) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + # Downgrading is complex as we don't know which names were placeholders. + # We'll leave this empty, assuming the model validation change is permanent. + pass + # ### end Alembic commands ### diff --git a/src/codegate/api/v1_models.py b/src/codegate/api/v1_models.py index 97ece660e..fc159aa83 100644 --- a/src/codegate/api/v1_models.py +++ b/src/codegate/api/v1_models.py @@ -1,9 +1,10 @@ import datetime import json from enum import Enum -from typing import Any, Dict, List, Optional, Union +from typing import Annotated, Any, Dict, List, Optional, Union import pydantic +from pydantic import Field import codegate.muxing.models as mux_models from codegate.db import models as db_models @@ -268,7 +269,7 @@ class ProviderEndpoint(pydantic.BaseModel): # This will be set on creation id: Optional[str] = "" - name: str + name: Annotated[str, Field(min_length=3)] description: str = "" provider_type: db_models.ProviderType endpoint: str = "" # Some providers have defaults we can leverage