From 66620e5f142f85e26403331ecdeb19cc405ccd1f Mon Sep 17 00:00:00 2001 From: Michael Melo Date: Thu, 23 Aug 2018 21:53:33 -0400 Subject: [PATCH 01/13] Riffing on a REST/entity driven structure --- .gitignore | 1 + api/pet/delete.yaml | 0 api/{delete => pet}/delete_foos.yaml | 0 api/{get => pet}/foo_by_id.dh | 0 api/pet/get.yaml | 0 api/pet/post.yaml | 0 api/pet/put.yaml | 0 api/{get => pet}/search_foos.yaml | 0 api/store/delete.yaml | 0 api/store/get.yaml | 0 api/store/post.yaml | 0 api/store/put.yaml | 0 api/user/delete.yaml | 0 api/user/get.yaml | 0 api/user/post.yaml | 0 api/user/put.yaml | 0 16 files changed, 1 insertion(+) create mode 100644 .gitignore create mode 100644 api/pet/delete.yaml rename api/{delete => pet}/delete_foos.yaml (100%) rename api/{get => pet}/foo_by_id.dh (100%) create mode 100644 api/pet/get.yaml create mode 100644 api/pet/post.yaml create mode 100644 api/pet/put.yaml rename api/{get => pet}/search_foos.yaml (100%) create mode 100644 api/store/delete.yaml create mode 100644 api/store/get.yaml create mode 100644 api/store/post.yaml create mode 100644 api/store/put.yaml create mode 100644 api/user/delete.yaml create mode 100644 api/user/get.yaml create mode 100644 api/user/post.yaml create mode 100644 api/user/put.yaml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9f11b75 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea/ diff --git a/api/pet/delete.yaml b/api/pet/delete.yaml new file mode 100644 index 0000000..e69de29 diff --git a/api/delete/delete_foos.yaml b/api/pet/delete_foos.yaml similarity index 100% rename from api/delete/delete_foos.yaml rename to api/pet/delete_foos.yaml diff --git a/api/get/foo_by_id.dh b/api/pet/foo_by_id.dh similarity index 100% rename from api/get/foo_by_id.dh rename to api/pet/foo_by_id.dh diff --git a/api/pet/get.yaml b/api/pet/get.yaml new file mode 100644 index 0000000..e69de29 diff --git a/api/pet/post.yaml b/api/pet/post.yaml new file mode 100644 index 0000000..e69de29 diff --git a/api/pet/put.yaml b/api/pet/put.yaml new file mode 100644 index 0000000..e69de29 diff --git a/api/get/search_foos.yaml b/api/pet/search_foos.yaml similarity index 100% rename from api/get/search_foos.yaml rename to api/pet/search_foos.yaml diff --git a/api/store/delete.yaml b/api/store/delete.yaml new file mode 100644 index 0000000..e69de29 diff --git a/api/store/get.yaml b/api/store/get.yaml new file mode 100644 index 0000000..e69de29 diff --git a/api/store/post.yaml b/api/store/post.yaml new file mode 100644 index 0000000..e69de29 diff --git a/api/store/put.yaml b/api/store/put.yaml new file mode 100644 index 0000000..e69de29 diff --git a/api/user/delete.yaml b/api/user/delete.yaml new file mode 100644 index 0000000..e69de29 diff --git a/api/user/get.yaml b/api/user/get.yaml new file mode 100644 index 0000000..e69de29 diff --git a/api/user/post.yaml b/api/user/post.yaml new file mode 100644 index 0000000..e69de29 diff --git a/api/user/put.yaml b/api/user/put.yaml new file mode 100644 index 0000000..e69de29 From c9ba3aa2d1119dcd55de7f61b657ba03538bb7cf Mon Sep 17 00:00:00 2001 From: Michael Melo Date: Thu, 23 Aug 2018 22:42:48 -0400 Subject: [PATCH 02/13] A first pass at defining POSTing a pet --- api/pet/post.yaml | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/api/pet/post.yaml b/api/pet/post.yaml index e69de29..6689ff0 100644 --- a/api/pet/post.yaml +++ b/api/pet/post.yaml @@ -0,0 +1,32 @@ +--- +what: + Add a new pet to the store + +POST: /pet +BODY: + id: integer($int64) + category: { + id: integer($int64), + name: string + } + name: string + photosUrls: [string] + tags: { + id: integer($int64), + name: string + } + status: regex ^(available|pending|sold)$ + +# The result of inserting the label 'pet' below +RESULT: pet + +# The framework returns the result of the last insert statement, in this case our 'pet' +# All inserts are part of the same transaction; boundaries can default to the whole of a 'label' +pet: |- + insert into category (id, name) values ({id}, {name}); + insert into tags (id, name) values ({id}, {name}); + insert into pets (id, name, photos_urls, status) values ({id}, {name}, {photosUrls}, {status}); + +# +# Tests go here, if you'd like +#tests: \ No newline at end of file From 48683c9922590b39831c800e051a5455cb52643d Mon Sep 17 00:00:00 2001 From: Michael Melo Date: Thu, 23 Aug 2018 22:50:18 -0400 Subject: [PATCH 03/13] Dot notation --- api/pet/post.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/pet/post.yaml b/api/pet/post.yaml index 6689ff0..29f42c2 100644 --- a/api/pet/post.yaml +++ b/api/pet/post.yaml @@ -23,8 +23,8 @@ RESULT: pet # The framework returns the result of the last insert statement, in this case our 'pet' # All inserts are part of the same transaction; boundaries can default to the whole of a 'label' pet: |- - insert into category (id, name) values ({id}, {name}); - insert into tags (id, name) values ({id}, {name}); + insert into category (id, name) values ({category.id}, {category.name}); + insert into tags (id, name) values ({tags.id}, {tags.name}); insert into pets (id, name, photos_urls, status) values ({id}, {name}, {photosUrls}, {status}); # From 64198e9ab6c24db0ae985dd78f7170a46a6f062c Mon Sep 17 00:00:00 2001 From: mike-melo Date: Fri, 24 Aug 2018 00:08:01 -0400 Subject: [PATCH 04/13] Upsert instead of insert --- api/pet/post.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/api/pet/post.yaml b/api/pet/post.yaml index 29f42c2..2d850af 100644 --- a/api/pet/post.yaml +++ b/api/pet/post.yaml @@ -23,10 +23,10 @@ RESULT: pet # The framework returns the result of the last insert statement, in this case our 'pet' # All inserts are part of the same transaction; boundaries can default to the whole of a 'label' pet: |- - insert into category (id, name) values ({category.id}, {category.name}); - insert into tags (id, name) values ({tags.id}, {tags.name}); + upsert into category (id, name) values ({category.id}, {category.name}); + upsert into tags (id, name) values ({tags.id}, {tags.name}); insert into pets (id, name, photos_urls, status) values ({id}, {name}, {photosUrls}, {status}); # # Tests go here, if you'd like -#tests: \ No newline at end of file +#tests: From 3574f876b3aa167d448db64f6c5b898d820a6ea7 Mon Sep 17 00:00:00 2001 From: mike-melo Date: Fri, 24 Aug 2018 20:34:22 -0400 Subject: [PATCH 05/13] Revised to reflect more of the .dh format --- api/pet/post.yaml | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/api/pet/post.yaml b/api/pet/post.yaml index 2d850af..47140f1 100644 --- a/api/pet/post.yaml +++ b/api/pet/post.yaml @@ -1,9 +1,9 @@ --- -what: - Add a new pet to the store +ENDPOINT + Adds a new pet to the store -POST: /pet -BODY: +POST /pet +BODY id: integer($int64) category: { id: integer($int64), @@ -17,16 +17,11 @@ BODY: } status: regex ^(available|pending|sold)$ -# The result of inserting the label 'pet' below -RESULT: pet - # The framework returns the result of the last insert statement, in this case our 'pet' # All inserts are part of the same transaction; boundaries can default to the whole of a 'label' -pet: |- +RETURNING SINGLE FROM upsert into category (id, name) values ({category.id}, {category.name}); upsert into tags (id, name) values ({tags.id}, {tags.name}); insert into pets (id, name, photos_urls, status) values ({id}, {name}, {photosUrls}, {status}); -# -# Tests go here, if you'd like -#tests: +ENSURING From da69138b6af03adc8b1b1a06412d483702705ed5 Mon Sep 17 00:00:00 2001 From: mike-melo Date: Fri, 24 Aug 2018 22:07:01 -0400 Subject: [PATCH 06/13] Some more fluency --- api/pet/post.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/api/pet/post.yaml b/api/pet/post.yaml index 47140f1..5fcb52c 100644 --- a/api/pet/post.yaml +++ b/api/pet/post.yaml @@ -19,9 +19,11 @@ BODY # The framework returns the result of the last insert statement, in this case our 'pet' # All inserts are part of the same transaction; boundaries can default to the whole of a 'label' -RETURNING SINGLE FROM +FIRST upsert into category (id, name) values ({category.id}, {category.name}); upsert into tags (id, name) values ({tags.id}, {tags.name}); + +THEN RETURN RESULT FROM insert into pets (id, name, photos_urls, status) values ({id}, {name}, {photosUrls}, {status}); ENSURING From 532dc819e238b8d2033812e3bdd03e5333745224 Mon Sep 17 00:00:00 2001 From: vivri Date: Tue, 28 Aug 2018 22:29:24 -0400 Subject: [PATCH 07/13] migration script reflects swagger entities --- api/pet/delete.yaml | 0 api/pet/delete_foos.yaml | 77 ----------------------------- api/pet/foo_by_id.dh | 27 ---------- api/pet/get.yaml | 0 api/pet/post.yaml | 29 ----------- api/pet/put.yaml | 0 api/pet/search_foos.yaml | 25 ---------- api/pet_entity.dh | 33 +++++++++++++ api/store/delete.yaml | 0 api/store/get.yaml | 0 api/store/post.yaml | 0 api/store/put.yaml | 0 api/user/delete.yaml | 0 api/user/get.yaml | 0 api/user/post.yaml | 0 api/user/put.yaml | 0 database/migrations/1_initialize.dh | 71 -------------------------- migrations/1_initialize.dh | 36 ++++++++++++++ 18 files changed, 69 insertions(+), 229 deletions(-) delete mode 100644 api/pet/delete.yaml delete mode 100644 api/pet/delete_foos.yaml delete mode 100644 api/pet/foo_by_id.dh delete mode 100644 api/pet/get.yaml delete mode 100644 api/pet/post.yaml delete mode 100644 api/pet/put.yaml delete mode 100644 api/pet/search_foos.yaml create mode 100644 api/pet_entity.dh delete mode 100644 api/store/delete.yaml delete mode 100644 api/store/get.yaml delete mode 100644 api/store/post.yaml delete mode 100644 api/store/put.yaml delete mode 100644 api/user/delete.yaml delete mode 100644 api/user/get.yaml delete mode 100644 api/user/post.yaml delete mode 100644 api/user/put.yaml delete mode 100644 database/migrations/1_initialize.dh create mode 100644 migrations/1_initialize.dh diff --git a/api/pet/delete.yaml b/api/pet/delete.yaml deleted file mode 100644 index e69de29..0000000 diff --git a/api/pet/delete_foos.yaml b/api/pet/delete_foos.yaml deleted file mode 100644 index b28dd6f..0000000 --- a/api/pet/delete_foos.yaml +++ /dev/null @@ -1,77 +0,0 @@ ---- -what: - deletes foos by id xor (color and/or shape) - -DELETE: /foos?{id}{color}{shape} - -params: - declarations: - id: Int range (1,4000000) - color: UTF8 length (1,16) - shape: ASCII regex ^(circle|square|[a-z]+gon)$ # circle, square, hexagon, pentagon,... - combinations: - (id |xor| (color |or| shape)) # id xor (color or shape) must be set - -# see `user_roles.yaml` -# if this is absent, full access is silently granted. -# since the special `resource_owner` role is specified, we need an `resource_ownership_test` -# to determine if the user is indeed an owner. -access_control: [store_owner, admin, resource_owner] - -# Testing for resource_ownership. Default is false -# -# general switch statement, can embed all top-level declarations that will "percolate up", -# including nested `switch` statements -switch: - - - case: (headers.User_Id |and| id) - resource_ownership_test: - query: # returning a row signifies success; empty result-set is failure - select * from foo where id={id} and foo_owner_id={headers.User_Id} - - - case: (headers.User_Id |and| (color |or| shape)) - resource_ownership_test: - query: |- - select * from foo - where - foo_owner_id={headers.User_Id} and - [(color) color={color}] - [(shape) and shape={shape}]; - - - # default case has no `case` clause - resource_ownership_test: - expression: (F) # always false - -switch: - - - case: (id) # if `id` exists - query: - delete from foo where id={id}; - - - case: (color |or| shape) - query: |- - delete from foo - where - [(color) color={color}] - [(shape) and shape={shape}]; - -# Record and test the expected behavior of the query, if you'd like - tests: - - - it: should properly set the resource ownership test - when: - headers: - User_Id: 123abc - params: - id: doggo123 - then: - endpoint_meta: - resource_ownership_test: - query: |- - select * from foo where id={id} and foo_owner_id={headers.User_Id} - - - - - - \ No newline at end of file diff --git a/api/pet/foo_by_id.dh b/api/pet/foo_by_id.dh deleted file mode 100644 index 7d8f9c1..0000000 --- a/api/pet/foo_by_id.dh +++ /dev/null @@ -1,27 +0,0 @@ -ENDPOINT selects a foo by id -GET /foos/{id} -PARAMS - id uint64 -RETURNING SINGLE FROM - select top 1 from foos where id={id}; - -ENSURING -> it shouldn't find results - given - truncate foos; - when - id = 1 - then - code 404 - -> it should find a record - given - truncate foos; - insert into foo (id, name) values (1, 'blah'), (2, 'yolo'); - when - id = 1 - then - code 200 - results - id name - 1 blah \ No newline at end of file diff --git a/api/pet/get.yaml b/api/pet/get.yaml deleted file mode 100644 index e69de29..0000000 diff --git a/api/pet/post.yaml b/api/pet/post.yaml deleted file mode 100644 index 5fcb52c..0000000 --- a/api/pet/post.yaml +++ /dev/null @@ -1,29 +0,0 @@ ---- -ENDPOINT - Adds a new pet to the store - -POST /pet -BODY - id: integer($int64) - category: { - id: integer($int64), - name: string - } - name: string - photosUrls: [string] - tags: { - id: integer($int64), - name: string - } - status: regex ^(available|pending|sold)$ - -# The framework returns the result of the last insert statement, in this case our 'pet' -# All inserts are part of the same transaction; boundaries can default to the whole of a 'label' -FIRST - upsert into category (id, name) values ({category.id}, {category.name}); - upsert into tags (id, name) values ({tags.id}, {tags.name}); - -THEN RETURN RESULT FROM - insert into pets (id, name, photos_urls, status) values ({id}, {name}, {photosUrls}, {status}); - -ENSURING diff --git a/api/pet/put.yaml b/api/pet/put.yaml deleted file mode 100644 index e69de29..0000000 diff --git a/api/pet/search_foos.yaml b/api/pet/search_foos.yaml deleted file mode 100644 index 88a808d..0000000 --- a/api/pet/search_foos.yaml +++ /dev/null @@ -1,25 +0,0 @@ ---- -what: - Search foos by parameters - -GET: /foos?{color}{shape} -RESULT: PAGINATED_LIST # the PAGINATED_LIST listens for custom headers for: - # page-number, per-page, sort-by-field, sort-order - -params: - declarations: - color: UTF8 length (1,16) - shape: ASCII regex ^(circle|square|[a-z]+gon)$ # circle, square, hexagon, pentagon,... - combinations: # boolean expression that specifies valid parameter combinations - (color) # here, `color` is mandatory, while `shape` isn't - -# a paginated list query provides (and necessitates) the use of: -# {page_offset}, {per_page}, {sort_field}, {sort_order} -query: |- - select top({per_page}) from foo - where color={color}[(shape) and shape={shape}] # will emit `expr` if `shape` is set - offset {page_offset} - sort by {sort_field} {sort_order}; - -# Tests go here, if you'd like -#tests: \ No newline at end of file diff --git a/api/pet_entity.dh b/api/pet_entity.dh new file mode 100644 index 0000000..7a7b165 --- /dev/null +++ b/api/pet_entity.dh @@ -0,0 +1,33 @@ +################################################### +# Describes a CRUD Entity mapped to a table +# Generates the following endpoints: +# - GET /pet/{primary key} +# - GET LIST /pet?{filter/search params}{pagination params} +# - POST /pet (create) +# - PUT /pet (upsert) +# - PATCH /pet (update) +# - DELETE /pet +# +# Caching (if "ON") uses "pets" as the cache key +# and caches results to /pets/{id}, +# invalidating the cache on PUT and DELETE to that {id} + +CRUD ENTITY /pets +MAPS TO TABLE pets +FIELDS + id uint32 pk + category uint32 fk(categories(id)) + name string size [1,32] + photoUrls [url] mapsToField(photo_urls) optional + tags [string] size [1,32] fk(tags) optional + status string regex ^(available|pending|sold)$ + +CACHING IS ON + +AUTHORIZING + GET BY ID to * + GET SEARCH to * + PUT to store_employee + POST to store_employee + PATCH to store_employee + DELETE to store_owner \ No newline at end of file diff --git a/api/store/delete.yaml b/api/store/delete.yaml deleted file mode 100644 index e69de29..0000000 diff --git a/api/store/get.yaml b/api/store/get.yaml deleted file mode 100644 index e69de29..0000000 diff --git a/api/store/post.yaml b/api/store/post.yaml deleted file mode 100644 index e69de29..0000000 diff --git a/api/store/put.yaml b/api/store/put.yaml deleted file mode 100644 index e69de29..0000000 diff --git a/api/user/delete.yaml b/api/user/delete.yaml deleted file mode 100644 index e69de29..0000000 diff --git a/api/user/get.yaml b/api/user/get.yaml deleted file mode 100644 index e69de29..0000000 diff --git a/api/user/post.yaml b/api/user/post.yaml deleted file mode 100644 index e69de29..0000000 diff --git a/api/user/put.yaml b/api/user/put.yaml deleted file mode 100644 index e69de29..0000000 diff --git a/database/migrations/1_initialize.dh b/database/migrations/1_initialize.dh deleted file mode 100644 index a68cde2..0000000 --- a/database/migrations/1_initialize.dh +++ /dev/null @@ -1,71 +0,0 @@ -MIGRATION(1) initialize the database -UP - CREATE TABLE pet_types ( - id int auto_increment, - name varchar(32) not null - ); - - CREATE TABLE pets ( - id int auto_increment, - pet_type int fk(pet_types(id)) not null, - date_of_birth datetime, - name varchar(32), - listed_price float(2), # with decimal precision of 2 - date_sold datetime - ); - - create function func1 (input) - function body - returns output - end func1; - - create procedure proc1 (input) - procedure body - change state in tables - no return - end proc1; - -DOWN - drop table pets; - drop table pet_types; - drop function func1; - drop procedure proc1; - -# for testing functions/procedures, but also constraints, and anything else -ENSURING -> it should test the stored proc - given - truncate foo; - truncate bar; - insert (a, b, c) into foo; - insert (a, b, c) into bar; - - # call the tested procedure and return a data-set - when - call proc1(x); - select * from foo; - # validate the returned tab-delimited, tabulated data set - then - Col1 Col2 Col3 - A' B' c - A2' B2' c - -> it shold test the stored function - # stateless functions may not have a `given` block - # OTOH, if `func1` relied on data, it should have been prepped - when - select func1('y') as Res - then - Res - Y' - -> it should test unique constraint foo(a) - given - truncate foo; - insert (a, b, c) into foo; - when - insert (a, d, e) into foo; - select * from foo; - then - COL1 COL2 COL3 - a b c \ No newline at end of file diff --git a/migrations/1_initialize.dh b/migrations/1_initialize.dh new file mode 100644 index 0000000..493c026 --- /dev/null +++ b/migrations/1_initialize.dh @@ -0,0 +1,36 @@ +MIGRATION(1) initialize the database +UP + CREATE TABLE categories ( + id serial PRIMARY KEY, + name varchar(32) not null + ); + + CREATE TYPE pet_status AS ENUM ('available', 'sold', 'pending'); + + CREATE TABLE pets ( + id serial PRIMARY KEY, + category integer REFERENCES categories (id) NOT NULL, + name varchar(32) NOT NULL, + tags varchar(32)[] NOT NULL, + photo_urls varchar(256)[] NOT NULL, + status pet_status NOT NULL + ); + + CREATE TYPE order_status AS ENUM ('placed', 'approved', 'delivered'); + + CREATE TABLE orders ( + id serial PRIMARY KEY, + pet_id integer REFERENCES pets (id) NOT NULL, + quantity integer NOT NULL, + ship_date timestamp with time zone NOT NULL, + status order_status NOT NULL, + complete boolean NOT NULL + ); + +DOWN + drop table categories; + drop table orders; + drop table pets; + drop type pet_status; + drop type order_status; + \ No newline at end of file From 5488afcd99bd199a221b5269b7ef7ca789667ed9 Mon Sep 17 00:00:00 2001 From: vivri Date: Tue, 28 Aug 2018 23:03:50 -0400 Subject: [PATCH 08/13] get inventory endpoint --- api/store/get_inventory.dh | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 api/store/get_inventory.dh diff --git a/api/store/get_inventory.dh b/api/store/get_inventory.dh new file mode 100644 index 0000000..8a36346 --- /dev/null +++ b/api/store/get_inventory.dh @@ -0,0 +1,27 @@ +ENDPOINT gets the aggregated inventory +GET LIST /store/inventory +FROM + select status, count(status) as pets from pets group by status; + +ENSURING +SETUP + BEFORE EACH + truncate pets; + +> it should not find results when table is empty + then + code 404 + +> it should return expected results + given + insert into pets (name, status) values ('pet1', 'pending'); + insert into pets (name, status) values ('pet2', 'available'); + insert into pets (name, status) values ('pet3', 'sold'); + insert into pets (name, status) values ('pet4', 'pending'); + then + code 200 + result + status pets + pending 2 + available 1 + sold 1 \ No newline at end of file From 24c6073df48d52afba028407b8244716a723f460 Mon Sep 17 00:00:00 2001 From: vivri Date: Tue, 28 Aug 2018 23:04:49 -0400 Subject: [PATCH 09/13] shortened the ENSURING stage --- api/store/get_inventory.dh | 1 - 1 file changed, 1 deletion(-) diff --git a/api/store/get_inventory.dh b/api/store/get_inventory.dh index 8a36346..08a078b 100644 --- a/api/store/get_inventory.dh +++ b/api/store/get_inventory.dh @@ -4,7 +4,6 @@ FROM select status, count(status) as pets from pets group by status; ENSURING -SETUP BEFORE EACH truncate pets; From 9d426fc164b40dedb2f417c53b98a8cf74116aca Mon Sep 17 00:00:00 2001 From: vivri Date: Tue, 28 Aug 2018 23:23:05 -0400 Subject: [PATCH 10/13] re-introduce post recursive params --- api/pet/post.dh | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 api/pet/post.dh diff --git a/api/pet/post.dh b/api/pet/post.dh new file mode 100644 index 0000000..610734d --- /dev/null +++ b/api/pet/post.dh @@ -0,0 +1,30 @@ +# +# - experimental: recursive POST params +# + +ENDPOINT + Adds a new pet to the store + +POST /pet +BODY + id uint32 + category { + id uint32 + name string length[1,32] + } + name string length[1,32] + photo_urls [url] + tags { + id uint32 + name string length[1,32] + } + status regex ^(available|pending|sold)$ + +# The framework returns the result of the last insert statement, in this case our 'pet' +# All inserts are part of the same transaction; boundaries can default to the whole of a 'label' +FIRST + upsert into category (id, name) values ({category.id}, {category.name}); + upsert into tags (id, name) values ({tags.id}, {tags.name}); + +THEN RETURN RESULT FROM + insert into pets (id, name, photos_urls, status) values ({id}, {name}, {photosUrls}, {status}); From 105bc195057326f7b654a839eee05dbbfc15c727 Mon Sep 17 00:00:00 2001 From: vivri Date: Tue, 18 Sep 2018 00:08:54 -0400 Subject: [PATCH 11/13] updated the format --- api/store/get_inventory.dh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/api/store/get_inventory.dh b/api/store/get_inventory.dh index 08a078b..5c30292 100644 --- a/api/store/get_inventory.dh +++ b/api/store/get_inventory.dh @@ -4,14 +4,14 @@ FROM select status, count(status) as pets from pets group by status; ENSURING - BEFORE EACH + WITH CLEANUP truncate pets; -> it should not find results when table is empty + it should not find results when table is empty then code 404 -> it should return expected results + it should return expected results given insert into pets (name, status) values ('pet1', 'pending'); insert into pets (name, status) values ('pet2', 'available'); From 834dce3e199f72429e50db321fcc6d3f26d24b0c Mon Sep 17 00:00:00 2001 From: vivri Date: Tue, 18 Sep 2018 00:09:12 -0400 Subject: [PATCH 12/13] updated the format --- migrations/1_initialize.dh | 2 +- migrations/2_something_else.dh | 36 ++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 migrations/2_something_else.dh diff --git a/migrations/1_initialize.dh b/migrations/1_initialize.dh index 493c026..26ac3e2 100644 --- a/migrations/1_initialize.dh +++ b/migrations/1_initialize.dh @@ -1,4 +1,4 @@ -MIGRATION(1) initialize the database +MIGRATION initialize the database UP CREATE TABLE categories ( id serial PRIMARY KEY, diff --git a/migrations/2_something_else.dh b/migrations/2_something_else.dh new file mode 100644 index 0000000..26ac3e2 --- /dev/null +++ b/migrations/2_something_else.dh @@ -0,0 +1,36 @@ +MIGRATION initialize the database +UP + CREATE TABLE categories ( + id serial PRIMARY KEY, + name varchar(32) not null + ); + + CREATE TYPE pet_status AS ENUM ('available', 'sold', 'pending'); + + CREATE TABLE pets ( + id serial PRIMARY KEY, + category integer REFERENCES categories (id) NOT NULL, + name varchar(32) NOT NULL, + tags varchar(32)[] NOT NULL, + photo_urls varchar(256)[] NOT NULL, + status pet_status NOT NULL + ); + + CREATE TYPE order_status AS ENUM ('placed', 'approved', 'delivered'); + + CREATE TABLE orders ( + id serial PRIMARY KEY, + pet_id integer REFERENCES pets (id) NOT NULL, + quantity integer NOT NULL, + ship_date timestamp with time zone NOT NULL, + status order_status NOT NULL, + complete boolean NOT NULL + ); + +DOWN + drop table categories; + drop table orders; + drop table pets; + drop type pet_status; + drop type order_status; + \ No newline at end of file From 4ca3382b861e9873cc2d0c80a6ffb0f51838c29c Mon Sep 17 00:00:00 2001 From: vivri Date: Tue, 18 Sep 2018 00:19:46 -0400 Subject: [PATCH 13/13] replace migration with something that has tests --- migrations/2_something_else.dh | 42 +++++++++++----------------------- 1 file changed, 13 insertions(+), 29 deletions(-) diff --git a/migrations/2_something_else.dh b/migrations/2_something_else.dh index 26ac3e2..69c344f 100644 --- a/migrations/2_something_else.dh +++ b/migrations/2_something_else.dh @@ -1,36 +1,20 @@ -MIGRATION initialize the database +MIGRATION setting up some tables UP CREATE TABLE categories ( id serial PRIMARY KEY, name varchar(32) not null ); - - CREATE TYPE pet_status AS ENUM ('available', 'sold', 'pending'); - - CREATE TABLE pets ( - id serial PRIMARY KEY, - category integer REFERENCES categories (id) NOT NULL, - name varchar(32) NOT NULL, - tags varchar(32)[] NOT NULL, - photo_urls varchar(256)[] NOT NULL, - status pet_status NOT NULL - ); - - CREATE TYPE order_status AS ENUM ('placed', 'approved', 'delivered'); - - CREATE TABLE orders ( - id serial PRIMARY KEY, - pet_id integer REFERENCES pets (id) NOT NULL, - quantity integer NOT NULL, - ship_date timestamp with time zone NOT NULL, - status order_status NOT NULL, - complete boolean NOT NULL - ); - DOWN drop table categories; - drop table orders; - drop table pets; - drop type pet_status; - drop type order_status; - \ No newline at end of file + +ENSURING + it should test our clever assumptions + given + this thing right there + and that one, too + when + i do this really clever thing + then + col1 col2 `col 3` + 1 `2 3` 4 + a b c \ No newline at end of file