M4-T01: add auth_login_throttle table + LoginThrottle model
This commit is contained in:
@@ -7,6 +7,7 @@ from app.config import get_settings
|
||||
from app.db import Base
|
||||
from app.models.config import AppConfigEntry # noqa: F401
|
||||
from app.models.auth import AuthSession, AuthUser # noqa: F401
|
||||
from app.models.auth_throttle import LoginThrottle # noqa: F401
|
||||
from app.models.public_ip import PublicIPHistory, PublicIPState # noqa: F401
|
||||
from app.models.location import Location # noqa: F401
|
||||
from app.models.poo import PooRecord # noqa: F401
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
"""add auth_login_throttle table for exponential back-off throttling
|
||||
|
||||
Revision ID: 20260621_07_auth_login_throttle
|
||||
Revises: 20260611_06_merge_location_poo_tables
|
||||
Create Date: 2026-06-21 00:00:00.000000
|
||||
"""
|
||||
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
revision: str = "20260621_07_auth_login_throttle"
|
||||
down_revision: Union[str, None] = "20260611_06_merge_location_poo_tables"
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.create_table(
|
||||
"auth_login_throttle",
|
||||
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
|
||||
sa.Column("key", sa.String(length=255), nullable=False),
|
||||
sa.Column("scope", sa.String(length=16), nullable=False),
|
||||
sa.Column("failures", sa.Integer(), nullable=False),
|
||||
sa.Column("first_failed_at", sa.DateTime(timezone=True), nullable=False),
|
||||
sa.Column("last_failed_at", sa.DateTime(timezone=True), nullable=False),
|
||||
sa.Column("next_allowed_at", sa.DateTime(timezone=True), nullable=True),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
sa.UniqueConstraint("scope", "key", name="uq_auth_login_throttle_scope_key"),
|
||||
)
|
||||
op.create_index(
|
||||
"ix_auth_login_throttle_scope_key",
|
||||
"auth_login_throttle",
|
||||
["scope", "key"],
|
||||
unique=False,
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_index("ix_auth_login_throttle_scope_key", table_name="auth_login_throttle")
|
||||
op.drop_table("auth_login_throttle")
|
||||
Reference in New Issue
Block a user