diff --git a/api/migrations/versions/2025_03_16_1200-ceaf4dfed584_change_memory_into_extrac_profile_and_.py b/api/migrations/versions/2025_03_16_1200-ceaf4dfed584_change_memory_into_extrac_profile_and_.py new file mode 100644 index 0000000000..e4c1d89d5f --- /dev/null +++ b/api/migrations/versions/2025_03_16_1200-ceaf4dfed584_change_memory_into_extrac_profile_and_.py @@ -0,0 +1,37 @@ +"""change memory into extrac profile, and use same update_at for all profile update + +Revision ID: ceaf4dfed584 +Revises: 78d1c56fd608 +Create Date: 2025-03-16 12:00:20.875506 + +""" +from alembic import op +import models as models +import sqlalchemy as sa +from sqlalchemy.dialects import postgresql + +# revision identifiers, used by Alembic. +revision = 'ceaf4dfed584' +down_revision = '78d1c56fd608' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('end_users', schema=None) as batch_op: + batch_op.add_column(sa.Column('profile_updated_at', sa.DateTime(), nullable=True)) + batch_op.drop_column('memory') + batch_op.drop_column('memory_updated_at') + + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('end_users', schema=None) as batch_op: + batch_op.add_column(sa.Column('memory_updated_at', postgresql.TIMESTAMP(), autoincrement=False, nullable=True)) + batch_op.add_column(sa.Column('memory', sa.TEXT(), autoincrement=False, nullable=True)) + batch_op.drop_column('profile_updated_at') + + # ### end Alembic commands ### diff --git a/api/models/model.py b/api/models/model.py index 4ad5025fea..21b3d86c4a 100644 --- a/api/models/model.py +++ b/api/models/model.py @@ -1323,15 +1323,20 @@ class EndUser(UserMixin, db.Model): # type: ignore[name-defined] is_anonymous = db.Column(db.Boolean, nullable=False, server_default=db.text("true")) session_id: Mapped[str] = mapped_column() gender = db.Column(db.Integer, nullable=False, server_default=db.text("0")) # 0: unknown, 1: male, 2: female - memory = db.Column(db.Text, nullable=True) # Long text to store user memory" - memory_updated_at = db.Column(db.DateTime, nullable=True) # To record when memory was last updated + profile_updated_at = db.Column(db.DateTime, nullable=True) # To record when profile was last updated health_status = db.Column(db.String(255), nullable=True) # Only accept for "normal", "potential", "critical" extra_profile = db.Column( db.JSON, nullable=True - ) # JSON format, e.g. { "major":"engineer", "topics":["math", "physics"], "summary": "This is a summary of the user's profile"} + ) # JSON format, e.g. { "major":"engineer", "topics":["math", "physics"], "summary": "This is a summary of the user's profile", "memory": "This is the user's memory"} created_at = db.Column(db.DateTime, nullable=False, server_default=func.current_timestamp()) updated_at = db.Column(db.DateTime, nullable=False, server_default=func.current_timestamp()) + @property + def memory(self): + if self.extra_profile is None: + return None + return self.extra_profile.get("memory") + @property def account(self): return db.session.query(Account).filter(Account.id == self.external_user_id).first()