Files
letta-server/alembic/versions/ee50a967e090_sync_migration_with_model_changes.py
Shubham Naik 564f0ace0f chore: Migrate database (#1974)
Co-authored-by: Shubham Naik <shub@memgpt.ai>
Co-authored-by: Matt Zhou <mattzh1314@gmail.com>
2024-11-03 11:17:49 -08:00

90 lines
5.1 KiB
Python

"""Sync migration with model changes
Revision ID: ee50a967e090
Revises: 0c315956709d
Create Date: 2024-11-01 19:18:39.399950
"""
from typing import Sequence, Union
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
import letta
from alembic import op
# revision identifiers, used by Alembic.
revision: str = "ee50a967e090"
down_revision: Union[str, None] = "0c315956709d"
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.add_column("agents", sa.Column("tool_rules", letta.metadata.ToolRulesColumn(), nullable=True))
op.add_column("organization", sa.Column("deleted", sa.Boolean(), nullable=False))
op.add_column("organization", sa.Column("updated_at", sa.DateTime(timezone=True), server_default=sa.text("now()"), nullable=True))
op.add_column("organization", sa.Column("is_deleted", sa.Boolean(), server_default=sa.text("FALSE"), nullable=False))
op.add_column("organization", sa.Column("_created_by_id", sa.String(), nullable=True))
op.add_column("organization", sa.Column("_last_updated_by_id", sa.String(), nullable=True))
op.add_column("tool", sa.Column("deleted", sa.Boolean(), nullable=False))
op.add_column("tool", sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.text("now()"), nullable=True))
op.add_column("tool", sa.Column("updated_at", sa.DateTime(timezone=True), server_default=sa.text("now()"), nullable=True))
op.add_column("tool", sa.Column("is_deleted", sa.Boolean(), server_default=sa.text("FALSE"), nullable=False))
op.add_column("tool", sa.Column("_created_by_id", sa.String(), nullable=True))
op.add_column("tool", sa.Column("_last_updated_by_id", sa.String(), nullable=True))
op.alter_column("tool", "tags", existing_type=postgresql.JSON(astext_type=sa.Text()), nullable=False)
op.alter_column("tool", "source_type", existing_type=sa.VARCHAR(), nullable=False)
op.alter_column("tool", "json_schema", existing_type=postgresql.JSON(astext_type=sa.Text()), nullable=False)
op.alter_column("tool", "_organization_id", existing_type=sa.VARCHAR(), nullable=False)
op.drop_constraint("uq_tool_name_organization", "tool", type_="unique")
op.create_unique_constraint("uix_name_organization", "tool", ["name", "_organization_id"])
op.create_foreign_key(None, "tool", "organization", ["_organization_id"], ["_id"])
op.drop_column("tool", "user_id")
op.add_column("user", sa.Column("deleted", sa.Boolean(), nullable=False))
op.add_column("user", sa.Column("updated_at", sa.DateTime(timezone=True), server_default=sa.text("now()"), nullable=True))
op.add_column("user", sa.Column("is_deleted", sa.Boolean(), server_default=sa.text("FALSE"), nullable=False))
op.add_column("user", sa.Column("_created_by_id", sa.String(), nullable=True))
op.add_column("user", sa.Column("_last_updated_by_id", sa.String(), nullable=True))
op.add_column("user", sa.Column("_organization_id", sa.String(), nullable=False))
op.create_foreign_key(None, "user", "organization", ["_organization_id"], ["_id"])
op.drop_column("user", "policies_accepted")
op.drop_column("user", "org_id")
# ### end Alembic commands ###
def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.add_column("user", sa.Column("org_id", sa.VARCHAR(), autoincrement=False, nullable=True))
op.add_column("user", sa.Column("policies_accepted", sa.BOOLEAN(), autoincrement=False, nullable=False))
op.drop_constraint(None, "user", type_="foreignkey")
op.drop_column("user", "_organization_id")
op.drop_column("user", "_last_updated_by_id")
op.drop_column("user", "_created_by_id")
op.drop_column("user", "is_deleted")
op.drop_column("user", "updated_at")
op.drop_column("user", "deleted")
op.add_column("tool", sa.Column("user_id", sa.VARCHAR(), autoincrement=False, nullable=True))
op.drop_constraint(None, "tool", type_="foreignkey")
op.drop_constraint("uix_name_organization", "tool", type_="unique")
op.create_unique_constraint("uq_tool_name_organization", "tool", ["name", "_organization_id"])
op.alter_column("tool", "_organization_id", existing_type=sa.VARCHAR(), nullable=True)
op.alter_column("tool", "json_schema", existing_type=postgresql.JSON(astext_type=sa.Text()), nullable=True)
op.alter_column("tool", "source_type", existing_type=sa.VARCHAR(), nullable=True)
op.alter_column("tool", "tags", existing_type=postgresql.JSON(astext_type=sa.Text()), nullable=True)
op.drop_column("tool", "_last_updated_by_id")
op.drop_column("tool", "_created_by_id")
op.drop_column("tool", "is_deleted")
op.drop_column("tool", "updated_at")
op.drop_column("tool", "created_at")
op.drop_column("tool", "deleted")
op.drop_column("organization", "_last_updated_by_id")
op.drop_column("organization", "_created_by_id")
op.drop_column("organization", "is_deleted")
op.drop_column("organization", "updated_at")
op.drop_column("organization", "deleted")
op.drop_column("agents", "tool_rules")
# ### end Alembic commands ###