So I am going through our database and removing some unneeded access levels that are basically duplicates of other ones. Our database structure has a column user_level
which is an enum that has a bunch of different strings (I know this isn't a great way to run user access levels but this is how the original developer made it).
What I am looking to do is to create a rollback that will save all the user_id's with their appropriate user_level so that in a few days if we see that we are having issues with our access levels we can roll back without messing up any other changes that have occurred in the database since we ran the update command.
What I was thinking of doing was just doing a
SELECT users.id, users.user_level
FROM users
WHERE users.user_level NOT IN ('Program Administrator','Executive','Sales Manager / Office Manager/ Company President');
then just manipulating the data that way, but what I would really like is have it create a query for me so we can place it in our ticket tracking system and all we have to do is copy / paste the query into our sql tool to run it for rollback.
However I am not sure what the best approach is. We have about 58,000 user records in our database.
So my question is does anyone have any ideas of how I should proceed and possibly some examples for this custom rollback.
EDIT:
So am looking for an equivalent of this php code but for MySQL
while ($user = mysql_fetch_array($databaseObj->result)) {
echo "UPDATE users SET user_level = '". $user['user_level'] ."' WHERE id='".$user['id']."'";
echo "<br>";
}
which will output
UPDATE users SET user_level = 'Sales Person/Packager' WHERE id='80006'
UPDATE users SET user_level = 'Sales Person/Packager' WHERE id='48'
UPDATE users SET user_level = 'Sales Person/Packager' WHERE id='42'
UPDATE users SET user_level = 'Sales Person/Packager' WHERE id='47'
UPDATE users SET user_level = 'Sales Person/Packager' WHERE id='49'
UPDATE users SET user_level = 'Sales Person/Packager' WHERE id='52'
UPDATE users SET user_level = 'Sales Person/Packager' WHERE id='58'
UPDATE users SET user_level = 'Sales Person/Packager' WHERE id='60'
which I can then save to a .sql file and just run this file should I need too.