I imported / migrated many users with bad / old / invalid email addresses


#1

I am looking to remove users that have never posted and haven’t been seen in a year for deactive users who has fake email. (I have imported from Mybb and so many users like that.)

Any ideas?


Bulk deactivate users with SQL query
Mailgun "temporarily disabled due to high bounce rate"
(Jeff Atwood) #2

You don’t need to remove them, just deactivate them. It’s a bad idea in general to migrate a bunch of ancient users and activate them all. You should only activate users who have posted in, say, the last year.

So the easy way is to run a SQL query that deactivates all users who haven’t posted in a year.

If the deactivated users have valid email addresses, they can always do a password reset to get back in.


#3

Yes, It makes more sense! Thank you for reply :slight_smile:

But i need SQL query for that. I dont know SQL.

I need SQL query that deactivates all users who haven’t posted in a year and haven’t been seen in a year. Anyone could help about that?


#4

User.where("user_stats.post_count = 0 AND last_seen_at <= '2016-01-01' AND active = true").update_all(active: false)

I write SQL query for that. Is that good?


(Mittineague) #5

The only possible issue I can see with that might be the date field.

The last_seen_at field is more than only yyyy-mm-dd and I don’t know how a <= comparison would handle the difference. You may need to format the last_seen_at to the same format you’re testing for. But maybe not.

I think it would be a good idea to try it without the update_all bit first to see if it returns what you want it to.


(Jeff Atwood) #6

I think you should use last post date instead of last seen date.