The login page leads with "Mit Discord einloggen"; username/password stays available below and can be allowed or refused per user. The Discord login asks for identify + guilds.members.read, so the site itself can check that the account is on the legion's server and read its roles - no bot token on the webspace. Unknown accounts get a new user in the new status "pending", Discord-only, who sees nothing but a "Freischaltung ausstehend" page and has no permissions until approved from the user list. Permission groups can be linked to a Discord role. Linked groups are granted and revoked from the member's roles at every Discord login and then every five minutes during a session, using the stored (refreshed) user token; leaving the server removes them and ends a Discord session. Manual groups are untouched, and several linked roles simply add up their groups. New columns are added automatically on first request (includes/schema.php), since the login page itself needs them; existing accounts keep password login. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
116 lines
5.6 KiB
SQL
116 lines
5.6 KiB
SQL
-- Lumina Ascendens - 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 '',
|
|
-- pending = per Discord angemeldet, aber noch nicht freigeschaltet.
|
|
status ENUM('active', 'disabled', 'pending') NOT NULL DEFAULT 'active',
|
|
must_change_password TINYINT(1) NOT NULL DEFAULT 0,
|
|
-- 0 = Anmeldung nur ueber Discord (Standard fuer per Discord angelegte Konten).
|
|
password_login TINYINT(1) NOT NULL DEFAULT 1,
|
|
discord_id BIGINT UNSIGNED NULL UNIQUE,
|
|
discord_username VARCHAR(100) NULL,
|
|
-- OAuth-Token des Discord-Logins (Scopes identify + guilds.members.read), damit
|
|
-- Server-Mitgliedschaft und Rollen waehrend der Sitzung neu geprueft werden koennen.
|
|
discord_access_token VARCHAR(255) NULL,
|
|
discord_refresh_token VARCHAR(255) NULL,
|
|
discord_token_expires DATETIME NULL,
|
|
discord_synced_at DATETIME 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,
|
|
-- Verknuepfte Discord-Rolle: wer sie auf dem Server hat, ist automatisch in dieser
|
|
-- Gruppe, wer sie verliert, fliegt raus. NULL = Gruppe wird von Hand vergeben.
|
|
discord_role_id BIGINT UNSIGNED 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;
|
|
|
|
-- --------------------------------------------------------------------------
|
|
-- Taktiken auf der Karte
|
|
-- --------------------------------------------------------------------------
|
|
|
|
-- Eine Taktik gehoert zu einer Region der Karte (map_slug aus assets/map/data/maps.json)
|
|
-- und besteht aus nacheinander ablaufenden Schritten.
|
|
CREATE TABLE IF NOT EXISTS tactics (
|
|
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
|
map_slug VARCHAR(60) NOT NULL,
|
|
name VARCHAR(120) NOT NULL,
|
|
description TEXT NULL,
|
|
created_by INT UNSIGNED NULL,
|
|
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
updated_at DATETIME NULL,
|
|
FOREIGN KEY (created_by) REFERENCES users(id) ON DELETE SET NULL,
|
|
INDEX idx_tactics_map (map_slug)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- Ein Schritt ist eine eigene Zeichenebene ("Schritt 1: Sammeln", "Schritt 2: Angriff").
|
|
CREATE TABLE IF NOT EXISTS tactic_steps (
|
|
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
|
tactic_id INT UNSIGNED NOT NULL,
|
|
title VARCHAR(120) NOT NULL DEFAULT '',
|
|
description TEXT NULL,
|
|
sort_order INT NOT NULL DEFAULT 0,
|
|
FOREIGN KEY (tactic_id) REFERENCES tactics(id) ON DELETE CASCADE,
|
|
INDEX idx_tactic_steps_tactic (tactic_id)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- points enthaelt die Stuetzpunkte als JSON-Array [[x,y], ...] in Weltkoordinaten der
|
|
-- Karte (0..4096, dieselben wie die Marker). TEXT statt JSON, damit auch aeltere
|
|
-- MySQL-/MariaDB-Versionen ohne JSON-Typ funktionieren.
|
|
CREATE TABLE IF NOT EXISTS tactic_shapes (
|
|
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
|
step_id INT UNSIGNED NOT NULL,
|
|
shape_type ENUM('pen', 'line', 'arrow', 'area', 'circle', 'point', 'text') NOT NULL,
|
|
label VARCHAR(200) NOT NULL DEFAULT '',
|
|
color VARCHAR(7) NOT NULL DEFAULT '#ffd700',
|
|
width TINYINT UNSIGNED NOT NULL DEFAULT 4,
|
|
points MEDIUMTEXT NOT NULL,
|
|
created_by INT UNSIGNED NULL,
|
|
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
FOREIGN KEY (step_id) REFERENCES tactic_steps(id) ON DELETE CASCADE,
|
|
FOREIGN KEY (created_by) REFERENCES users(id) ON DELETE SET NULL,
|
|
INDEX idx_tactic_shapes_step (step_id)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|