"""Add users.locked + locked_at for permanent account lockout

Revision ID: 037
Revises: 036
Create Date: 2026-07-13 12:00:00.000000

Permanent-lockout mode (opt-in via the auth_lockout_permanent setting): after
the failed-attempt threshold an account is locked until an admin clears it
(post-incident), instead of the temporary 15-minute auto-unlock. The last
active admin is never permanently locked (recoverable via the temporary path)
so the system can't be fully locked out.

Idempotent.
"""
from alembic import op


revision = "037"
down_revision = "036"
branch_labels = None
depends_on = None


def upgrade() -> None:
    op.execute("ALTER TABLE users ADD COLUMN IF NOT EXISTS locked BOOLEAN NOT NULL DEFAULT FALSE;")
    op.execute("ALTER TABLE users ADD COLUMN IF NOT EXISTS locked_at TIMESTAMP NULL;")


def downgrade() -> None:
    op.execute("ALTER TABLE users DROP COLUMN IF EXISTS locked_at;")
    op.execute("ALTER TABLE users DROP COLUMN IF EXISTS locked;")
