Skip to content

Commit

Permalink
fix: jsonb -> json for sqlite compatibility (#1095)
Browse files Browse the repository at this point in the history
  • Loading branch information
carenthomas authored Feb 21, 2025
1 parent 0d9ff8a commit 3b742b8
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 3 deletions.
60 changes: 60 additions & 0 deletions alembic/versions/fdcdafdb11cf_identity_properties_jsonb_to_json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
"""identity properties jsonb to json
Revision ID: fdcdafdb11cf
Revises: 549eff097c71
Create Date: 2025-02-21 10:30:49.937854
"""

from typing import Sequence, Union

import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

from alembic import op

# revision identifiers, used by Alembic.
revision: str = "fdcdafdb11cf"
down_revision: Union[str, None] = "549eff097c71"
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.alter_column(
"identities",
"properties",
existing_type=postgresql.JSONB(astext_type=sa.Text()),
type_=postgresql.JSON(astext_type=sa.Text()),
existing_nullable=False,
existing_server_default=sa.text("'[]'::jsonb"),
)
op.drop_constraint("unique_identifier_without_project", "identities", type_="unique")
op.create_unique_constraint(
"unique_identifier_key_project_id_organization_id",
"identities",
["identifier_key", "project_id", "organization_id"],
postgresql_nulls_not_distinct=True,
)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint("unique_identifier_key_project_id_organization_id", "identities", type_="unique")
op.create_unique_constraint(
"unique_identifier_without_project",
"identities",
["identifier_key", "project_id", "organization_id"],
postgresql_nulls_not_distinct=True,
)
op.alter_column(
"identities",
"properties",
existing_type=postgresql.JSON(astext_type=sa.Text()),
type_=postgresql.JSONB(astext_type=sa.Text()),
existing_nullable=False,
existing_server_default=sa.text("'[]'::jsonb"),
)
# ### end Alembic commands ###
6 changes: 3 additions & 3 deletions letta/orm/identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import List, Optional

from sqlalchemy import String, UniqueConstraint
from sqlalchemy.dialects.postgresql import JSONB
from sqlalchemy.dialects.postgresql import JSON
from sqlalchemy.orm import Mapped, mapped_column, relationship

from letta.orm.mixins import OrganizationMixin
Expand All @@ -21,7 +21,7 @@ class Identity(SqlalchemyBase, OrganizationMixin):
"identifier_key",
"project_id",
"organization_id",
name="unique_identifier_without_project",
name="unique_identifier_key_project_id_organization_id",
postgresql_nulls_not_distinct=True,
),
)
Expand All @@ -32,7 +32,7 @@ class Identity(SqlalchemyBase, OrganizationMixin):
identity_type: Mapped[str] = mapped_column(nullable=False, doc="The type of the identity.")
project_id: Mapped[Optional[str]] = mapped_column(nullable=True, doc="The project id of the identity.")
properties: Mapped[List["IdentityProperty"]] = mapped_column(
JSONB, nullable=False, default=list, doc="List of properties associated with the identity"
JSON, nullable=False, default=list, doc="List of properties associated with the identity"
)

# relationships
Expand Down

0 comments on commit 3b742b8

Please sign in to comment.