Skip to content

Commit

Permalink
feat: Add migration to correct last_status_change for expired users (#…
Browse files Browse the repository at this point in the history
…1187)

* feat: Add migration to correct last_status_change for expired users.

* add check expire not NULL

---------

Co-authored-by: Mohammad <[email protected]>
  • Loading branch information
Alirezaja1384 and ImMohammad20000 authored Dec 1, 2024
1 parent 3f8f4af commit 8346ce4
Showing 1 changed file with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""last_status_change_for_expired_users
Revision ID: 54c4b8c525fc
Revises: 2313cdc30da3
Create Date: 2024-07-25 11:15:51.776880
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '54c4b8c525fc'
down_revision = '2313cdc30da3'
branch_labels = None
depends_on = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
bind = op.get_bind()
if bind.engine.name == "mysql":
op.execute("UPDATE users SET last_status_change=FROM_UNIXTIME(expire) WHERE status='expired' AND expire is not NULL")
else:
op.execute("UPDATE users SET last_status_change=DATETIME(expire, 'unixepoch') WHERE status='expired' AND expire is not NULL")
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.execute("UPDATE users SET last_status_change=CURRENT_TIMESTAMP WHERE status='expired' AND expire is not NULL")
# ### end Alembic commands ###

0 comments on commit 8346ce4

Please sign in to comment.