From 4ea47bd507de08b958d2f46f152d468d3ff4273c Mon Sep 17 00:00:00 2001 From: Naomi Aro Date: Fri, 19 Mar 2021 14:23:16 -0700 Subject: [PATCH 1/7] Add first sqitch stuff --- .gitignore | 1 + schema/deploy/appschema.sql | 9 +++++++++ schema/revert/appschema.sql | 9 +++++++++ schema/sqitch.conf | 8 ++++++++ schema/sqitch.plan | 5 +++++ schema/verify/appschema.sql | 9 +++++++++ 6 files changed, 41 insertions(+) create mode 100644 .gitignore create mode 100644 schema/deploy/appschema.sql create mode 100644 schema/revert/appschema.sql create mode 100644 schema/sqitch.conf create mode 100644 schema/sqitch.plan create mode 100644 schema/verify/appschema.sql diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e43b0f9 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.DS_Store diff --git a/schema/deploy/appschema.sql b/schema/deploy/appschema.sql new file mode 100644 index 0000000..27329ef --- /dev/null +++ b/schema/deploy/appschema.sql @@ -0,0 +1,9 @@ +-- Deploy onboarding:appschema to pg + +BEGIN; + +-- XXX Add DDLs here. + +CREATE SCHEMA onboarding; + +COMMIT; diff --git a/schema/revert/appschema.sql b/schema/revert/appschema.sql new file mode 100644 index 0000000..06d5e39 --- /dev/null +++ b/schema/revert/appschema.sql @@ -0,0 +1,9 @@ +-- Revert onboarding:appschema from pg + +BEGIN; + +-- XXX Add DDLs here. + +DROP SCHEMA onboarding; + +COMMIT; diff --git a/schema/sqitch.conf b/schema/sqitch.conf new file mode 100644 index 0000000..3447459 --- /dev/null +++ b/schema/sqitch.conf @@ -0,0 +1,8 @@ +[core] + engine = pg + # plan_file = sqitch.plan + # top_dir = . +# [engine "pg"] + # target = db:pg: + # registry = sqitch + # client = psql diff --git a/schema/sqitch.plan b/schema/sqitch.plan new file mode 100644 index 0000000..0efb13b --- /dev/null +++ b/schema/sqitch.plan @@ -0,0 +1,5 @@ +%syntax-version=1.0.0 +%project=onboarding +%uri=https://github.com/naomiaro/button-onboarding + +appschema 2021-03-19T20:12:31Z Naomi Aro # Add schema for all onboarding objects. diff --git a/schema/verify/appschema.sql b/schema/verify/appschema.sql new file mode 100644 index 0000000..b338efd --- /dev/null +++ b/schema/verify/appschema.sql @@ -0,0 +1,9 @@ +-- Verify onboarding:appschema on pg + +BEGIN; + +-- XXX Add verifications here. + +SELECT pg_catalog.has_schema_privilege('onboarding', 'usage'); + +ROLLBACK; From 4c85dbcb80a02e29d99988c4a3ae8737f5ca23ef Mon Sep 17 00:00:00 2001 From: Naomi Aro Date: Fri, 19 Mar 2021 15:21:13 -0700 Subject: [PATCH 2/7] update sqitch conf --- schema/sqitch.conf | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/schema/sqitch.conf b/schema/sqitch.conf index 3447459..7172f75 100644 --- a/schema/sqitch.conf +++ b/schema/sqitch.conf @@ -6,3 +6,11 @@ # target = db:pg: # registry = sqitch # client = psql +[target "onboarding"] + uri = db:pg:onboarding +[engine "pg"] + target = onboarding +[deploy] + verify = true +[rebase] + verify = true From 1e3bc705a40c3f726ee826610e8a1c4d19a0a22d Mon Sep 17 00:00:00 2001 From: Naomi Aro Date: Tue, 23 Mar 2021 11:05:47 -0700 Subject: [PATCH 3/7] create appschema for todo_app --- .gitattributes | 1 + schema/deploy/appschema.sql | 2 +- schema/revert/appschema.sql | 2 +- schema/sqitch.conf | 6 ++++-- schema/verify/appschema.sql | 2 +- 5 files changed, 8 insertions(+), 5 deletions(-) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..164c72a --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +schema/sqitch.plan merge=union diff --git a/schema/deploy/appschema.sql b/schema/deploy/appschema.sql index 27329ef..2369d75 100644 --- a/schema/deploy/appschema.sql +++ b/schema/deploy/appschema.sql @@ -4,6 +4,6 @@ BEGIN; -- XXX Add DDLs here. -CREATE SCHEMA onboarding; +CREATE SCHEMA todo_app; COMMIT; diff --git a/schema/revert/appschema.sql b/schema/revert/appschema.sql index 06d5e39..a2c0307 100644 --- a/schema/revert/appschema.sql +++ b/schema/revert/appschema.sql @@ -4,6 +4,6 @@ BEGIN; -- XXX Add DDLs here. -DROP SCHEMA onboarding; +DROP SCHEMA todo_app; COMMIT; diff --git a/schema/sqitch.conf b/schema/sqitch.conf index 7172f75..ceb96f9 100644 --- a/schema/sqitch.conf +++ b/schema/sqitch.conf @@ -8,9 +8,11 @@ # client = psql [target "onboarding"] uri = db:pg:onboarding -[engine "pg"] - target = onboarding [deploy] verify = true [rebase] verify = true +[target "todo_app"] + uri = db:pg:todo_app +[engine "pg"] + target = todo_app diff --git a/schema/verify/appschema.sql b/schema/verify/appschema.sql index b338efd..304b91a 100644 --- a/schema/verify/appschema.sql +++ b/schema/verify/appschema.sql @@ -4,6 +4,6 @@ BEGIN; -- XXX Add verifications here. -SELECT pg_catalog.has_schema_privilege('onboarding', 'usage'); +SELECT pg_catalog.has_schema_privilege('todo_app', 'usage'); ROLLBACK; From 42cc597a0399020b1485eab93d1d57d0a0f96dec Mon Sep 17 00:00:00 2001 From: Naomi Aro Date: Tue, 23 Mar 2021 11:23:35 -0700 Subject: [PATCH 4/7] create todos sqitch files --- schema/deploy/todos.sql | 16 ++++++++++++++++ schema/revert/todos.sql | 7 +++++++ schema/sqitch.conf | 8 -------- schema/sqitch.plan | 1 + schema/verify/todos.sql | 9 +++++++++ 5 files changed, 33 insertions(+), 8 deletions(-) create mode 100644 schema/deploy/todos.sql create mode 100644 schema/revert/todos.sql create mode 100644 schema/verify/todos.sql diff --git a/schema/deploy/todos.sql b/schema/deploy/todos.sql new file mode 100644 index 0000000..ea0082f --- /dev/null +++ b/schema/deploy/todos.sql @@ -0,0 +1,16 @@ +-- Deploy onboarding:todo_app.todos to pg +-- requires: appschema + +BEGIN; + +SET client_min_messages = 'warning'; + +CREATE TABLE todo_app.todos ( + id SERIAL PRIMARY KEY, + task TEXT NOT NULL, + completed BOOLEAN NOT NULL DEFAULT FALSE, + date_created TIMESTAMPTZ NOT NULL DEFAULT NOW(), + date_updated TIMESTAMPTZ NOT NULL DEFAULT NOW() +); + +COMMIT; diff --git a/schema/revert/todos.sql b/schema/revert/todos.sql new file mode 100644 index 0000000..33cc824 --- /dev/null +++ b/schema/revert/todos.sql @@ -0,0 +1,7 @@ +-- Revert onboarding:todo_app.todos from pg + +BEGIN; + +DROP TABLE todo_app.todos; + +COMMIT; diff --git a/schema/sqitch.conf b/schema/sqitch.conf index ceb96f9..425c449 100644 --- a/schema/sqitch.conf +++ b/schema/sqitch.conf @@ -1,13 +1,5 @@ [core] engine = pg - # plan_file = sqitch.plan - # top_dir = . -# [engine "pg"] - # target = db:pg: - # registry = sqitch - # client = psql -[target "onboarding"] - uri = db:pg:onboarding [deploy] verify = true [rebase] diff --git a/schema/sqitch.plan b/schema/sqitch.plan index 0efb13b..8a6e4e6 100644 --- a/schema/sqitch.plan +++ b/schema/sqitch.plan @@ -3,3 +3,4 @@ %uri=https://github.com/naomiaro/button-onboarding appschema 2021-03-19T20:12:31Z Naomi Aro # Add schema for all onboarding objects. +todos [appschema] 2021-03-23T18:08:10Z Naomi Aro # Creates a table for the todos. diff --git a/schema/verify/todos.sql b/schema/verify/todos.sql new file mode 100644 index 0000000..3f43ced --- /dev/null +++ b/schema/verify/todos.sql @@ -0,0 +1,9 @@ +-- Verify onboarding:todo_app.todos on pg + +BEGIN; + +SELECT id, task, completed, date_created, date_updated + FROM todo_app.todos + WHERE FALSE; + +ROLLBACK; From 7181feb4c8dec25fcf371e2befff27155afdaf66 Mon Sep 17 00:00:00 2001 From: Naomi Aro Date: Tue, 23 Mar 2021 14:00:01 -0700 Subject: [PATCH 5/7] create an insert todo function --- schema/deploy/insert_todo.sql | 14 ++++++++++++++ schema/revert/insert_todo.sql | 7 +++++++ schema/sqitch.plan | 1 + schema/verify/insert_todo.sql | 7 +++++++ 4 files changed, 29 insertions(+) create mode 100644 schema/deploy/insert_todo.sql create mode 100644 schema/revert/insert_todo.sql create mode 100644 schema/verify/insert_todo.sql diff --git a/schema/deploy/insert_todo.sql b/schema/deploy/insert_todo.sql new file mode 100644 index 0000000..af0fe9e --- /dev/null +++ b/schema/deploy/insert_todo.sql @@ -0,0 +1,14 @@ +-- Deploy onboarding:todo_app.insert_todo to pg +-- requires: todos +-- requires: appschema + +BEGIN; + +CREATE OR REPLACE FUNCTION todo_app.insert_todo( + task TEXT, + completed BOOLEAN +) RETURNS VOID LANGUAGE SQL SECURITY DEFINER AS $$ + INSERT INTO todo_app.todos (task, completed) VALUES($1, $2); +$$; + +COMMIT; diff --git a/schema/revert/insert_todo.sql b/schema/revert/insert_todo.sql new file mode 100644 index 0000000..0b7a992 --- /dev/null +++ b/schema/revert/insert_todo.sql @@ -0,0 +1,7 @@ +-- Revert onboarding:todo_app.insert_todo from pg + +BEGIN; + +DROP FUNCTION todo_app.insert_todo(TEXT, BOOLEAN); + +COMMIT; diff --git a/schema/sqitch.plan b/schema/sqitch.plan index 8a6e4e6..31655dd 100644 --- a/schema/sqitch.plan +++ b/schema/sqitch.plan @@ -4,3 +4,4 @@ appschema 2021-03-19T20:12:31Z Naomi Aro # Add schema for all onboarding objects. todos [appschema] 2021-03-23T18:08:10Z Naomi Aro # Creates a table for the todos. +insert_todo [todos appschema] 2021-03-23T20:44:59Z Naomi Aro # Function to insert TODO diff --git a/schema/verify/insert_todo.sql b/schema/verify/insert_todo.sql new file mode 100644 index 0000000..37198a8 --- /dev/null +++ b/schema/verify/insert_todo.sql @@ -0,0 +1,7 @@ +-- Verify onboarding:todo_app.insert_todo on pg + +BEGIN; + +SELECT has_function_privilege('todo_app.insert_todo(text, boolean)', 'execute'); + +ROLLBACK; From 87aaa7652daed96c5ced4b1c1dbcea24c11d7385 Mon Sep 17 00:00:00 2001 From: Naomi Aro Date: Tue, 23 Mar 2021 17:02:27 -0700 Subject: [PATCH 6/7] Add seed data --- schema/deploy/appschema.sql | 2 -- schema/deploy/insert_todo.sql | 2 +- schema/deploy/seed_todo.sql | 14 ++++++++++++++ schema/deploy/todos.sql | 2 +- schema/revert/appschema.sql | 2 -- schema/revert/insert_todo.sql | 2 +- schema/revert/seed_todo.sql | 8 ++++++++ schema/revert/todos.sql | 2 +- schema/sqitch.plan | 1 + schema/verify/appschema.sql | 2 -- schema/verify/insert_todo.sql | 2 +- schema/verify/seed_todo.sql | 13 +++++++++++++ schema/verify/todos.sql | 2 +- 13 files changed, 42 insertions(+), 12 deletions(-) create mode 100644 schema/deploy/seed_todo.sql create mode 100644 schema/revert/seed_todo.sql create mode 100644 schema/verify/seed_todo.sql diff --git a/schema/deploy/appschema.sql b/schema/deploy/appschema.sql index 2369d75..9e3f0ab 100644 --- a/schema/deploy/appschema.sql +++ b/schema/deploy/appschema.sql @@ -2,8 +2,6 @@ BEGIN; --- XXX Add DDLs here. - CREATE SCHEMA todo_app; COMMIT; diff --git a/schema/deploy/insert_todo.sql b/schema/deploy/insert_todo.sql index af0fe9e..375e6ce 100644 --- a/schema/deploy/insert_todo.sql +++ b/schema/deploy/insert_todo.sql @@ -1,4 +1,4 @@ --- Deploy onboarding:todo_app.insert_todo to pg +-- Deploy onboarding:insert_todo to pg -- requires: todos -- requires: appschema diff --git a/schema/deploy/seed_todo.sql b/schema/deploy/seed_todo.sql new file mode 100644 index 0000000..437a430 --- /dev/null +++ b/schema/deploy/seed_todo.sql @@ -0,0 +1,14 @@ +-- Deploy onboarding:seed_todo to pg +-- requires: insert_todo +-- requires: todos +-- requires: appschema + +BEGIN; + +DO $$ +BEGIN + PERFORM todo_app.insert_todo('Unfinished Task', false); + PERFORM todo_app.insert_todo('Finished Task', true); +END$$; + +COMMIT; diff --git a/schema/deploy/todos.sql b/schema/deploy/todos.sql index ea0082f..6ad37f2 100644 --- a/schema/deploy/todos.sql +++ b/schema/deploy/todos.sql @@ -1,4 +1,4 @@ --- Deploy onboarding:todo_app.todos to pg +-- Deploy onboarding:todos to pg -- requires: appschema BEGIN; diff --git a/schema/revert/appschema.sql b/schema/revert/appschema.sql index a2c0307..4b8a0c4 100644 --- a/schema/revert/appschema.sql +++ b/schema/revert/appschema.sql @@ -2,8 +2,6 @@ BEGIN; --- XXX Add DDLs here. - DROP SCHEMA todo_app; COMMIT; diff --git a/schema/revert/insert_todo.sql b/schema/revert/insert_todo.sql index 0b7a992..940a8b1 100644 --- a/schema/revert/insert_todo.sql +++ b/schema/revert/insert_todo.sql @@ -1,4 +1,4 @@ --- Revert onboarding:todo_app.insert_todo from pg +-- Revert onboarding:insert_todo from pg BEGIN; diff --git a/schema/revert/seed_todo.sql b/schema/revert/seed_todo.sql new file mode 100644 index 0000000..eb285e3 --- /dev/null +++ b/schema/revert/seed_todo.sql @@ -0,0 +1,8 @@ +-- Revert onboarding:seed_todo from pg + +BEGIN; + +DELETE FROM todo_app.todos; +ALTER SEQUENCE todo_app.todos_id_seq RESTART; + +COMMIT; diff --git a/schema/revert/todos.sql b/schema/revert/todos.sql index 33cc824..38e5bd4 100644 --- a/schema/revert/todos.sql +++ b/schema/revert/todos.sql @@ -1,4 +1,4 @@ --- Revert onboarding:todo_app.todos from pg +-- Revert onboarding:todos from pg BEGIN; diff --git a/schema/sqitch.plan b/schema/sqitch.plan index 31655dd..8f63a8c 100644 --- a/schema/sqitch.plan +++ b/schema/sqitch.plan @@ -5,3 +5,4 @@ appschema 2021-03-19T20:12:31Z Naomi Aro # Add schema for all onboarding objects. todos [appschema] 2021-03-23T18:08:10Z Naomi Aro # Creates a table for the todos. insert_todo [todos appschema] 2021-03-23T20:44:59Z Naomi Aro # Function to insert TODO +seed_todo [insert_todo todos appschema] 2021-03-23T23:22:49Z Naomi Aro # seed todos table diff --git a/schema/verify/appschema.sql b/schema/verify/appschema.sql index 304b91a..7779b2c 100644 --- a/schema/verify/appschema.sql +++ b/schema/verify/appschema.sql @@ -2,8 +2,6 @@ BEGIN; --- XXX Add verifications here. - SELECT pg_catalog.has_schema_privilege('todo_app', 'usage'); ROLLBACK; diff --git a/schema/verify/insert_todo.sql b/schema/verify/insert_todo.sql index 37198a8..782a6ac 100644 --- a/schema/verify/insert_todo.sql +++ b/schema/verify/insert_todo.sql @@ -1,4 +1,4 @@ --- Verify onboarding:todo_app.insert_todo on pg +-- Verify onboarding:insert_todo on pg BEGIN; diff --git a/schema/verify/seed_todo.sql b/schema/verify/seed_todo.sql new file mode 100644 index 0000000..9f389ad --- /dev/null +++ b/schema/verify/seed_todo.sql @@ -0,0 +1,13 @@ +-- Verify onboarding:seed_todo on pg + +BEGIN; + +DO $$ +DECLARE + count INTEGER; +BEGIN + count := (SELECT last_value FROM todo_app.todos_id_seq); + ASSERT count = 2; +END $$; + +ROLLBACK; diff --git a/schema/verify/todos.sql b/schema/verify/todos.sql index 3f43ced..b383d21 100644 --- a/schema/verify/todos.sql +++ b/schema/verify/todos.sql @@ -1,4 +1,4 @@ --- Verify onboarding:todo_app.todos on pg +-- Verify onboarding:todos on pg BEGIN; From 71d3c5286b7e0459e095d77b41856bd24ecf7f2a Mon Sep 17 00:00:00 2001 From: Naomi Aro Date: Tue, 23 Mar 2021 17:08:12 -0700 Subject: [PATCH 7/7] Add more seeds --- schema/deploy/seed_todo.sql | 3 +++ schema/verify/seed_todo.sql | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/schema/deploy/seed_todo.sql b/schema/deploy/seed_todo.sql index 437a430..1c0a3f3 100644 --- a/schema/deploy/seed_todo.sql +++ b/schema/deploy/seed_todo.sql @@ -7,6 +7,9 @@ BEGIN; DO $$ BEGIN + PERFORM todo_app.insert_todo('Task 1', false); + PERFORM todo_app.insert_todo('Task 2', false); + PERFORM todo_app.insert_todo('Task 3', false); PERFORM todo_app.insert_todo('Unfinished Task', false); PERFORM todo_app.insert_todo('Finished Task', true); END$$; diff --git a/schema/verify/seed_todo.sql b/schema/verify/seed_todo.sql index 9f389ad..eb3e52a 100644 --- a/schema/verify/seed_todo.sql +++ b/schema/verify/seed_todo.sql @@ -4,10 +4,10 @@ BEGIN; DO $$ DECLARE - count INTEGER; + todos_count INTEGER; BEGIN - count := (SELECT last_value FROM todo_app.todos_id_seq); - ASSERT count = 2; + todos_count := (SELECT last_value FROM todo_app.todos_id_seq); + ASSERT todos_count = 5; END $$; ROLLBACK;