Add Partner/Firmen links, migration for companies and partner relationship
All checks were successful
Staging Build / build (push) Successful in 2m40s
All checks were successful
Staging Build / build (push) Successful in 2m40s
This commit is contained in:
@@ -58,6 +58,14 @@ export default async function AdminLayout({
|
||||
<Users className="w-5 h-5" />
|
||||
Benutzer
|
||||
</Link>
|
||||
<Link href="/admin/partners" className="flex items-center gap-3 px-3 py-2 rounded-lg text-slate-400 hover:text-white hover:bg-white/5 transition-all">
|
||||
<Building2 className="w-5 h-5" />
|
||||
Partner
|
||||
</Link>
|
||||
<Link href="/admin/companies" className="flex items-center gap-3 px-3 py-2 rounded-lg text-slate-400 hover:text-white hover:bg-white/5 transition-all">
|
||||
<Building2 className="w-5 h-5" />
|
||||
Firmen
|
||||
</Link>
|
||||
|
||||
<div className="pt-2 pb-1 px-3">
|
||||
<span className="text-[10px] font-semibold uppercase tracking-wider text-slate-600">Einstellungen</span>
|
||||
|
||||
@@ -1,31 +1,51 @@
|
||||
-- Migration: companies table + company_id in users
|
||||
-- Migration: companies and partners tables with relationships
|
||||
|
||||
-- 1. Tabelle companies erstellen
|
||||
CREATE TABLE IF NOT EXISTS public.partners (
|
||||
-- 1. Create companies table
|
||||
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
|
||||
-- 2. Create partners table with optional company reference
|
||||
CREATE TABLE IF NOT EXISTS public.partners (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
name TEXT NOT NULL,
|
||||
company_id UUID REFERENCES public.companies(id) ON DELETE SET NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
||||
);
|
||||
|
||||
-- Enable RLS on both tables
|
||||
ALTER TABLE public.companies ENABLE ROW LEVEL SECURITY;
|
||||
ALTER TABLE public.partners ENABLE ROW LEVEL SECURITY;
|
||||
|
||||
-- Policies
|
||||
DROP POLICY IF EXISTS "Admins und Partner lesen Partner" ON public.partners;
|
||||
DROP POLICY IF EXISTS "Service role kann alles" ON public.partners;
|
||||
-- Policies for companies
|
||||
DROP POLICY IF EXISTS "Admins und Unternehmen lesen" ON public.companies;
|
||||
CREATE POLICY "Admins und Unternehmen lesen"
|
||||
ON public.companies FOR SELECT
|
||||
USING (auth.role() = 'authenticated');
|
||||
|
||||
CREATE POLICY "Admins und Partner lesen Partner"
|
||||
DROP POLICY IF EXISTS "Service role kann alles Unternehmen" ON public.companies;
|
||||
CREATE POLICY "Service role kann alles Unternehmen"
|
||||
ON public.companies FOR ALL
|
||||
USING (true)
|
||||
WITH CHECK (true);
|
||||
|
||||
-- Policies for partners
|
||||
DROP POLICY IF EXISTS "Admins und Partner lesen" ON public.partners;
|
||||
CREATE POLICY "Admins und Partner lesen"
|
||||
ON public.partners FOR SELECT
|
||||
USING (auth.role() = 'authenticated');
|
||||
|
||||
CREATE POLICY "Service role kann alles"
|
||||
DROP POLICY IF EXISTS "Service role kann alles Partner" ON public.partners;
|
||||
CREATE POLICY "Service role kann alles Partner"
|
||||
ON public.partners FOR ALL
|
||||
USING (true)
|
||||
WITH CHECK (true);
|
||||
|
||||
-- 2. company_id zu public.users hinzufügen
|
||||
-- 3. Add company_id to users (instead of partner_id)
|
||||
ALTER TABLE public.users
|
||||
ADD COLUMN IF NOT EXISTS partner_id UUID REFERENCES public.partners(id) ON DELETE SET NULL;
|
||||
ADD COLUMN IF NOT EXISTS company_id UUID REFERENCES public.companies(id) ON DELETE SET NULL;
|
||||
|
||||
-- Reload Schema Cache
|
||||
-- Reload schema cache
|
||||
NOTIFY pgrst, 'reload schema';
|
||||
|
||||
Reference in New Issue
Block a user