LuminaWebsite/sql/schema.sql
Maaxxs 42ebc82e63 Add a role display name, separate from the internal identifier
Roles get a new optional display_name (roles.display_name): everywhere
a role name is shown to users (dashboard badges, member list section
headers/badges, admin user list, role checkboxes in user_form.php),
it's now COALESCE(NULLIF(display_name,''), name) - falls back to the
existing internal name when unset. The name field keeps its original
role as the unique technical identifier; admin/role_form.php's label
now says so explicitly, and admin/roles.php lists both columns since
that's the one screen actually managing the identifier.

Also drops "aktiven" from the member list's count line, since the
page already only lists active accounts without needing to say so.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-19 15:28:00 +02:00

57 lines
2.6 KiB
SQL

-- Aion2 Gilde - Datenbankschema
-- Import dieser Datei z.B. über phpMyAdmin in eine leere Datenbank.
SET NAMES utf8mb4;
CREATE TABLE IF NOT EXISTS users (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(50) NOT NULL UNIQUE,
password_hash VARCHAR(255) NOT NULL,
display_name VARCHAR(100) NOT NULL DEFAULT '',
status ENUM('active', 'disabled') NOT NULL DEFAULT 'active',
must_change_password TINYINT(1) NOT NULL DEFAULT 0,
discord_id BIGINT UNSIGNED NULL UNIQUE,
discord_username VARCHAR(100) NULL,
avatar_filename VARCHAR(255) NULL,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
last_login DATETIME NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE IF NOT EXISTS roles (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(50) NOT NULL UNIQUE,
-- Wird ueberall dort angezeigt, wo Mitgliedern/Rollen im Frontend ein Name
-- gezeigt wird (Dashboard, Mitgliederliste, ...) - "name" oben bleibt dabei
-- der interne, eindeutige Identifizierer. Leer = "name" wird als Anzeige
-- verwendet (Fallback).
display_name VARCHAR(100) NOT NULL DEFAULT '',
description VARCHAR(255) NOT NULL DEFAULT '',
is_system TINYINT(1) NOT NULL DEFAULT 0,
-- NULL = Mitglieder dieser Rolle erscheinen in der Mitgliederliste nur in der
-- allgemeinen Gruppe. Eine Zahl gibt der Rolle dort eine eigene Gruppe und
-- bestimmt deren Reihenfolge (aufsteigend, z.B. 1 = zuerst).
roster_order INT NULL DEFAULT NULL,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE IF NOT EXISTS permissions (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
`key` VARCHAR(100) NOT NULL UNIQUE,
description VARCHAR(255) NOT NULL DEFAULT ''
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE IF NOT EXISTS role_permissions (
role_id INT UNSIGNED NOT NULL,
permission_id INT UNSIGNED NOT NULL,
PRIMARY KEY (role_id, permission_id),
FOREIGN KEY (role_id) REFERENCES roles(id) ON DELETE CASCADE,
FOREIGN KEY (permission_id) REFERENCES permissions(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE IF NOT EXISTS user_roles (
user_id INT UNSIGNED NOT NULL,
role_id INT UNSIGNED NOT NULL,
PRIMARY KEY (user_id, role_id),
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
FOREIGN KEY (role_id) REFERENCES roles(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;