From 7af8817907a4041b2e23a342722e16d6a1f0ecea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Voron?= Date: Tue, 29 Oct 2024 09:13:19 +0100 Subject: [PATCH] server: upgrade CITEXT usage --- .../versions/2024-06-06-1059_initial_migration.py | 7 +++---- .../2024-07-15-1335_create_externalorganization.py | 3 +-- .../2024-07-16-1104_link_externalorganization_to_.py | 5 ++--- server/polar/models/external_organization.py | 5 ++--- server/polar/models/organization.py | 5 ++--- server/polar/models/product.py | 4 ++-- server/polar/models/repository.py | 5 ++--- server/pyproject.toml | 1 - server/uv.lock | 10 ---------- 9 files changed, 14 insertions(+), 31 deletions(-) diff --git a/server/migrations/versions/2024-06-06-1059_initial_migration.py b/server/migrations/versions/2024-06-06-1059_initial_migration.py index 5420de8c21..9d84026817 100644 --- a/server/migrations/versions/2024-06-06-1059_initial_migration.py +++ b/server/migrations/versions/2024-06-06-1059_initial_migration.py @@ -8,7 +8,6 @@ import enum -import citext import sqlalchemy as sa from alembic import op from sqlalchemy.dialects import postgresql @@ -91,7 +90,7 @@ def upgrade() -> None: StringEnum(Platforms), nullable=False, ), - sa.Column("name", citext.CIText(), nullable=False), + sa.Column("name", postgresql.CITEXT(), nullable=False), sa.Column("external_id", sa.BigInteger(), nullable=False), sa.Column("avatar_url", sa.String(), nullable=False), sa.Column("is_personal", sa.Boolean(), nullable=False), @@ -825,7 +824,7 @@ def upgrade() -> None: ) op.create_table( "products", - sa.Column("name", citext.CIText(), nullable=False), + sa.Column("name", postgresql.CITEXT(), nullable=False), sa.Column("description", sa.Text(), nullable=True), sa.Column("is_archived", sa.Boolean(), nullable=False), sa.Column("type", sa.String(), nullable=True), @@ -878,7 +877,7 @@ def upgrade() -> None: ), sa.Column("external_id", sa.BigInteger(), nullable=False), sa.Column("organization_id", sa.UUID(), nullable=False), - sa.Column("name", citext.CIText(), nullable=False), + sa.Column("name", postgresql.CITEXT(), nullable=False), sa.Column("description", sa.Text(), nullable=True), sa.Column("open_issues", sa.Integer(), nullable=True), sa.Column("forks", sa.Integer(), nullable=True), diff --git a/server/migrations/versions/2024-07-15-1335_create_externalorganization.py b/server/migrations/versions/2024-07-15-1335_create_externalorganization.py index b6f4cedfb7..e9c310fb42 100644 --- a/server/migrations/versions/2024-07-15-1335_create_externalorganization.py +++ b/server/migrations/versions/2024-07-15-1335_create_externalorganization.py @@ -6,7 +6,6 @@ """ -import citext import sqlalchemy as sa from alembic import op from sqlalchemy.dialects import postgresql @@ -28,7 +27,7 @@ def upgrade() -> None: op.create_table( "external_organizations", sa.Column("platform", StringEnum(Platforms), nullable=False), - sa.Column("name", citext.CIText(), nullable=False), + sa.Column("name", postgresql.CITEXT(), nullable=False), sa.Column("external_id", sa.BigInteger(), nullable=False), sa.Column("avatar_url", sa.String(), nullable=False), sa.Column("is_personal", sa.Boolean(), nullable=False), diff --git a/server/migrations/versions/2024-07-16-1104_link_externalorganization_to_.py b/server/migrations/versions/2024-07-16-1104_link_externalorganization_to_.py index 7b7c800553..6ceab0b84f 100644 --- a/server/migrations/versions/2024-07-16-1104_link_externalorganization_to_.py +++ b/server/migrations/versions/2024-07-16-1104_link_externalorganization_to_.py @@ -6,7 +6,6 @@ """ -import citext import sqlalchemy as sa from alembic import op from sqlalchemy.dialects import postgresql @@ -48,7 +47,7 @@ def upgrade() -> None: "organizations", "name", new_column_name="slug", - existing_type=citext.CIText(), + existing_type=postgresql.CITEXT(), existing_nullable=False, ) @@ -147,7 +146,7 @@ def downgrade() -> None: "organizations", "slug", new_column_name="name", - existing_type=citext.CIText(), + existing_type=postgresql.CITEXT(), existing_nullable=False, ) diff --git a/server/polar/models/external_organization.py b/server/polar/models/external_organization.py index bbd6ff4bd7..b2e72a6784 100644 --- a/server/polar/models/external_organization.py +++ b/server/polar/models/external_organization.py @@ -2,7 +2,6 @@ from typing import TYPE_CHECKING from uuid import UUID -from citext import CIText from sqlalchemy import ( TIMESTAMP, BigInteger, @@ -13,7 +12,7 @@ UniqueConstraint, Uuid, ) -from sqlalchemy.dialects.postgresql import JSONB +from sqlalchemy.dialects.postgresql import CITEXT, JSONB from sqlalchemy.orm import Mapped, declared_attr, mapped_column, relationship from polar.enums import Platforms @@ -56,7 +55,7 @@ def organization(cls) -> Mapped["Organization | None"]: return relationship("Organization", lazy="raise") platform: Mapped[Platforms] = mapped_column(StringEnum(Platforms), nullable=False) - name: Mapped[str] = mapped_column(CIText(), nullable=False, unique=True) + name: Mapped[str] = mapped_column(CITEXT(), nullable=False, unique=True) external_id: Mapped[int] = mapped_column(BigInteger, nullable=False, unique=True) avatar_url: Mapped[str] = mapped_column(String, nullable=False) is_personal: Mapped[bool] = mapped_column(Boolean, nullable=False) diff --git a/server/polar/models/organization.py b/server/polar/models/organization.py index 409f31b518..1778d2325c 100644 --- a/server/polar/models/organization.py +++ b/server/polar/models/organization.py @@ -2,7 +2,6 @@ from typing import Any from uuid import UUID -from citext import CIText from sqlalchemy import ( TIMESTAMP, Boolean, @@ -12,7 +11,7 @@ UniqueConstraint, Uuid, ) -from sqlalchemy.dialects.postgresql import JSONB +from sqlalchemy.dialects.postgresql import CITEXT, JSONB from sqlalchemy.orm import Mapped, declared_attr, mapped_column, relationship from polar.config import settings @@ -26,7 +25,7 @@ class Organization(RecordModel): __table_args__ = (UniqueConstraint("slug"),) name: Mapped[str] = mapped_column(String, nullable=False, index=True) - slug: Mapped[str] = mapped_column(CIText(), nullable=False, unique=True) + slug: Mapped[str] = mapped_column(CITEXT, nullable=False, unique=True) avatar_url: Mapped[str | None] = mapped_column(String, nullable=True) account_id: Mapped[UUID | None] = mapped_column( diff --git a/server/polar/models/product.py b/server/polar/models/product.py index d836e9ddf5..492c285553 100644 --- a/server/polar/models/product.py +++ b/server/polar/models/product.py @@ -1,7 +1,6 @@ from typing import TYPE_CHECKING from uuid import UUID -from citext import CIText from sqlalchemy import ( Boolean, ColumnElement, @@ -11,6 +10,7 @@ Uuid, select, ) +from sqlalchemy.dialects.postgresql import CITEXT from sqlalchemy.ext.associationproxy import AssociationProxy, association_proxy from sqlalchemy.ext.hybrid import hybrid_property from sqlalchemy.orm import Mapped, declared_attr, mapped_column, relationship @@ -28,7 +28,7 @@ class Product(RecordModel): __tablename__ = "products" - name: Mapped[str] = mapped_column(CIText(), nullable=False) + name: Mapped[str] = mapped_column(CITEXT(), nullable=False) description: Mapped[str | None] = mapped_column(Text, nullable=True) is_archived: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False) diff --git a/server/polar/models/repository.py b/server/polar/models/repository.py index 94c66b4ebd..e0fd9cdd28 100644 --- a/server/polar/models/repository.py +++ b/server/polar/models/repository.py @@ -2,7 +2,6 @@ from typing import Any from uuid import UUID -from citext import CIText from sqlalchemy import ( TIMESTAMP, BigInteger, @@ -15,7 +14,7 @@ UniqueConstraint, Uuid, ) -from sqlalchemy.dialects.postgresql import JSONB +from sqlalchemy.dialects.postgresql import CITEXT, JSONB from sqlalchemy.orm import Mapped, declared_attr, mapped_column, relationship from polar.config import settings @@ -44,7 +43,7 @@ class Repository(RecordModel): def organization(cls) -> Mapped[ExternalOrganization]: return relationship(ExternalOrganization, lazy="raise") - name: Mapped[str] = mapped_column(CIText(), nullable=False) + name: Mapped[str] = mapped_column(CITEXT(), nullable=False) description: Mapped[str | None] = mapped_column(Text, nullable=True) open_issues: Mapped[int | None] = mapped_column(Integer, nullable=True) diff --git a/server/pyproject.toml b/server/pyproject.toml index c0625cfc27..db625302b0 100644 --- a/server/pyproject.toml +++ b/server/pyproject.toml @@ -22,7 +22,6 @@ dependencies = [ "sentry-sdk[fastapi,sqlalchemy]>=2.16.0", "discord-webhook[async]==1.3.0", "posthog>=3.6.0", - "sqlalchemy-citext @ git+https://github.com/akolov/sqlalchemy-citext.git@15b3de84730bb4645c83d890a73f5c9b6b289531", "python-slugify>=8.0.1", "resend>=2.4.0", "python-multipart>=0.0.12", diff --git a/server/uv.lock b/server/uv.lock index a0b1996818..6776acdb51 100644 --- a/server/uv.lock +++ b/server/uv.lock @@ -1190,7 +1190,6 @@ dependencies = [ { name = "safe-redirect-url" }, { name = "sentry-sdk", extra = ["fastapi", "sqlalchemy"] }, { name = "sqlalchemy", extra = ["asyncio"] }, - { name = "sqlalchemy-citext" }, { name = "sqlalchemy-utils" }, { name = "sse-starlette" }, { name = "standardwebhooks" }, @@ -1273,7 +1272,6 @@ requires-dist = [ { name = "safe-redirect-url", specifier = ">=0.1.1" }, { name = "sentry-sdk", extras = ["fastapi", "sqlalchemy"], specifier = ">=2.16.0" }, { name = "sqlalchemy", extras = ["asyncio"], specifier = ">=2.0.34" }, - { name = "sqlalchemy-citext", git = "https://github.com/akolov/sqlalchemy-citext.git?rev=15b3de84730bb4645c83d890a73f5c9b6b289531#15b3de84730bb4645c83d890a73f5c9b6b289531" }, { name = "sqlalchemy-utils", specifier = ">=0.41.1" }, { name = "sse-starlette", specifier = ">=2.0.0" }, { name = "standardwebhooks", specifier = ">=1.0.0" }, @@ -1935,14 +1933,6 @@ asyncio = [ { name = "greenlet" }, ] -[[package]] -name = "sqlalchemy-citext" -version = "1.8.0" -source = { git = "https://github.com/akolov/sqlalchemy-citext.git?rev=15b3de84730bb4645c83d890a73f5c9b6b289531#15b3de84730bb4645c83d890a73f5c9b6b289531" } -dependencies = [ - { name = "sqlalchemy" }, -] - [[package]] name = "sqlalchemy-utils" version = "0.41.2"