Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Naomi/step-1 #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
schema/sqitch.plan merge=union
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
7 changes: 7 additions & 0 deletions schema/deploy/appschema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- Deploy onboarding:appschema to pg

BEGIN;

CREATE SCHEMA todo_app;

COMMIT;
14 changes: 14 additions & 0 deletions schema/deploy/insert_todo.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-- Deploy onboarding: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;
17 changes: 17 additions & 0 deletions schema/deploy/seed_todo.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-- Deploy onboarding:seed_todo to pg
-- requires: insert_todo
-- requires: todos
-- requires: appschema

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$$;

COMMIT;
16 changes: 16 additions & 0 deletions schema/deploy/todos.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- Deploy onboarding: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;
7 changes: 7 additions & 0 deletions schema/revert/appschema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- Revert onboarding:appschema from pg

BEGIN;

DROP SCHEMA todo_app;

COMMIT;
7 changes: 7 additions & 0 deletions schema/revert/insert_todo.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- Revert onboarding:insert_todo from pg

BEGIN;

DROP FUNCTION todo_app.insert_todo(TEXT, BOOLEAN);

COMMIT;
8 changes: 8 additions & 0 deletions schema/revert/seed_todo.sql
Original file line number Diff line number Diff line change
@@ -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;
7 changes: 7 additions & 0 deletions schema/revert/todos.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- Revert onboarding:todos from pg

BEGIN;

DROP TABLE todo_app.todos;

COMMIT;
10 changes: 10 additions & 0 deletions schema/sqitch.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[core]
engine = pg
[deploy]
verify = true
[rebase]
verify = true
[target "todo_app"]
uri = db:pg:todo_app
[engine "pg"]
target = todo_app
8 changes: 8 additions & 0 deletions schema/sqitch.plan
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
%syntax-version=1.0.0
%project=onboarding
%uri=https://github.com/naomiaro/button-onboarding

appschema 2021-03-19T20:12:31Z Naomi Aro <naomi.aro@gov.bc.ca> # Add schema for all onboarding objects.
todos [appschema] 2021-03-23T18:08:10Z Naomi Aro <naomi.aro@gov.bc.ca> # Creates a table for the todos.
insert_todo [todos appschema] 2021-03-23T20:44:59Z Naomi Aro <naomi.aro@gov.bc.ca> # Function to insert TODO
seed_todo [insert_todo todos appschema] 2021-03-23T23:22:49Z Naomi Aro <naomi.aro@gov.bc.ca> # seed todos table
7 changes: 7 additions & 0 deletions schema/verify/appschema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- Verify onboarding:appschema on pg

BEGIN;

SELECT pg_catalog.has_schema_privilege('todo_app', 'usage');

ROLLBACK;
7 changes: 7 additions & 0 deletions schema/verify/insert_todo.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- Verify onboarding:insert_todo on pg

BEGIN;

SELECT has_function_privilege('todo_app.insert_todo(text, boolean)', 'execute');

ROLLBACK;
13 changes: 13 additions & 0 deletions schema/verify/seed_todo.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-- Verify onboarding:seed_todo on pg

BEGIN;

DO $$
DECLARE
todos_count INTEGER;
BEGIN
todos_count := (SELECT last_value FROM todo_app.todos_id_seq);
ASSERT todos_count = 5;
END $$;

ROLLBACK;
9 changes: 9 additions & 0 deletions schema/verify/todos.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- Verify onboarding:todos on pg

BEGIN;

SELECT id, task, completed, date_created, date_updated
FROM todo_app.todos
WHERE FALSE;

ROLLBACK;