updated active user db model w/ burnettk

This commit is contained in:
jasquat 2023-05-04 12:51:15 -04:00
parent 92cdceb201
commit 699c3eb619
3 changed files with 10 additions and 6 deletions

View File

@ -1,8 +1,8 @@
"""empty message """empty message
Revision ID: a41f08815751 Revision ID: 6aa02463da9c
Revises: 68adb1d504e1 Revises: 68adb1d504e1
Create Date: 2023-05-03 16:51:35.252279 Create Date: 2023-05-04 12:50:07.979692
""" """
from alembic import op from alembic import op
@ -10,7 +10,7 @@ import sqlalchemy as sa
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = 'a41f08815751' revision = '6aa02463da9c'
down_revision = '68adb1d504e1' down_revision = '68adb1d504e1'
branch_labels = None branch_labels = None
depends_on = None depends_on = None
@ -22,12 +22,13 @@ def upgrade():
sa.Column('id', sa.Integer(), nullable=False), sa.Column('id', sa.Integer(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=False), sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('last_visited_identifier', sa.String(length=255), nullable=False), sa.Column('last_visited_identifier', sa.String(length=255), nullable=False),
sa.Column('last_seen_in_seconds', sa.Integer(), nullable=True), sa.Column('last_seen_in_seconds', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
sa.PrimaryKeyConstraint('id'), sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('user_id', 'last_visited_identifier', name='user_last_visited_unique') sa.UniqueConstraint('user_id', 'last_visited_identifier', name='user_last_visited_unique')
) )
with op.batch_alter_table('active_user', schema=None) as batch_op: with op.batch_alter_table('active_user', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_active_user_last_seen_in_seconds'), ['last_seen_in_seconds'], unique=False)
batch_op.create_index(batch_op.f('ix_active_user_last_visited_identifier'), ['last_visited_identifier'], unique=False) batch_op.create_index(batch_op.f('ix_active_user_last_visited_identifier'), ['last_visited_identifier'], unique=False)
batch_op.create_index(batch_op.f('ix_active_user_user_id'), ['user_id'], unique=False) batch_op.create_index(batch_op.f('ix_active_user_user_id'), ['user_id'], unique=False)
@ -39,6 +40,7 @@ def downgrade():
with op.batch_alter_table('active_user', schema=None) as batch_op: with op.batch_alter_table('active_user', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_active_user_user_id')) batch_op.drop_index(batch_op.f('ix_active_user_user_id'))
batch_op.drop_index(batch_op.f('ix_active_user_last_visited_identifier')) batch_op.drop_index(batch_op.f('ix_active_user_last_visited_identifier'))
batch_op.drop_index(batch_op.f('ix_active_user_last_seen_in_seconds'))
op.drop_table('active_user') op.drop_table('active_user')
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -14,4 +14,4 @@ class ActiveUserModel(SpiffworkflowBaseDBModel):
id: int = db.Column(db.Integer, primary_key=True) id: int = db.Column(db.Integer, primary_key=True)
user_id: int = db.Column(ForeignKey(UserModel.id), nullable=False, index=True) # type: ignore user_id: int = db.Column(ForeignKey(UserModel.id), nullable=False, index=True) # type: ignore
last_visited_identifier: str = db.Column(db.String(255), nullable=False, index=True) last_visited_identifier: str = db.Column(db.String(255), nullable=False, index=True)
last_seen_in_seconds: int = db.Column(db.Integer) last_seen_in_seconds: int = db.Column(db.Integer, nullable=False, index=True)

View File

@ -18,7 +18,9 @@ def active_user_updates(last_visited_identifier: str) -> Response:
user_id=g.user.id, last_visited_identifier=last_visited_identifier user_id=g.user.id, last_visited_identifier=last_visited_identifier
).first() ).first()
if active_user is None: if active_user is None:
active_user = ActiveUserModel(user_id=g.user.id, last_visited_identifier=last_visited_identifier) active_user = ActiveUserModel(
user_id=g.user.id, last_visited_identifier=last_visited_identifier, last_seen_in_seconds=round(time.time())
)
db.session.add(active_user) db.session.add(active_user)
db.session.commit() db.session.commit()