rework internal order system

This commit is contained in:
Matthias Hochmeister
2026-03-24 08:59:46 +01:00
parent 3c0a8a6832
commit 6ff5cc89ad
8 changed files with 240 additions and 154 deletions

View File

@@ -1,17 +1,23 @@
-- Migration 048: Catalog categories table + item characteristics
-- - Admin-managed categories (replacing free-text kategorie)
-- - 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
-- 1. Categories table (with parent_id for subcategories)
CREATE TABLE IF NOT EXISTS ausruestung_kategorien_katalog (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL UNIQUE,
erstellt_am TIMESTAMPTZ DEFAULT NOW()
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)
);
-- Add unique constraint for top-level categories (parent_id IS NULL)
CREATE UNIQUE INDEX IF NOT EXISTS ausruestung_kategorien_top_level_unique
ON ausruestung_kategorien_katalog (name) WHERE parent_id IS 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 != ''
@@ -24,7 +30,7 @@ ALTER TABLE ausruestung_artikel ADD COLUMN IF NOT EXISTS kategorie_id INT REFERE
UPDATE ausruestung_artikel a
SET kategorie_id = k.id
FROM ausruestung_kategorien_katalog k
WHERE k.name = a.kategorie AND a.kategorie_id IS NULL;
WHERE k.name = a.kategorie AND a.kategorie_id IS NULL AND k.parent_id IS NULL;
-- 2. Characteristics definitions per catalog item
CREATE TABLE IF NOT EXISTS ausruestung_artikel_eigenschaften (