Skip to content

Commit

Permalink
server: upgrade CITEXT usage
Browse files Browse the repository at this point in the history
  • Loading branch information
frankie567 committed Oct 29, 2024
1 parent f347aa5 commit 7af8817
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import enum

import citext
import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"""

import citext
import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql
Expand All @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"""

import citext
import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql
Expand Down Expand Up @@ -48,7 +47,7 @@ def upgrade() -> None:
"organizations",
"name",
new_column_name="slug",
existing_type=citext.CIText(),
existing_type=postgresql.CITEXT(),
existing_nullable=False,
)

Expand Down Expand Up @@ -147,7 +146,7 @@ def downgrade() -> None:
"organizations",
"slug",
new_column_name="name",
existing_type=citext.CIText(),
existing_type=postgresql.CITEXT(),
existing_nullable=False,
)

Expand Down
5 changes: 2 additions & 3 deletions server/polar/models/external_organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from typing import TYPE_CHECKING
from uuid import UUID

from citext import CIText
from sqlalchemy import (
TIMESTAMP,
BigInteger,
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions server/polar/models/organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from typing import Any
from uuid import UUID

from citext import CIText
from sqlalchemy import (
TIMESTAMP,
Boolean,
Expand All @@ -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
Expand All @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions server/polar/models/product.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from typing import TYPE_CHECKING
from uuid import UUID

from citext import CIText
from sqlalchemy import (
Boolean,
ColumnElement,
Expand All @@ -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
Expand All @@ -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)

Expand Down
5 changes: 2 additions & 3 deletions server/polar/models/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from typing import Any
from uuid import UUID

from citext import CIText
from sqlalchemy import (
TIMESTAMP,
BigInteger,
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion server/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 0 additions & 10 deletions server/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7af8817

Please sign in to comment.