------------------------------------------------------------
--        Script SQLite  
------------------------------------------------------------


------------------------------------------------------------
-- Table: ingredients
------------------------------------------------------------
CREATE TABLE ingredients(
	id           INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT ,
	name         TEXT NOT NULL ,
	quantity     TEXT NOT NULL ,
	recipe_id    INTEGER NOT NULL
);


------------------------------------------------------------
-- Table: type
------------------------------------------------------------
CREATE TABLE type(
	id      INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT ,
	type    TEXT NOT NULL
);


------------------------------------------------------------
-- Table: recipes
------------------------------------------------------------
CREATE TABLE recipes(
	id         	INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT ,
	name       	TEXT NOT NULL ,
	image	   	TEXT NOT NULL,
	video      	TEXT,
	preparation	TEXT,
	baking		TEXT,
	type_id    	INTEGER NOT NULL ,
	steps		TEXT

	,CONSTRAINT recipes_type_FK FOREIGN KEY (type_id) REFERENCES type(id)
);


------------------------------------------------------------
-- Table: recipes_ingredients
------------------------------------------------------------
CREATE TABLE recipes_ingredients(
	ingredient_id            INTEGER NOT NULL ,
	recipe_id    INTEGER NOT NULL,
	CONSTRAINT recipes_ingredients_PK PRIMARY KEY (ingredient_id,recipe_id)

	,CONSTRAINT recipes_ingredients_ingredients_FK FOREIGN KEY (ingredient_id) REFERENCES ingredients(id)
	,CONSTRAINT recipes_ingredients_recipes0_FK FOREIGN KEY (recipe_id) REFERENCES recipes(id)
);

