Need to delete all users from BookStack #492

Closed
opened 2026-02-04 20:33:19 +03:00 by OVERLORD · 5 comments
Owner

Originally created by @s0n- on GitHub (Oct 31, 2017).

We are migrating and need to remove all the users from bookstack but maintain the data. When we attempt to drop the users table we get errors, which doesnt come as a surprise.

is there a routine or something we can run to delete all the users except admin

Originally created by @s0n- on GitHub (Oct 31, 2017). We are migrating and need to remove all the users from bookstack but maintain the data. When we attempt to drop the users table we get errors, which doesnt come as a surprise. is there a routine or something we can run to delete all the users except admin
OVERLORD added the 🐕 Support label 2026-02-04 20:33:19 +03:00
Author
Owner

@ssddanbrown commented on GitHub (Nov 7, 2017):

Hi @s0n-,

There is no helper to do this so SQL is probably the way to go. You can use the below SQL to achieve this. Obviously ensure you've got a secure backup before running the below in the event of any errors:

# Set database to use, Change to the name of your 'bookstack' database.
use bookstack;

# Delete users that are not 'admin' or system users.
DELETE u FROM users u
        LEFT JOIN
    role_user ru ON (ru.user_id = u.id)
        LEFT JOIN
    roles r ON (r.id = ru.role_id)
WHERE
    u.system_name IS NULL AND r.name != 'admin';

There should be a system 'public' user which should be kept (Which the SQL above does).
If you've used social accounts it may be best to clear the social_accounts table aswell.

@ssddanbrown commented on GitHub (Nov 7, 2017): Hi @s0n-, There is no helper to do this so SQL is probably the way to go. You can use the below SQL to achieve this. Obviously ensure you've got a secure backup before running the below in the event of any errors: ```sql # Set database to use, Change to the name of your 'bookstack' database. use bookstack; # Delete users that are not 'admin' or system users. DELETE u FROM users u LEFT JOIN role_user ru ON (ru.user_id = u.id) LEFT JOIN roles r ON (r.id = ru.role_id) WHERE u.system_name IS NULL AND r.name != 'admin'; ``` There should be a system 'public' user which should be kept (Which the SQL above does). If you've used social accounts it may be best to clear the `social_accounts` table aswell.
Author
Owner

@s0n- commented on GitHub (Nov 7, 2017):

This is great!! Thank you!

@s0n- commented on GitHub (Nov 7, 2017): This is great!! Thank you!
Author
Owner

@Shackelford-Arden commented on GitHub (Nov 8, 2017):

Just curious if this is something that might be valuable in Bookstack's documentation or if this is something that'll be incorporated into Bookstack's functionality.

If neither, I'd say we should be good to close this I'd think.

@Shackelford-Arden commented on GitHub (Nov 8, 2017): Just curious if this is something that might be valuable in Bookstack's documentation or if this is something that'll be incorporated into Bookstack's functionality. If neither, I'd say we should be good to close this I'd think.
Author
Owner

@Abijeet commented on GitHub (Nov 9, 2017):

I think we should create a command, similar to the ones already available,

https://www.bookstackapp.com/docs/admin/commands/

@ssddanbrown - Can I go ahead and submit a merge request towards this?

@Abijeet commented on GitHub (Nov 9, 2017): I think we should create a command, similar to the ones already available, https://www.bookstackapp.com/docs/admin/commands/ @ssddanbrown - Can I go ahead and submit a merge request towards this?
Author
Owner

@ssddanbrown commented on GitHub (Dec 8, 2017):

@Abijeet Sorry, Missed your last message here. Absolutely, Feel free if you're still up for it.

While thinking about this I've also opened up #609 as that would have a similar use.

@ssddanbrown commented on GitHub (Dec 8, 2017): @Abijeet Sorry, Missed your last message here. Absolutely, Feel free if you're still up for it. While thinking about this I've also opened up #609 as that would have a similar use.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/BookStack#492