Last Updated: April 27, 2016
· davur

Temporarily "disable" all users in Django

-- Temporarily "disable" all users by changing their username

-- Choose and check if prefix exists (choose another if any matches found)
select count(1) from auth_user where username 'DIS_%';

-- "DISABLE" all users temporarily (be aware that long usernames would get truncated)
update auth_user set username = concat('DIS_', username) where LENGTH(username) <= 25;

-- "ENABLE" affected users
update auth_user set username = substring(username, 5) where username like 'DIS_%';

-- Log out users currently logged in
update django_session set expire_date = NOW() where expire_date < NOW();

I had to strong arm a customer that was way behind on their payments. "Your last bill hasn't overdue", "Your last 3 months bills are overdue" didn't have the desired effect. Neither did the threat "Pay up or we will shut down the servers". Knowing that they still used the service and would pay up eventually if they lost access I didn't want to shut down the service and that shutting down the service wasn't really an option for reasons.

Note: "Pro Tip" may not be the best title here, but I just wanted to store this hint for posterity, in case I ever need it again.

Say Thanks