feat: add company management and user-company assignment in admin panel
All checks were successful
Staging Build / build (push) Successful in 2m35s

This commit is contained in:
DanielS
2026-06-24 17:12:40 +02:00
parent 6b66cc5c41
commit 7a14aa0f75
8 changed files with 346 additions and 15 deletions

View File

@@ -0,0 +1,31 @@
-- Migration: companies table + company_id in users
-- 1. Tabelle companies erstellen
CREATE TABLE IF NOT EXISTS public.companies (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
name TEXT NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
-- RLS aktivieren
ALTER TABLE public.companies ENABLE ROW LEVEL SECURITY;
-- Policies
DROP POLICY IF EXISTS "Admins und Partner lesen Firmen" ON public.companies;
DROP POLICY IF EXISTS "Service role kann alles" ON public.companies;
CREATE POLICY "Admins und Partner lesen Firmen"
ON public.companies FOR SELECT
USING (auth.role() = 'authenticated');
CREATE POLICY "Service role kann alles"
ON public.companies FOR ALL
USING (true)
WITH CHECK (true);
-- 2. company_id zu public.users hinzufügen
ALTER TABLE public.users
ADD COLUMN IF NOT EXISTS company_id UUID REFERENCES public.companies(id) ON DELETE SET NULL;
-- Reload Schema Cache
NOTIFY pgrst, 'reload schema';