aretherecookies-server/scripts/ddl.sql

133 lines
4.5 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 ('none', 'few', 'many', 'lots');
CREATE TYPE category AS ENUM ('beverages', 'desserts', 'entrees', 'other');
create table food_items (
id uuid PRIMARY KEY,
name VARCHAR(100),
place_id VARCHAR(50),
category category,
images VARCHAR,
thumbImage VARCHAR,
loc geography(POINT,4326)
);
create table quantities (
food_item_id uuid,
date timestamp (1) with time zone,
quantity quantity,
PRIMARY KEY(food_item_id, date)
);
CREATE INDEX food_loc_index ON food_items USING GIST ( loc );
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',
ST_GeogFromText('SRID=4326;POINT(-97.73798459999999, 30.266898599999998)')
);
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;
SELECT
*,
ST_AsGeoJSON(loc) as location,
ST_Distance(
loc,
ST_GeogFromText('SRID=4326;POINT(-97.7286718 30.3033267)')
) / 1609 as distance
FROM food_items
WHERE
ST_DWithin(
loc,
ST_GeogFromText('SRID=4326;POINT(-97.7286718 30.3033267)'),
10 * 1609
)
ORDER BY distance ASC;