Skip to content

armgit / letta

Public Imported from GitHub
0

Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.

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

cthomas6ad423d006d9
diff --git a/alembic/versions/fdcdafdb11cf_identity_properties_jsonb_to_json.py b/alembic/versions/fdcdafdb11cf_identity_properties_jsonb_to_json.py
new file mode 100644
index 000000000..c249f8807
--- /dev/null
+++ b/alembic/versions/fdcdafdb11cf_identity_properties_jsonb_to_json.py
@@ -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 ###
diff --git a/letta/orm/identity.py b/letta/orm/identity.py
index 1a8058e57..f92b053b2 100644
--- a/letta/orm/identity.py
+++ b/letta/orm/identity.py
@@ -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