diff --git a/schema/deploy/insert_seed_data.sql b/schema/deploy/insert_seed_data.sql new file mode 100644 index 0000000..1e3a439 --- /dev/null +++ b/schema/deploy/insert_seed_data.sql @@ -0,0 +1,19 @@ +-- Deploy schema:insert_seed_data to pg +-- requires: todo_appschema +-- requires: tasks + +BEGIN; + +-- XXX Add DDLs here. +INSERT INTO + todo_app.tasks (id, task, completed) + VALUES + (1, 'Make bed', false), + (2, 'Shower', false), + (3, 'Write todo list', true), + (4, 'Learn to hack', false), + (5, 'Lunch with Julia', false), + (6, 'Buy groceries', false), + (7, 'Feed dog', true); + +COMMIT; diff --git a/schema/deploy/tasks.sql b/schema/deploy/tasks.sql new file mode 100644 index 0000000..b8e37e3 --- /dev/null +++ b/schema/deploy/tasks.sql @@ -0,0 +1,16 @@ +-- Deploy schema:tasks to pg +-- requires: todo_appschema + +BEGIN; + +SET client_min_messages = 'warning'; + +CREATE TABLE todo_app.tasks ( + id INTEGER 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/deploy/todo_appschema.sql b/schema/deploy/todo_appschema.sql new file mode 100644 index 0000000..c8e9ec0 --- /dev/null +++ b/schema/deploy/todo_appschema.sql @@ -0,0 +1,8 @@ +-- Deploy schema:todo_appschema to pg + +BEGIN; + +-- XXX Add DDLs here. +CREATE SCHEMA todo_app; + +COMMIT; diff --git a/schema/revert/insert_seed_data.sql b/schema/revert/insert_seed_data.sql new file mode 100644 index 0000000..7bd8f21 --- /dev/null +++ b/schema/revert/insert_seed_data.sql @@ -0,0 +1,8 @@ +-- Revert schema:insert_seed_data from pg + +BEGIN; + +-- XXX Add DDLs here. +TRUNCATE TABLE todo_app.tasks; + +COMMIT; diff --git a/schema/revert/tasks.sql b/schema/revert/tasks.sql new file mode 100644 index 0000000..d8e855c --- /dev/null +++ b/schema/revert/tasks.sql @@ -0,0 +1,8 @@ +-- Revert schema:todo from pg + +BEGIN; + +-- XXX Add DDLs here. +DROP TABLE todo_app.tasks; + +COMMIT; diff --git a/schema/revert/todo_appschema.sql b/schema/revert/todo_appschema.sql new file mode 100644 index 0000000..b2c001b --- /dev/null +++ b/schema/revert/todo_appschema.sql @@ -0,0 +1,8 @@ +-- Revert schema:todo_appschema from pg + +BEGIN; + +-- XXX Add DDLs here. +DROP SCHEMA todo_app; + +COMMIT; diff --git a/schema/sqitch.conf b/schema/sqitch.conf new file mode 100644 index 0000000..61e3aff --- /dev/null +++ b/schema/sqitch.conf @@ -0,0 +1,16 @@ +[core] + engine = pg + # plan_file = sqitch.plan + # top_dir = . +# [engine "pg"] + # target = db:pg: + # registry = sqitch + # client = psql +[target "todo_app_db"] +    uri = db:pg:todo_app_db +[engine "pg"] +    target = todo_app_db +[deploy] + verify = true +[rebase] + verify = true diff --git a/schema/sqitch.plan b/schema/sqitch.plan new file mode 100644 index 0000000..644d698 --- /dev/null +++ b/schema/sqitch.plan @@ -0,0 +1,7 @@ +%syntax-version=1.0.0 +%project=schema +%uri=https://github.com/JoshLarouche/cas-onboarding/ + +todo_appschema 2023-03-23T16:20:40Z JoshLarouche # Add schema for all todo objects. +tasks [todo_appschema] 2023-03-24T15:21:51Z JoshLarouche # Creates table to track our tasks. +insert_seed_data [todo_appschema] 2023-03-24T15:53:29Z JoshLarouche # Inserts seed data into tasks table. diff --git a/schema/verify/insert_seed_data.sql b/schema/verify/insert_seed_data.sql new file mode 100644 index 0000000..9282601 --- /dev/null +++ b/schema/verify/insert_seed_data.sql @@ -0,0 +1,9 @@ +-- Verify schema:insert_seed_data on pg + +BEGIN; + +-- XXX Add verifications here. +SELECT id, task, completed, date_created, date_updated + FROM todo_app.tasks; + +ROLLBACK; diff --git a/schema/verify/tasks.sql b/schema/verify/tasks.sql new file mode 100644 index 0000000..dec50bc --- /dev/null +++ b/schema/verify/tasks.sql @@ -0,0 +1,10 @@ +-- Verify schema:todo on pg + +BEGIN; + +-- XXX Add verifications here. +SELECT id, task, completed, date_created, date_updated + FROM todo_app.tasks + WHERE FALSE; + +ROLLBACK; diff --git a/schema/verify/todo_appschema.sql b/schema/verify/todo_appschema.sql new file mode 100644 index 0000000..be68c24 --- /dev/null +++ b/schema/verify/todo_appschema.sql @@ -0,0 +1,15 @@ +-- Verify schema:todo_appschema on pg + +BEGIN; + +-- XXX Add verifications here. +SELECT pg_catalog.has_schema_privilege('todo_app', 'usage'); + +SELECT 1/COUNT(*) FROM information_schema.schemata WHERE schema_name = 'todo_app'; + +DO $$ +BEGIN + ASSERT (SELECT has_schema_privilege('todo_app', 'usage')); +END $$; + +ROLLBACK;