--
-- PostgreSQL database dump
--

SET search_path = public, pg_catalog;

--
-- TOC entry 4 (OID 97924)
-- Name: recipes; Type: TABLE; Schema: public; Owner: projectjj
--

CREATE TABLE recipes (
    recipe_id serial NOT NULL,
    recipe_name text NOT NULL,
    recipe_persons smallint DEFAULT 1 NOT NULL,
    recipe_prepare_time interval,
    recipe_work_time interval,
    recipe_picture text,
    recipe_comment text,
    recipe_type integer,
    recipe_vegetarian boolean DEFAULT false NOT NULL,
    recipe_instructions text
) WITHOUT OIDS;


--
-- TOC entry 5 (OID 97933)
-- Name: recipe_types; Type: TABLE; Schema: public; Owner: projectjj
--

CREATE TABLE recipe_types (
    recipe_type_id serial NOT NULL,
    recipe_type_type text NOT NULL
) WITHOUT OIDS;


--
-- TOC entry 6 (OID 97951)
-- Name: ingredient_units; Type: TABLE; Schema: public; Owner: projectjj
--

CREATE TABLE ingredient_units (
    ingredient_unit_id serial NOT NULL,
    ingredient_unit_unit text NOT NULL
) WITHOUT OIDS;


--
-- TOC entry 7 (OID 97961)
-- Name: ingredient_types; Type: TABLE; Schema: public; Owner: projectjj
--

CREATE TABLE ingredient_types (
    ingredient_type_id serial NOT NULL,
    ingredient_type_type text NOT NULL
) WITHOUT OIDS;


--
-- TOC entry 8 (OID 97971)
-- Name: ingredients; Type: TABLE; Schema: public; Owner: projectjj
--

CREATE TABLE ingredients (
    ingredient_id serial NOT NULL,
    ingredient_name text NOT NULL,
    ingredient_type integer,
    ingredient_unit integer,
    ingredient_price real
) WITHOUT OIDS;


--
-- TOC entry 9 (OID 97987)
-- Name: recipe_ingredients; Type: TABLE; Schema: public; Owner: projectjj
--

CREATE TABLE recipe_ingredients (
    recipe_id integer NOT NULL,
    ingredient_id integer NOT NULL,
    ingredient_units real NOT NULL
) WITHOUT OIDS;


--
-- TOC entry 10 (OID 98001)
-- Name: menus; Type: TABLE; Schema: public; Owner: projectjj
--

CREATE TABLE menus (
    menu_id serial NOT NULL,
    menu_name text NOT NULL,
    menu_comment text
) WITHOUT OIDS;


--
-- TOC entry 11 (OID 98009)
-- Name: menu_recipes; Type: TABLE; Schema: public; Owner: projectjj
--

CREATE TABLE menu_recipes (
    menu_id integer NOT NULL,
    recipe_id integer NOT NULL,
    recipe_order smallint NOT NULL
) WITHOUT OIDS;


--
-- TOC entry 12 (OID 98023)
-- Name: inventories; Type: TABLE; Schema: public; Owner: projectjj
--

CREATE TABLE inventories (
    inventory_id serial NOT NULL,
    inventory_name text NOT NULL,
    inventory_begin date,
    inventory_end date
) WITHOUT OIDS;


--
-- TOC entry 13 (OID 98031)
-- Name: inventory_ingredients; Type: TABLE; Schema: public; Owner: projectjj
--

CREATE TABLE inventory_ingredients (
    inventory_id integer NOT NULL,
    ingredient_id integer NOT NULL,
    ingredient_units real
) WITHOUT OIDS;


SET check_function_bodies = false;

--
-- TOC entry 26 (OID 98149)
-- Name: _int_contains(integer[], integer[]); Type: FUNCTION; Schema: public; Owner: projectjj
--

CREATE FUNCTION _int_contains(integer[], integer[]) RETURNS boolean
    AS '$libdir/_int', '_int_contains'
    LANGUAGE c STRICT;


--
-- TOC entry 28 (OID 98150)
-- Name: _int_contained(integer[], integer[]); Type: FUNCTION; Schema: public; Owner: projectjj
--

CREATE FUNCTION _int_contained(integer[], integer[]) RETURNS boolean
    AS '$libdir/_int', '_int_contained'
    LANGUAGE c STRICT;


--
-- TOC entry 14 (OID 97948)
-- Name: fki_; Type: INDEX; Schema: public; Owner: projectjj
--

CREATE INDEX fki_ ON recipes USING btree (recipe_type);


--
-- TOC entry 16 (OID 97940)
-- Name: recipe_types_pkey; Type: CONSTRAINT; Schema: public; Owner: projectjj
--

ALTER TABLE ONLY recipe_types
    ADD CONSTRAINT recipe_types_pkey PRIMARY KEY (recipe_type_id);


--
-- TOC entry 15 (OID 97942)
-- Name: recipes_pkey; Type: CONSTRAINT; Schema: public; Owner: projectjj
--

ALTER TABLE ONLY recipes
    ADD CONSTRAINT recipes_pkey PRIMARY KEY (recipe_id);


--
-- TOC entry 17 (OID 97957)
-- Name: ingredient_units_pkey; Type: CONSTRAINT; Schema: public; Owner: projectjj
--

ALTER TABLE ONLY ingredient_units
    ADD CONSTRAINT ingredient_units_pkey PRIMARY KEY (ingredient_unit_id);


--
-- TOC entry 18 (OID 97967)
-- Name: ingredient_types_pkey; Type: CONSTRAINT; Schema: public; Owner: projectjj
--

ALTER TABLE ONLY ingredient_types
    ADD CONSTRAINT ingredient_types_pkey PRIMARY KEY (ingredient_type_id);


--
-- TOC entry 20 (OID 97977)
-- Name: ingredients_pkey; Type: CONSTRAINT; Schema: public; Owner: projectjj
--

ALTER TABLE ONLY ingredients
    ADD CONSTRAINT ingredients_pkey PRIMARY KEY (ingredient_id);


--
-- TOC entry 21 (OID 97997)
-- Name: recipe_ingredients_pkey; Type: CONSTRAINT; Schema: public; Owner: projectjj
--

ALTER TABLE ONLY recipe_ingredients
    ADD CONSTRAINT recipe_ingredients_pkey PRIMARY KEY (recipe_id, ingredient_id);


--
-- TOC entry 22 (OID 98007)
-- Name: menus_pkey; Type: CONSTRAINT; Schema: public; Owner: projectjj
--

ALTER TABLE ONLY menus
    ADD CONSTRAINT menus_pkey PRIMARY KEY (menu_id);


--
-- TOC entry 23 (OID 98019)
-- Name: menu_recipes_pkey; Type: CONSTRAINT; Schema: public; Owner: projectjj
--

ALTER TABLE ONLY menu_recipes
    ADD CONSTRAINT menu_recipes_pkey PRIMARY KEY (menu_id, recipe_id);


--
-- TOC entry 24 (OID 98029)
-- Name: inventories_pkey; Type: CONSTRAINT; Schema: public; Owner: projectjj
--

ALTER TABLE ONLY inventories
    ADD CONSTRAINT inventories_pkey PRIMARY KEY (inventory_id);


--
-- TOC entry 25 (OID 98041)
-- Name: inventory_ingredients_pkey; Type: CONSTRAINT; Schema: public; Owner: projectjj
--

ALTER TABLE ONLY inventory_ingredients
    ADD CONSTRAINT inventory_ingredients_pkey PRIMARY KEY (inventory_id, ingredient_id);


--
-- TOC entry 19 (OID 98124)
-- Name: ingredients_ingredient_name_key; Type: CONSTRAINT; Schema: public; Owner: projectjj
--

ALTER TABLE ONLY ingredients
    ADD CONSTRAINT ingredients_ingredient_name_key UNIQUE (ingredient_name);


--
-- TOC entry 30 (OID 97944)
-- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: projectjj
--

ALTER TABLE ONLY recipes
    ADD CONSTRAINT "$1" FOREIGN KEY (recipe_type) REFERENCES recipe_types(recipe_type_id) ON UPDATE CASCADE ON DELETE SET NULL;


--
-- TOC entry 32 (OID 97979)
-- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: projectjj
--

ALTER TABLE ONLY ingredients
    ADD CONSTRAINT "$1" FOREIGN KEY (ingredient_type) REFERENCES ingredient_types(ingredient_type_id) ON UPDATE CASCADE ON DELETE SET NULL;


--
-- TOC entry 31 (OID 97983)
-- Name: $2; Type: FK CONSTRAINT; Schema: public; Owner: projectjj
--

ALTER TABLE ONLY ingredients
    ADD CONSTRAINT "$2" FOREIGN KEY (ingredient_unit) REFERENCES ingredient_units(ingredient_unit_id) ON UPDATE CASCADE ON DELETE SET NULL;


--
-- TOC entry 34 (OID 97989)
-- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: projectjj
--

ALTER TABLE ONLY recipe_ingredients
    ADD CONSTRAINT "$1" FOREIGN KEY (recipe_id) REFERENCES recipes(recipe_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- TOC entry 33 (OID 97993)
-- Name: $2; Type: FK CONSTRAINT; Schema: public; Owner: projectjj
--

ALTER TABLE ONLY recipe_ingredients
    ADD CONSTRAINT "$2" FOREIGN KEY (ingredient_id) REFERENCES ingredients(ingredient_id) ON UPDATE CASCADE ON DELETE SET NULL;


--
-- TOC entry 36 (OID 98011)
-- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: projectjj
--

ALTER TABLE ONLY menu_recipes
    ADD CONSTRAINT "$1" FOREIGN KEY (menu_id) REFERENCES menus(menu_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- TOC entry 35 (OID 98015)
-- Name: $2; Type: FK CONSTRAINT; Schema: public; Owner: projectjj
--

ALTER TABLE ONLY menu_recipes
    ADD CONSTRAINT "$2" FOREIGN KEY (recipe_id) REFERENCES recipes(recipe_id) ON UPDATE CASCADE ON DELETE SET NULL;


--
-- TOC entry 38 (OID 98033)
-- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: projectjj
--

ALTER TABLE ONLY inventory_ingredients
    ADD CONSTRAINT "$1" FOREIGN KEY (inventory_id) REFERENCES inventories(inventory_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- TOC entry 37 (OID 98037)
-- Name: $2; Type: FK CONSTRAINT; Schema: public; Owner: projectjj
--

ALTER TABLE ONLY inventory_ingredients
    ADD CONSTRAINT "$2" FOREIGN KEY (ingredient_id) REFERENCES ingredients(ingredient_id) ON UPDATE CASCADE ON DELETE SET NULL;


--
-- TOC entry 2 (OID 2200)
-- Name: SCHEMA public; Type: COMMENT; Schema: -; Owner: postgres
--

COMMENT ON SCHEMA public IS 'Standard public schema';


--
-- TOC entry 27 (OID 98149)
-- Name: FUNCTION _int_contains(integer[], integer[]); Type: COMMENT; Schema: public; Owner: projectjj
--

COMMENT ON FUNCTION _int_contains(integer[], integer[]) IS 'contains';


--
-- TOC entry 29 (OID 98150)
-- Name: FUNCTION _int_contained(integer[], integer[]); Type: COMMENT; Schema: public; Owner: projectjj
--

COMMENT ON FUNCTION _int_contained(integer[], integer[]) IS 'contained in';


