Created
December 10, 2013 19:09
-
-
Save justuseapen/7896301 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#create db: | |
createdb recipes | |
#create tables: | |
CREATE TABLE recipes ( | |
id serial, | |
name varchar(255) NOT NULL, | |
yield int, | |
directions text NOT NULL, | |
time_required int | |
); | |
CREATE TABLE recipe_ingredients ( | |
recipe_id int NOT NULL, | |
quantity varchar(100) NOT NULL, | |
ingredient_id int NOT NULL | |
); | |
CREATE TABLE ingredients ( | |
id serial, | |
name varchar(77) NOT NULL | |
); | |
#insert recipes: | |
INSERT INTO recipes (name, yield, directions, time_required) | |
VALUES ('Green Eggs & Ham', 2, '1. Cook the eggs. | |
2. Cook the ham. | |
3. Combine.', 25 | |
); | |
INSERT INTO recipes (name, directions) | |
VALUES ('Fried Green Tomatoes','1. Slice the tomatoes 1/2 inch thick. | |
2. Whisk eggs and milk together. | |
3. Dip tomatoes in egg mixture and then bread crumbs. | |
4. Heat oil in a large skillet. | |
5. Fry the tomatoes in the oil.' | |
); | |
INSERT INTO recipes (name, yield, directions) | |
VALUES ('Martini',1,'1. Pour all ingredients into mixing glass with ice cubes. | |
2. Stir well. | |
3. Strain in chilled martini cocktail glass. | |
4. Squeeze oil from lemon peel onto the drink, or garnish with olive.' | |
); | |
#insert ingredients: | |
INSERT INTO ingredients (name) | |
VALUES ('Ham'); | |
INSERT INTO ingredients (name) | |
VALUES ('Tomatoes'); | |
INSERT INTO ingredients (name) | |
VALUES ('Eggs'); | |
INSERT INTO ingredients (name) | |
VALUES ('Milk'); | |
INSERT INTO ingredients (name) | |
VALUES ('Breadcrumbs'); | |
INSERT INTO ingredients (name) | |
VALUES ('Vegetable Oil'); | |
INSERT INTO ingredients (name) | |
VALUES ('Lemon Peels'); | |
INSERT INTO ingredients (name) | |
VALUES ('Gin'); | |
INSERT INTO ingredients (name) | |
VALUES ('Dry Vermouth'); | |
INSERT INTO ingredients (name) | |
VALUES ('Vodka'); | |
INSERT INTO ingredients (name) | |
VALUES ('Green Eggs'); | |
#insert associations: | |
INSERT INTO recipe_ingredients (recipe_id, quantity, ingredient_id) | |
VALUES (1,'4',11); | |
INSERT INTO recipe_ingredients (recipe_id, quantity, ingredient_id) | |
VALUES (1, '1/2 lb',1); | |
INSERT INTO recipe_ingredients (recipe_id, quantity, ingredient_id) | |
VALUES (2,'3 large green',2); | |
INSERT INTO recipe_ingredients (recipe_id, quantity, ingredient_id) | |
VALUES (2,'2',3); | |
INSERT INTO recipe_ingredients (recipe_id, quantity, ingredient_id) | |
VALUES (2,'1/2 cup',4); | |
INSERT INTO recipe_ingredients (recipe_id, quantity, ingredient_id) | |
VALUES (2,'1/2 cup',5); | |
INSERT INTO recipe_ingredients (recipe_id, quantity, ingredient_id) | |
VALUES (2,'1 quart',6); | |
INSERT INTO recipe_ingredients (recipe_id, quantity, ingredient_id) | |
VALUES (3,'2 oz',8); | |
INSERT INTO recipe_ingredients (recipe_id, quantity, ingredient_id) | |
VALUES (3,'1 oz',9); | |
INSERT INTO recipe_ingredients (recipe_id, quantity, ingredient_id) | |
VALUES (3,'optional',7); | |
#Update gin to vodka | |
UPDATE recipe_ingredients SET quantity = '3oz' WHERE ingredient_id = 8; | |
UPDATE recipe_ingredients SET ingredient_id = 10 WHERE ingredient_id = 8; | |
#Delete GEAH | |
DELETE FROM recipes WHERE name = 'Green Eggs & Ham'; | |
DELETE FROM recipe_ingredients WHERE recipe_id = 1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment