add features
This commit is contained in:
32
backend/src/database/migrations/020_create_notifications.sql
Normal file
32
backend/src/database/migrations/020_create_notifications.sql
Normal file
@@ -0,0 +1,32 @@
|
||||
-- Migration 020: Create notifications table
|
||||
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
|
||||
|
||||
CREATE TABLE IF NOT EXISTS notifications (
|
||||
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
||||
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
typ VARCHAR(50) NOT NULL,
|
||||
titel VARCHAR(500) NOT NULL,
|
||||
nachricht TEXT NOT NULL,
|
||||
schwere VARCHAR(20) NOT NULL DEFAULT 'info'
|
||||
CHECK (schwere IN ('info', 'warnung', 'fehler')),
|
||||
gelesen BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
gelesen_am TIMESTAMPTZ,
|
||||
link VARCHAR(500),
|
||||
quell_id VARCHAR(100),
|
||||
quell_typ VARCHAR(50),
|
||||
erstellt_am TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
|
||||
-- Fast lookup for unread badge count
|
||||
CREATE INDEX IF NOT EXISTS notifications_user_unread_idx
|
||||
ON notifications (user_id, gelesen)
|
||||
WHERE NOT gelesen;
|
||||
|
||||
-- Fast lookup for notification list ordered by date
|
||||
CREATE INDEX IF NOT EXISTS notifications_user_date_idx
|
||||
ON notifications (user_id, erstellt_am DESC);
|
||||
|
||||
-- Dedup index: one unread notification per (user, source type, source id)
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS notifications_dedup_idx
|
||||
ON notifications (user_id, quell_typ, quell_id)
|
||||
WHERE NOT gelesen AND quell_typ IS NOT NULL AND quell_id IS NOT NULL;
|
||||
@@ -0,0 +1,25 @@
|
||||
-- Migration 021: Add motorisiert flag to ausruestung_kategorien
|
||||
-- Motorized equipment (motorisiert = TRUE) → managed by fahrmeister
|
||||
-- Non-motorized equipment (motorisiert = FALSE) → managed by zeugmeister
|
||||
|
||||
ALTER TABLE ausruestung_kategorien
|
||||
ADD COLUMN IF NOT EXISTS motorisiert BOOLEAN NOT NULL DEFAULT FALSE;
|
||||
|
||||
-- Recreate the helper view to include the new column
|
||||
CREATE OR REPLACE VIEW ausruestung_mit_pruefstatus AS
|
||||
SELECT
|
||||
a.*,
|
||||
k.name AS kategorie_name,
|
||||
k.kurzname AS kategorie_kurzname,
|
||||
k.motorisiert AS kategorie_motorisiert,
|
||||
f.bezeichnung AS fahrzeug_bezeichnung,
|
||||
f.kurzname AS fahrzeug_kurzname,
|
||||
CASE
|
||||
WHEN a.naechste_pruefung_am IS NOT NULL
|
||||
THEN a.naechste_pruefung_am::date - CURRENT_DATE
|
||||
ELSE NULL
|
||||
END AS pruefung_tage_bis_faelligkeit
|
||||
FROM ausruestung a
|
||||
JOIN ausruestung_kategorien k ON k.id = a.kategorie_id
|
||||
LEFT JOIN fahrzeuge f ON f.id = a.fahrzeug_id AND f.deleted_at IS NULL
|
||||
WHERE a.deleted_at IS NULL;
|
||||
@@ -0,0 +1,6 @@
|
||||
-- Migration 022: Add alle_gruppen flag to veranstaltung_kategorien
|
||||
-- When alle_gruppen = TRUE, selecting this category auto-fills
|
||||
-- the event's alle_gruppen = TRUE and clears individual zielgruppen.
|
||||
|
||||
ALTER TABLE veranstaltung_kategorien
|
||||
ADD COLUMN IF NOT EXISTS alle_gruppen BOOLEAN NOT NULL DEFAULT FALSE;
|
||||
Reference in New Issue
Block a user