From 3c6176b7b4920c88a99f4443c4836fbc79640657 Mon Sep 17 00:00:00 2001 From: ytqh Date: Sat, 8 Mar 2025 16:23:37 +0800 Subject: [PATCH] add fields on end user --- ...b3b2ce369_add_memory_fields_to_end_user.py | 35 +++++++++++++++++++ api/models/model.py | 2 ++ 2 files changed, 37 insertions(+) create mode 100644 api/migrations/versions/2025_03_08_1621-0dab3b2ce369_add_memory_fields_to_end_user.py diff --git a/api/migrations/versions/2025_03_08_1621-0dab3b2ce369_add_memory_fields_to_end_user.py b/api/migrations/versions/2025_03_08_1621-0dab3b2ce369_add_memory_fields_to_end_user.py new file mode 100644 index 0000000000..a4f22b5c5c --- /dev/null +++ b/api/migrations/versions/2025_03_08_1621-0dab3b2ce369_add_memory_fields_to_end_user.py @@ -0,0 +1,35 @@ +"""add memory fields to end user + +Revision ID: 0dab3b2ce369 +Revises: c11c071cf21e +Create Date: 2025-03-08 16:21:08.903178 + +""" +from alembic import op +import models as models +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '0dab3b2ce369' +down_revision = 'c11c071cf21e' +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('memory', sa.Text(), nullable=True)) + batch_op.add_column(sa.Column('memory_updated_at', sa.DateTime(), nullable=True)) + + # ### 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.drop_column('memory_updated_at') + batch_op.drop_column('memory') + + # ### end Alembic commands ### diff --git a/api/models/model.py b/api/models/model.py index 9616d8c182..e9c0a1c662 100644 --- a/api/models/model.py +++ b/api/models/model.py @@ -1324,6 +1324,8 @@ class EndUser(UserMixin, db.Model): # type: ignore[name-defined] session_id: Mapped[str] = mapped_column() gender = db.Column(db.Integer, nullable=False, server_default=db.text("0")) # 0: unknown, 1: male, 2: female extra_profile = db.Column(db.JSON, nullable=True) # JSON format, e.g. { "major":"engineer" } + 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 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())