Hello, I'm stuck on a mysql data cleaner. Here's what I'm trying to do.
I have a list of online servers. I currently prune out servers older then 60 days.
My problem is I allow inner nested servers. So for example Server1 might have 7 other servers listed within Server1's private page. So the problem is, if I remove Server1 those 7 other servers are lost in mysql and never seen again lol. They're there they just wont be listed since their parent server, the one they where associated was deleted.
So what i'd like to do is take the most active server within the nest and make it the new dominant server for when the root one is pruned out.
Heres the steps I've though up in my head.
1) select server(s) in mysql that are 60 days old or older and get them ready for deletion.
2) select the top most online server associated with the server that's about to be deleted.
3) Make all other servers that are associated with the server thats 60 days old get re-associated with the most active server (in step 2).
4) After all servers are re-associated delete the server thats 60 days old or older.
So I'm stuck as to how to do this using a UNION or SUB method. Any ideas?
Heres some sandbox code I've been playing around with.
$query = ("SELECT pid,gid FROM serverlist WHERE gid='0' AND lastactive <= DATE_SUB(NOW(),INTERVAL 60 DAY)")
UNION
("SELECT pid,gid FROM serverlist") ORDER by lastactive DESC;
Oh almost forgot. I use pid as an unique ID for all servers. I use gid for pointing nested servers to a parent. So basically the gid is set to 0 if it's a parent. If it's a child it gets the parents pid added to it's gid. So serverabc with a gid of 2 would be a child of whatever server has the pid of 2.