feat(auth): add created_at and updated_at in OAuthToken

resolve #78
This commit is contained in:
MingxuanGame
2025-11-23 13:56:28 +00:00
parent e049056534
commit 7b34bd8b0b
3 changed files with 58 additions and 24 deletions

View File

@@ -0,0 +1,41 @@
"""oauth-client: add date
Revision ID: 57641cb601f4
Revises: 23707640303c
Create Date: 2025-11-23 13:46:55.654967
"""
from collections.abc import Sequence
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = "57641cb601f4"
down_revision: str | Sequence[str] | None = "23707640303c"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None
def upgrade() -> None:
"""Upgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.add_column("oauth_clients", sa.Column("created_at", sa.DateTime(), nullable=True))
op.add_column(
"oauth_clients", sa.Column("updated_at", sa.DateTime(), nullable=True, onupdate=sa.text("CURRENT_TIMESTAMP"))
)
op.execute(
"UPDATE oauth_clients SET created_at = NOW(), updated_at = NOW() WHERE created_at IS NULL OR updated_at IS NULL"
)
op.alter_column("oauth_clients", "created_at", existing_type=sa.DateTime(), nullable=False)
op.alter_column("oauth_clients", "updated_at", existing_type=sa.DateTime(), nullable=False)
# ### end Alembic commands ###
def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column("oauth_clients", "updated_at")
op.drop_column("oauth_clients", "created_at")
# ### end Alembic commands ###