fix: jsonb -> json for sqlite compatibility (#1095)

This commit is contained in:
cthomas
2025-02-21 12:06:53 -08:00
committed by GitHub
parent 1970868594
commit 6ad423d006
2 changed files with 63 additions and 3 deletions

View File

@@ -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 ###

View File

@@ -2,7 +2,7 @@ import uuid
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
@@ -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,
),
)
@@ -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