rework internal order system

This commit is contained in:
Matthias Hochmeister
2026-03-24 09:35:37 +01:00
parent 39b8b30ca2
commit 209d5a676e
3 changed files with 173 additions and 133 deletions

View File

@@ -1,23 +1,21 @@
-- Migration 048: Catalog categories table + item characteristics
-- - Admin-managed categories with subcategories (replacing free-text kategorie)
-- - Per-item characteristics (options or free-text)
-- - Characteristic values per request position
-- - Remove view_all permission (approve covers it)
-- - Add manage_categories permission
-- 1. Categories table (with parent_id for subcategories)
CREATE TABLE IF NOT EXISTS ausruestung_kategorien_katalog (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL,
parent_id INT REFERENCES ausruestung_kategorien_katalog(id) ON DELETE CASCADE,
erstellt_am TIMESTAMPTZ DEFAULT NOW(),
UNIQUE(name, parent_id)
erstellt_am TIMESTAMPTZ DEFAULT NOW()
);
-- Add unique constraint for top-level categories (parent_id IS NULL)
CREATE UNIQUE INDEX IF NOT EXISTS ausruestung_kategorien_top_level_unique
-- Unique: top-level categories by name (where parent_id IS NULL)
CREATE UNIQUE INDEX IF NOT EXISTS ausruestung_kat_top_unique
ON ausruestung_kategorien_katalog (name) WHERE parent_id IS NULL;
-- Unique: subcategories by (parent_id, name)
CREATE UNIQUE INDEX IF NOT EXISTS ausruestung_kat_child_unique
ON ausruestung_kategorien_katalog (parent_id, name) WHERE parent_id IS NOT NULL;
-- Migrate existing categories from free-text
INSERT INTO ausruestung_kategorien_katalog (name)
SELECT DISTINCT kategorie FROM ausruestung_artikel WHERE kategorie IS NOT NULL AND kategorie != ''