feat: add company management and user-company assignment in admin panel
All checks were successful
Staging Build / build (push) Successful in 2m35s
All checks were successful
Staging Build / build (push) Successful in 2m35s
This commit is contained in:
@@ -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';
|
||||
Reference in New Issue
Block a user