From 55f2a1c0e9319e9e4809e855824790a0d01fab59 Mon Sep 17 00:00:00 2001 From: Sepehr Sobhani Date: Wed, 6 Apr 2022 14:06:36 -0700 Subject: [PATCH 1/6] Create .gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b164a65 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.xml +*.idea +*.iml From 7b239ff2bb641847ec4efbfd31c418c9ad408fb3 Mon Sep 17 00:00:00 2001 From: Sepehr Sobhani Date: Wed, 6 Apr 2022 14:08:21 -0700 Subject: [PATCH 2/6] Initialize sqitch configuration --- schema/sqitch.conf | 8 ++++++++ schema/sqitch.plan | 4 ++++ 2 files changed, 12 insertions(+) create mode 100644 schema/sqitch.conf create mode 100644 schema/sqitch.plan 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..e8a34fd --- /dev/null +++ b/schema/sqitch.plan @@ -0,0 +1,4 @@ +%syntax-version=1.0.0 +%project=todo_app +%uri=https://github.com/Sepehr-Sobhani/button-onboarding + From c6fc4c16fa9f5b8534c65f6d128ec82a6f4bb087 Mon Sep 17 00:00:00 2001 From: Sepehr Sobhani Date: Wed, 6 Apr 2022 15:46:22 -0700 Subject: [PATCH 3/6] Add sqitch migration for creating the todo_app schema --- schema/deploy/todo_appschema.sql | 7 +++++++ schema/revert/todo_appschema.sql | 7 +++++++ schema/sqitch.plan | 1 + schema/verify/todo_appschema.sql | 11 +++++++++++ 4 files changed, 26 insertions(+) create mode 100644 schema/deploy/todo_appschema.sql create mode 100644 schema/revert/todo_appschema.sql create mode 100644 schema/verify/todo_appschema.sql diff --git a/schema/deploy/todo_appschema.sql b/schema/deploy/todo_appschema.sql new file mode 100644 index 0000000..916a76d --- /dev/null +++ b/schema/deploy/todo_appschema.sql @@ -0,0 +1,7 @@ +-- Deploy todo_app:todo_appschema to pg + +BEGIN; + +CREATE SCHEMA todo_app; + +COMMIT; diff --git a/schema/revert/todo_appschema.sql b/schema/revert/todo_appschema.sql new file mode 100644 index 0000000..bbfa1b0 --- /dev/null +++ b/schema/revert/todo_appschema.sql @@ -0,0 +1,7 @@ +-- Revert todo_app:todo_appschema from pg + +BEGIN; + +DROP SCHEMA todo_app; + +COMMIT; diff --git a/schema/sqitch.plan b/schema/sqitch.plan index e8a34fd..1b7af9a 100644 --- a/schema/sqitch.plan +++ b/schema/sqitch.plan @@ -2,3 +2,4 @@ %project=todo_app %uri=https://github.com/Sepehr-Sobhani/button-onboarding +todo_appschema 2022-04-06T21:11:50Z Sepehr Sobhani # Add Schema for all todo app objects. diff --git a/schema/verify/todo_appschema.sql b/schema/verify/todo_appschema.sql new file mode 100644 index 0000000..d5cb97d --- /dev/null +++ b/schema/verify/todo_appschema.sql @@ -0,0 +1,11 @@ +-- Verify todo_app:todo_appschema on pg + +BEGIN; + +DO $$ +BEGIN + ASSERT(SELECT pg_catalog.has_schema_privilege('todo_app', 'usage')); +END $$; + + +ROLLBACK; From f458541581d25c21db204ec54fb6b597f8ebb772 Mon Sep 17 00:00:00 2001 From: Sepehr Sobhani Date: Wed, 6 Apr 2022 16:33:38 -0700 Subject: [PATCH 4/6] Set default deployment target and always verify --- schema/sqitch.conf | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/schema/sqitch.conf b/schema/sqitch.conf index 3447459..c3e82af 100644 --- a/schema/sqitch.conf +++ b/schema/sqitch.conf @@ -6,3 +6,11 @@ # target = db:pg: # registry = sqitch # client = psql +[target "todo_app"] + uri = db:pg:todo_app +[engine "pg"] + target = todo_app +[deploy] + verify = true +[rebase] + verify = true From ef4d70f1c210e2f528aa003ce209476be1027210 Mon Sep 17 00:00:00 2001 From: Sepehr Sobhani Date: Thu, 7 Apr 2022 12:25:52 -0700 Subject: [PATCH 5/6] Add tasks table --- schema/deploy/tasks.sql | 14 ++++++++++++++ schema/revert/tasks.sql | 7 +++++++ schema/sqitch.plan | 1 + schema/verify/tasks.sql | 7 +++++++ 4 files changed, 29 insertions(+) create mode 100644 schema/deploy/tasks.sql create mode 100644 schema/revert/tasks.sql create mode 100644 schema/verify/tasks.sql diff --git a/schema/deploy/tasks.sql b/schema/deploy/tasks.sql new file mode 100644 index 0000000..54362c7 --- /dev/null +++ b/schema/deploy/tasks.sql @@ -0,0 +1,14 @@ +-- Deploy todo_app:tasks to pg +-- requires: todo_appschema + +BEGIN; + +CREATE TABLE todo_app.tasks ( + id SERIAL PRIMARY KEY, + task TEXT NOT NULL, + completed BOOLEAN NOT NULL DEFAULT FALSE, + date_created TIMESTAMP NOT NULL DEFAULT NOW(), + date_updated TIMESTAMP NOT NULL DEFAULT NOW() +); + +COMMIT; diff --git a/schema/revert/tasks.sql b/schema/revert/tasks.sql new file mode 100644 index 0000000..7666b8e --- /dev/null +++ b/schema/revert/tasks.sql @@ -0,0 +1,7 @@ +-- Revert todo_app:tasks from pg + +BEGIN; + +DROP TABLE IF EXISTS todo_app.tasks; + +COMMIT; diff --git a/schema/sqitch.plan b/schema/sqitch.plan index 1b7af9a..919f550 100644 --- a/schema/sqitch.plan +++ b/schema/sqitch.plan @@ -3,3 +3,4 @@ %uri=https://github.com/Sepehr-Sobhani/button-onboarding todo_appschema 2022-04-06T21:11:50Z Sepehr Sobhani # Add Schema for all todo app objects. +tasks [todo_appschema] 2022-04-07T18:34:52Z Sepehr Sobhani # Creates table to track tasks. diff --git a/schema/verify/tasks.sql b/schema/verify/tasks.sql new file mode 100644 index 0000000..6b60e6d --- /dev/null +++ b/schema/verify/tasks.sql @@ -0,0 +1,7 @@ +-- Verify todo_app:tasks on pg + +BEGIN; + +SELECT id, task, completed, date_created, date_updated FROM todo_app.tasks WHERE FALSE; + +ROLLBACK; From e995007ba1e2eea25407bde418e0b679f8606f61 Mon Sep 17 00:00:00 2001 From: Sepehr Sobhani Date: Thu, 7 Apr 2022 14:12:11 -0700 Subject: [PATCH 6/6] Add task seed data --- schema/deploy/insert_seed_task.sql | 17 +++++++++++++++++ schema/revert/insert_seed_task.sql | 7 +++++++ schema/sqitch.plan | 1 + schema/verify/insert_seed_task.sql | 7 +++++++ 4 files changed, 32 insertions(+) create mode 100644 schema/deploy/insert_seed_task.sql create mode 100644 schema/revert/insert_seed_task.sql create mode 100644 schema/verify/insert_seed_task.sql diff --git a/schema/deploy/insert_seed_task.sql b/schema/deploy/insert_seed_task.sql new file mode 100644 index 0000000..6691933 --- /dev/null +++ b/schema/deploy/insert_seed_task.sql @@ -0,0 +1,17 @@ +-- Deploy todo_app:insert_seed_task to pg +-- requires: tasks +-- requires: todo_appschema + +BEGIN; + +INSERT INTO + todo_app.tasks (task, completed) +VALUES + ('Buy milk', false), + ('Buy eggs', false), + ('Buy bread', true), + ('Buy coffee', false), + ('Buy tea', true), + ('Buy chocolate', false); + +COMMIT; diff --git a/schema/revert/insert_seed_task.sql b/schema/revert/insert_seed_task.sql new file mode 100644 index 0000000..3efbf32 --- /dev/null +++ b/schema/revert/insert_seed_task.sql @@ -0,0 +1,7 @@ +-- Revert todo_app:insert_seed_task from pg + +BEGIN; + +TRUNCATE TABLE todo_app.tasks ; + +COMMIT; diff --git a/schema/sqitch.plan b/schema/sqitch.plan index 919f550..f0bdf5a 100644 --- a/schema/sqitch.plan +++ b/schema/sqitch.plan @@ -4,3 +4,4 @@ todo_appschema 2022-04-06T21:11:50Z Sepehr Sobhani # Add Schema for all todo app objects. tasks [todo_appschema] 2022-04-07T18:34:52Z Sepehr Sobhani # Creates table to track tasks. +insert_seed_task [tasks todo_appschema] 2022-04-07T20:37:04Z Sepehr Sobhani # Create seed data for tasks table diff --git a/schema/verify/insert_seed_task.sql b/schema/verify/insert_seed_task.sql new file mode 100644 index 0000000..e223dc0 --- /dev/null +++ b/schema/verify/insert_seed_task.sql @@ -0,0 +1,7 @@ +-- Verify todo_app:insert_seed_task on pg + +BEGIN; + +SELECT id, task, completed, date_created, date_updated FROM todo_app.tasks; + +ROLLBACK;