-- -- PostgreSQL database dump -- -- Dumped from database version 17.6 -- Dumped by pg_dump version 17.10 SET statement_timeout = 0; SET lock_timeout = 0; SET idle_in_transaction_session_timeout = 0; SET transaction_timeout = 0; SET client_encoding = 'UTF8'; SET standard_conforming_strings = on; SELECT pg_catalog.set_config('search_path', '', false); SET check_function_bodies = false; SET xmloption = content; SET client_min_messages = warning; SET row_security = off; -- -- Name: public; Type: SCHEMA; Schema: -; Owner: - -- -- Das "public"-Schema existiert im offiziellen postgres-Image bereits; -- CREATE SCHEMA würde dort mit ON_ERROR_STOP=1 das komplette Init-Skript -- abbrechen. CREATE SCHEMA IF NOT EXISTS public; -- -- Name: SCHEMA public; Type: COMMENT; Schema: -; Owner: - -- COMMENT ON SCHEMA public IS 'standard public schema'; -- -- Name: app_role(); Type: FUNCTION; Schema: public; Owner: - -- CREATE FUNCTION public.app_role() RETURNS text LANGUAGE sql STABLE SECURITY DEFINER SET search_path TO 'public' AS $$ select role from public.profiles where id = auth.uid() $$; -- -- Name: handle_new_user(); Type: FUNCTION; Schema: public; Owner: - -- CREATE FUNCTION public.handle_new_user() RETURNS trigger LANGUAGE plpgsql SECURITY DEFINER SET search_path TO 'public' AS $$ begin insert into public.profiles (id, email, full_name, role) values ( new.id, new.email, coalesce(new.raw_user_meta_data ->> 'full_name', ''), coalesce(new.raw_user_meta_data ->> 'role', 'staff') ) on conflict (id) do nothing; return new; end; $$; -- -- Name: handle_user_email_change(); Type: FUNCTION; Schema: public; Owner: - -- CREATE FUNCTION public.handle_user_email_change() RETURNS trigger LANGUAGE plpgsql SECURITY DEFINER SET search_path TO 'public' AS $$ begin update public.profiles set email = new.email where id = new.id; return new; end; $$; -- -- Name: touch_updated_at(); Type: FUNCTION; Schema: public; Owner: - -- CREATE FUNCTION public.touch_updated_at() RETURNS trigger LANGUAGE plpgsql AS $$ begin new.updated_at := now(); return new; end; $$; SET default_tablespace = ''; SET default_table_access_method = heap; -- -- Name: additives; Type: TABLE; Schema: public; Owner: - -- CREATE TABLE public.additives ( code text NOT NULL, name text NOT NULL, sort integer DEFAULT 0 NOT NULL ); -- -- Name: allergens; Type: TABLE; Schema: public; Owner: - -- CREATE TABLE public.allergens ( code text NOT NULL, name text NOT NULL, sort integer DEFAULT 0 NOT NULL ); -- -- Name: dishes; Type: TABLE; Schema: public; Owner: - -- CREATE TABLE public.dishes ( id uuid DEFAULT gen_random_uuid() NOT NULL, name text NOT NULL, price numeric(6,2) DEFAULT 0 NOT NULL, created_at timestamp with time zone DEFAULT now() NOT NULL, updated_at timestamp with time zone DEFAULT now() NOT NULL ); -- -- Name: menu_entries; Type: TABLE; Schema: public; Owner: - -- CREATE TABLE public.menu_entries ( id uuid DEFAULT gen_random_uuid() NOT NULL, menu_date date NOT NULL, section_key text NOT NULL, dish_id uuid NOT NULL, "position" integer DEFAULT 0 NOT NULL, created_at timestamp with time zone DEFAULT now() NOT NULL ); -- -- Name: profiles; Type: TABLE; Schema: public; Owner: - -- CREATE TABLE public.profiles ( id uuid NOT NULL, email text NOT NULL, full_name text DEFAULT ''::text NOT NULL, role text DEFAULT 'staff'::text NOT NULL, created_at timestamp with time zone DEFAULT now() NOT NULL, CONSTRAINT profiles_role_check CHECK ((role = ANY (ARRAY['admin'::text, 'staff'::text]))) ); -- -- Name: sections; Type: TABLE; Schema: public; Owner: - -- CREATE TABLE public.sections ( key text NOT NULL, label text NOT NULL, time_range text NOT NULL, sort integer NOT NULL ); -- -- Name: settings; Type: TABLE; Schema: public; Owner: - -- CREATE TABLE public.settings ( id integer NOT NULL, colors jsonb DEFAULT '{}'::jsonb NOT NULL, logo_path text, updated_at timestamp with time zone DEFAULT now() NOT NULL, CONSTRAINT settings_id_check CHECK ((id = 1)) ); -- -- Name: additives additives_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY public.additives ADD CONSTRAINT additives_pkey PRIMARY KEY (code); -- -- Name: allergens allergens_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY public.allergens ADD CONSTRAINT allergens_pkey PRIMARY KEY (code); -- -- Name: dishes dishes_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY public.dishes ADD CONSTRAINT dishes_pkey PRIMARY KEY (id); -- -- Name: menu_entries menu_entries_menu_date_section_key_dish_id_key; Type: CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY public.menu_entries ADD CONSTRAINT menu_entries_menu_date_section_key_dish_id_key UNIQUE (menu_date, section_key, dish_id); -- -- Name: menu_entries menu_entries_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY public.menu_entries ADD CONSTRAINT menu_entries_pkey PRIMARY KEY (id); -- -- Name: profiles profiles_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY public.profiles ADD CONSTRAINT profiles_pkey PRIMARY KEY (id); -- -- Name: sections sections_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY public.sections ADD CONSTRAINT sections_pkey PRIMARY KEY (key); -- -- Name: settings settings_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY public.settings ADD CONSTRAINT settings_pkey PRIMARY KEY (id); -- -- Name: menu_entries_date_idx; Type: INDEX; Schema: public; Owner: - -- CREATE INDEX menu_entries_date_idx ON public.menu_entries USING btree (menu_date); -- -- Name: dishes dishes_touch_updated_at; Type: TRIGGER; Schema: public; Owner: - -- CREATE TRIGGER dishes_touch_updated_at BEFORE UPDATE ON public.dishes FOR EACH ROW EXECUTE FUNCTION public.touch_updated_at(); -- -- Name: settings settings_touch_updated_at; Type: TRIGGER; Schema: public; Owner: - -- CREATE TRIGGER settings_touch_updated_at BEFORE UPDATE ON public.settings FOR EACH ROW EXECUTE FUNCTION public.touch_updated_at(); -- -- Name: menu_entries menu_entries_dish_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY public.menu_entries ADD CONSTRAINT menu_entries_dish_id_fkey FOREIGN KEY (dish_id) REFERENCES public.dishes(id) ON DELETE CASCADE; -- -- Name: menu_entries menu_entries_section_key_fkey; Type: FK CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY public.menu_entries ADD CONSTRAINT menu_entries_section_key_fkey FOREIGN KEY (section_key) REFERENCES public.sections(key); -- -- Name: profiles profiles_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY public.profiles ADD CONSTRAINT profiles_id_fkey FOREIGN KEY (id) REFERENCES auth.users(id) ON DELETE CASCADE; -- -- Name: additives; Type: ROW SECURITY; Schema: public; Owner: - -- ALTER TABLE public.additives ENABLE ROW LEVEL SECURITY; -- -- Name: additives additives_public_read; Type: POLICY; Schema: public; Owner: - -- CREATE POLICY additives_public_read ON public.additives FOR SELECT TO authenticated, anon USING (true); -- -- Name: additives additives_staff_write; Type: POLICY; Schema: public; Owner: - -- CREATE POLICY additives_staff_write ON public.additives TO authenticated USING ((public.app_role() = ANY (ARRAY['staff'::text, 'admin'::text]))) WITH CHECK ((public.app_role() = ANY (ARRAY['staff'::text, 'admin'::text]))); -- -- Name: allergens; Type: ROW SECURITY; Schema: public; Owner: - -- ALTER TABLE public.allergens ENABLE ROW LEVEL SECURITY; -- -- Name: allergens allergens_public_read; Type: POLICY; Schema: public; Owner: - -- CREATE POLICY allergens_public_read ON public.allergens FOR SELECT TO authenticated, anon USING (true); -- -- Name: allergens allergens_staff_write; Type: POLICY; Schema: public; Owner: - -- CREATE POLICY allergens_staff_write ON public.allergens TO authenticated USING ((public.app_role() = ANY (ARRAY['staff'::text, 'admin'::text]))) WITH CHECK ((public.app_role() = ANY (ARRAY['staff'::text, 'admin'::text]))); -- -- Name: dishes; Type: ROW SECURITY; Schema: public; Owner: - -- ALTER TABLE public.dishes ENABLE ROW LEVEL SECURITY; -- -- Name: dishes dishes_public_read; Type: POLICY; Schema: public; Owner: - -- CREATE POLICY dishes_public_read ON public.dishes FOR SELECT TO authenticated, anon USING (true); -- -- Name: dishes dishes_staff_write; Type: POLICY; Schema: public; Owner: - -- CREATE POLICY dishes_staff_write ON public.dishes TO authenticated USING ((public.app_role() = ANY (ARRAY['staff'::text, 'admin'::text]))) WITH CHECK ((public.app_role() = ANY (ARRAY['staff'::text, 'admin'::text]))); -- -- Name: menu_entries; Type: ROW SECURITY; Schema: public; Owner: - -- ALTER TABLE public.menu_entries ENABLE ROW LEVEL SECURITY; -- -- Name: menu_entries menu_entries_public_read; Type: POLICY; Schema: public; Owner: - -- CREATE POLICY menu_entries_public_read ON public.menu_entries FOR SELECT TO authenticated, anon USING (true); -- -- Name: menu_entries menu_entries_staff_write; Type: POLICY; Schema: public; Owner: - -- CREATE POLICY menu_entries_staff_write ON public.menu_entries TO authenticated USING ((public.app_role() = ANY (ARRAY['staff'::text, 'admin'::text]))) WITH CHECK ((public.app_role() = ANY (ARRAY['staff'::text, 'admin'::text]))); -- -- Name: profiles; Type: ROW SECURITY; Schema: public; Owner: - -- ALTER TABLE public.profiles ENABLE ROW LEVEL SECURITY; -- -- Name: profiles profiles_select_own_or_admin; Type: POLICY; Schema: public; Owner: - -- CREATE POLICY profiles_select_own_or_admin ON public.profiles FOR SELECT TO authenticated USING (((id = ( SELECT auth.uid() AS uid)) OR (public.app_role() = 'admin'::text))); -- -- Name: profiles profiles_update_own_name; Type: POLICY; Schema: public; Owner: - -- CREATE POLICY profiles_update_own_name ON public.profiles FOR UPDATE TO authenticated USING ((id = ( SELECT auth.uid() AS uid))) WITH CHECK ((id = ( SELECT auth.uid() AS uid))); -- -- Name: sections; Type: ROW SECURITY; Schema: public; Owner: - -- ALTER TABLE public.sections ENABLE ROW LEVEL SECURITY; -- -- Name: sections sections_public_read; Type: POLICY; Schema: public; Owner: - -- CREATE POLICY sections_public_read ON public.sections FOR SELECT TO authenticated, anon USING (true); -- -- Name: settings; Type: ROW SECURITY; Schema: public; Owner: - -- ALTER TABLE public.settings ENABLE ROW LEVEL SECURITY; -- -- Name: settings settings_admin_update; Type: POLICY; Schema: public; Owner: - -- CREATE POLICY settings_admin_update ON public.settings FOR UPDATE TO authenticated USING ((public.app_role() = 'admin'::text)) WITH CHECK ((public.app_role() = 'admin'::text)); -- -- Name: settings settings_public_read; Type: POLICY; Schema: public; Owner: - -- CREATE POLICY settings_public_read ON public.settings FOR SELECT TO authenticated, anon USING (true); -- -- PostgreSQL database dump complete --