CREATE TABLE login_attempts ( ip_hash CHAR(64) NOT NULL CHECK (ip_hash ~ '^[a-f0-9]{64}$'), attempted_at TIMESTAMPTZ NOT NULL DEFAULT now() ); CREATE INDEX login_attempts_recent_idx ON login_attempts (ip_hash, attempted_at DESC);