-- Branding-Konfiguration, über /admin/branding per UI editierbar.
-- Exakt EINE Row in der Tabelle — Singleton via unique-Index erzwungen.
-- Leere/NULL-Werte bedeuten "Fallback auf ENV bzw. Code-Defaults".
create table if not exists public.site_settings (
id uuid primary key default gen_random_uuid(),
singleton boolean not null default true,
-- Firma / Öffentlich
company_name text,
company_short text,
claim text,
description text,
website text,
-- SEO / Metadaten
seo_title text,
seo_description text,
not_found_suffix text,
-- Admin-Labels
admin_app_name text,
admin_app_subtext text,
default_company_name text,
calendar_placeholder text,
-- Theme-Farben (Hex)
primary_color text,
primary_dark text,
primary_deep text,
secondary_color text,
secondary_dark text,
secondary_deep text,
-- Assets (public URLs aus dem branding-assets Storage-Bucket)
logo_url text,
logo_alt text,
favicon_url text,
updated_at timestamptz not null default now()
);
-- Exakt eine Row erlaubt: unique on (singleton=true)
create unique index if not exists site_settings_singleton_unique
on public.site_settings ((true)) where singleton = true;
-- Initiale Row anlegen, falls noch nicht da
insert into public.site_settings (singleton)
values (true)
on conflict do nothing;
-- RLS: Branding ist public (Farben, Name, Logo) — anon darf lesen.
alter table public.site_settings enable row level security;
drop policy if exists "public_read_site_settings" on public.site_settings;
create policy "public_read_site_settings"
on public.site_settings
for select to anon
using (true);
-- Schreibzugriff bleibt bei service-role (Admin-Server-Actions).
-- Storage-Bucket für Logo / Favicon / Icon. Öffentlich, damit und
-- direkt drauf zugreifen können.
insert into storage.buckets (id, name, public)
values ('branding-assets', 'branding-assets', true)
on conflict (id) do nothing;
-- Jeder darf lesen (Bucket ist public gesetzt, aber ein expliziter Select-
-- Policy-Eintrag schadet nicht und macht das Verhalten explizit).
drop policy if exists "public_read_branding_assets" on storage.objects;
create policy "public_read_branding_assets"
on storage.objects for select
to anon
using (bucket_id = 'branding-assets');