Files
Paradise/SQL/updates/69-70.sql
Charlie Nolan 2b98749d32 Make DB admin ranks more useful (#29906)
* Make DB admin ranks more useful

* Avoid error message when cancelling permission toggle, allow adding localhost admins as real admins.

* Lint.

* Don't SQL error when a previously-unseen player connects.

* Use ckey of permission editor, not mob name.

* Strikethrough

* Order in the list.

* Deadmin, readmin, and 2fa.

* Correct merge error

---------

Co-authored-by: Burzah <116982774+Burzah@users.noreply.github.com>
2025-08-10 12:05:19 +01:00

40 lines
1.5 KiB
SQL

# Updating DB from 69-70 -FunnyMan3595
# Adds the admin_ranks table
# Create the new table.
CREATE TABLE `admin_ranks` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL,
`default_permissions` int(16) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
KEY `name` (`name`)
) ENGINE=InnoDB AUTO_INCREMENT=99 DEFAULT CHARSET=utf8mb4;
# Create official ranks for every existing display rank, with the minimum common permissions.
INSERT INTO admin_ranks (name, default_permissions)
SELECT admin_rank, BIT_AND(flags) FROM admin GROUP BY admin_rank;
# Add new columns to admin table.
ALTER TABLE admin
ADD COLUMN `display_rank` varchar(32) COLLATE utf8mb4_unicode_ci,
ADD COLUMN `permissions_rank` int(11) COMMENT 'Foreign key for admin_ranks.id',
ADD COLUMN `extra_permissions` int(16) NOT NULL DEFAULT '0',
ADD COLUMN `removed_permissions` int(16) NOT NULL DEFAULT '0';
# Set the rank and any extra_permissions for each admin.
# There won't be any removed_permissions because we took the minimum common permissions earlier.
# We also leave display_rank blank, since admin_ranks.name matches their old admin_rank.
UPDATE admin JOIN admin_ranks ON admin.admin_rank = admin_ranks.name
SET
admin.permissions_rank = admin_ranks.id,
admin.extra_permissions = admin.flags & ~admin_ranks.default_permissions;
# Drop the old columns from the admin table.
ALTER TABLE admin
DROP COLUMN admin_rank,
DROP COLUMN level,
DROP COLUMN flags;
# Drop the lastadminrank column from the player table.
ALTER TABLE player DROP COLUMN lastadminrank;