aretherecookies-server/scripts/ddl.sql

106 lines
4.4 KiB
MySQL
Raw Normal View History

2017-10-14 22:04:44 -05:00
CREATE EXTENSION IF NOT EXISTS "postgis";
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE TYPE QUANTITY AS ENUM ('lots', 'many', 'few', 'none');
CREATE TYPE CATEGORY AS ENUM ('beverages', 'desserts', 'entrees', 'other');
DROP TABLE IF EXISTS food_items CASCADE;
CREATE TABLE food_items (
2017-10-14 22:04:44 -05:00
id uuid PRIMARY KEY,
name VARCHAR(100),
place_id VARCHAR(50),
category CATEGORY,
2017-10-14 22:04:44 -05:00
images VARCHAR,
thumbImage VARCHAR,
loc geography(POINT,4326)
);
DROP TABLE quantities CASCADE;
CREATE TABLE quantities (
2017-10-14 22:04:44 -05:00
food_item_id uuid,
date timestamp (1) with time zone,
quantity QUANTITY,
2017-10-14 22:04:44 -05:00
PRIMARY KEY(food_item_id, date)
);
CREATE INDEX IF NOT EXISTS food_loc_index ON food_items USING GIST ( loc );
2017-10-14 22:04:44 -05:00
INSERT INTO food_items (id, name, place_id, category, images, thumbImage, loc)
VALUES (
uuid_generate_v4(),
'Big John Cookies',
'ChIJf5QJFBK1RIYRjjfxZz9Z0O0',
'desserts',
'https://s-media-cache-ak0.pinimg.com/564x/e7/5f/08/e75f08b00c0bc7f2b01b3d1a636389f6.jpg,http://images.media-allrecipes.com/userphotos/560x315/1107530.jpg',
'http://images.media-allrecipes.com/userphotos/560x315/1107530.jpg',
ST_GeogFromText('SRID=4326;POINT(-97.7532464 30.270667599999996)')
);
INSERT INTO food_items (id, name, place_id, category, images, thumbImage, loc)
VALUES (
uuid_generate_v4(),
'Jelly Filled Donuts',
'ChIJ72if-Qe1RIYRCzMucGEEdBA',
'desserts',
'https://timenewsfeed.files.wordpress.com/2013/06/jellydonut.jpg',
'https://timenewsfeed.files.wordpress.com/2013/06/jellydonut.jpg',
ST_GeogFromText('SRID=4326;POINT(-97.742308 30.263963300000004)')
);
INSERT INTO food_items (id, name, place_id, category, images, thumbImage, loc)
VALUES (
uuid_generate_v4(),
'Spelt Brownies',
'ChIJG44vBQi1RIYRvWGHdYUolZY',
'desserts',
'http://www.momshealthyeats.com/wp-content/uploads/2011/11/spelt-fudge-brownie.jpg',
'http://www.momshealthyeats.com/wp-content/uploads/2011/11/spelt-fudge-brownie.jpg',
ST_GeogFromText('SRID=4326;POINT(-97.7419085 30.265019100000004)')
);
INSERT INTO food_items (id, name, place_id, category, images, thumbImage, loc)
VALUES (
uuid_generate_v4(),
'Oatmeal Raisin Cookies',
'ChIJf5QJFBK1RIYRjjfxZz9Z0O0',
'desserts',
'http://cookingontheside.com/wp-content/uploads/2009/04/oatmeal_raisin_cookies_stack-400.jpg',
'http://cookingontheside.com/wp-content/uploads/2009/04/oatmeal_raisin_cookies_stack-400.jpg',
ST_GeogFromText('SRID=4326;POINT(-97.7532464 30.270667599999996)')
);
INSERT INTO food_items (id, name, place_id, category, images, thumbImage, loc)
VALUES (
uuid_generate_v4(),
'Donuts with Sprinkles',
'ChIJ72if-Qe1RIYRCzMucGEEdBA',
'desserts',
'https://dannivee.files.wordpress.com/2013/10/img_1950.jpg',
'https://dannivee.files.wordpress.com/2013/10/img_1950.jpg',
ST_GeogFromText('SRID=4326;POINT(-97.742308 30.263963300000004)')
);
INSERT INTO food_items (id, name, place_id, category, images, thumbImage, loc)
VALUES (
uuid_generate_v4(),
'Powdered Donuts',
'ChIJ72if-Qe1RIYRCzMucGEEdBA',
'desserts',
'http://3.bp.blogspot.com/-NUKSXr1qLHs/UQmsaEFgbTI/AAAAAAAAA_Y/l4psfVl4a5A/s1600/white-powdered-sugar-doughnuts-tracie-kaska.jpg',
'http://3.bp.blogspot.com/-NUKSXr1qLHs/UQmsaEFgbTI/AAAAAAAAA_Y/l4psfVl4a5A/s1600/white-powdered-sugar-doughnuts-tracie-kaska.jpg',
ST_GeogFromText('SRID=4326;POINT(-97.742308 30.263963300000004)')
);
INSERT INTO food_items (id, name, place_id, category, images, thumbImage, loc)
VALUES (
uuid_generate_v4(),
'Snickerdoodles',
'ChIJr3szW6a1RIYRkM7LRpnBIO0',
'desserts',
'http://josephcphillips.com/wp-content/uploads/2015/02/snickerdoodles2.jpg',
'http://josephcphillips.com/wp-content/uploads/2015/02/snickerdoodles2.jpg',
2017-10-29 12:25:00 -05:00
ST_GeogFromText('SRID=4326;POINT(-97.73798459999999 30.266898599999998)')
2017-10-14 22:04:44 -05:00
);
INSERT INTO food_items (id, name, place_id, category, images, thumbImage, loc)
VALUES (
uuid_generate_v4(),
'Pizza',
'ChIJr3szW6a1RIYRkM7LRpnBIO0',
'desserts',
'http://www.foodandhealth.co.uk/wp-content/uploads/2016/05/Hot-stone-Vegan-Pizza.jpg',
'http://www.foodandhealth.co.uk/wp-content/uploads/2016/05/Hot-stone-Vegan-Pizza.jpg',
ST_GeogFromText('SRID=4326;POINT(-97.73798459999999 30.266898599999998)')
);
INSERT INTO quantities SELECT id, current_timestamp, 'many' FROM food_items;
CREATE VIEW latest_quantities AS SELECT food_item_id, quantity, date from quantities q1 where date = (
SELECT max(date) FROM quantities q2 WHERE q1.food_item_id=q2.food_item_id
);