Files
gh-christianlouis-docuelevate/migrations/versions/038_add_api_token_expires_at.py
T
copilot-swe-agent[bot] 11a49eb7fd fix(migrations): restore accidentally deleted migration files 038-042
Migration files 038-042 were accidentally deleted by commit d2217531
("Sentinel: Fix SSRF in IMAP connections"), which broke container
startup because existing databases had alembic_version stamped to
042_add_file_shares — a revision Alembic could no longer find.

Restored from the parent of that commit:
- 038_add_api_token_expires_at.py
- 039_add_classification_rules.py
- 040_add_automation_hooks.py
- 041_add_document_comments_and_annotations.py
- 042_add_file_shares.py

Alembic now resolves a clean single-head chain (001→042).

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
Agent-Logs-Url: https://github.com/christianlouis/DocuElevate/sessions/f6165a49-2ec0-4158-9f1f-d508bb0489fe
2026-03-23 23:36:45 +00:00

44 lines
1.4 KiB
Python

"""Add expires_at column to api_tokens table.
Allows API tokens to be issued with an optional lifetime. If ``expires_at``
is set, the token is automatically rejected after that timestamp.
Revision ID: 038_add_api_token_expires_at
Revises: 037_add_user_sessions_and_qr_challenges
Create Date: 2026-03-18
"""
from typing import Union
import sqlalchemy as sa
from alembic import op
revision: str = "038_add_api_token_expires_at"
down_revision: Union[str, None] = "037_add_user_sessions_and_qr_challenges"
depends_on: Union[str, None] = None
def upgrade() -> None:
"""Add expires_at column to api_tokens (idempotent)."""
conn = op.get_bind()
inspector = sa.inspect(conn)
if "api_tokens" not in inspector.get_table_names():
return
existing_columns = {col["name"] for col in inspector.get_columns("api_tokens")}
if "expires_at" not in existing_columns:
op.add_column(
"api_tokens",
sa.Column("expires_at", sa.DateTime(timezone=True), nullable=True),
)
def downgrade() -> None:
"""Remove expires_at column from api_tokens."""
conn = op.get_bind()
inspector = sa.inspect(conn)
if "api_tokens" not in inspector.get_table_names():
return
existing_columns = {col["name"] for col in inspector.get_columns("api_tokens")}
if "expires_at" in existing_columns:
op.drop_column("api_tokens", "expires_at")