diff --git a/docker-compose.yml b/docker-compose.yml index eba518cd..1d9b712e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -70,6 +70,14 @@ services: - POSTGRES_USER=${PG_USER} - POSTGRES_PASSWORD=${PG_PASSWORD} + sqitch: + container_name: sqitch + build: + context: ./sqitch + dockerfile: ./Dockerfile + depends_on: + - db + staging_db: container_name: pg_container_testing image: postgres diff --git a/sqitch/Dockerfile b/sqitch/Dockerfile new file mode 100644 index 00000000..bb2df352 --- /dev/null +++ b/sqitch/Dockerfile @@ -0,0 +1 @@ +FROM sqitch/sqitch:latest \ No newline at end of file diff --git a/sqitch/README.md b/sqitch/README.md new file mode 100644 index 00000000..5d38868f --- /dev/null +++ b/sqitch/README.md @@ -0,0 +1,96 @@ +# Sqitch +Sqitch is an open source database change management tool, basically like git but specifically for databases. + +First, Make sure will ran `make dev-build`, so that the sqitch container is running. +Then cd into the `sqitch` folder. +As a sanity check, type `./sqitch help` into the command line and check that the following pops up: +``` +Usage + sqitch [--etc-path | --help | --man | --version] + sqitch [--chdir ] [--no-pager] [--quiet] [--verbose] + [] [] + +Common Commands + The most commonly used sqitch commands are: + + add Add a new change to the plan + bundle Bundle a Sqitch project for distribution + checkout Revert, checkout another VCS branch, and re-deploy changes + config Get and set local, user, or system options + deploy Deploy changes to a database + engine Manage database engine configuration + help Display help information about Sqitch commands + init Initialize a project + log Show change logs for a database + plan Show the contents of a plan + rebase Revert and redeploy database changes + revert Revert changes from a database + rework Duplicate a change in the plan and revise its scripts + show Show information about changes and tags, or change script contents + status Show the current deployment status of a database + tag Add or list tags in the plan + target Manage target database configuration + upgrade Upgrade the registry to the current version + verify Verify changes to a database + + See "sqitch help " or "sqitch help " to read about a + specific command or concept. See "sqitch help --guide" for a list of + conceptual guides. +``` + +## User config +Much like git, it will be great if we can tell who made a certain change to the database. +To do that, simply run the following commands. +`sqitch config --user user.name ''` +`sqitch config --user user.email ''` + +## Adding a new SQL script to the database +To add a new change to the database (Like a new SQl script, table or function), first run +`./sqitch add appschema -n ""` + +You will see the following changes: +1. New SQL files will be made in the `/deploy`, `/revert` and `/verify` folders. +2. The `sqitch.plan` file will be appended with your new change and message. + +The `/deploy` folder contains all the SQL scripts that will be ran when we deploy the database. +The `/revert` folder contains all the SQL scripts that will be ran when we need to revert the database to some previous state. (Usually just contains a bunch of DROP TABLE expressions) +The `/verify` folder contains all the SQL scripts to verify that a deploy did what it's supposed to. + +## Deploying changes +To deploy changes you made to the database simply type in: +`./sqitch deploy test` + +This will cause sqitch to run all the SQl scripts inside your `/deploy` folder in the order they are created. + +## Revert changes +To revert changes you made to a database, type +`./sqitch revert test --to @HEAD^` + +The `@HEAD` always points to *the last change deployed to the database* +The `^` appended tells Sqitch to select the change prior to the last deployed change. +You can add more `^` to go back further. +You can also use `@ROOT` which refers to the first change deployed to the database. + +## Verify changes +(Use this if you actually fill out the scripts inside of the `/verify` folder) + +Run `./sqitch verify test` to run verification checks. + +## Sqitch.conf +This file contains all the settings that sqitch will follow, you don't need to touch anything here. +The only thing of note is the +``` +[target "test"] + uri = db:pg://postgres:postgres@localhost:5432/test_db +``` + +This tells sqitch that `test` refers to the a specific database uri (Which is the current one we are using) +So you don't have to type the actual uri itself if you want to use sqitch, you just type `test` instead. + +## The .bat and .sh files +Don't remove them or touch them. +The sqitch docker container need them in order for you to interact with sqitch from the command line. + +## References +Refer to the official Sqitch page for more detailed documentation. +https://sqitch.org/ \ No newline at end of file diff --git a/sqitch/deploy/01-create_migration_table.sql b/sqitch/deploy/01-create_migration_table.sql new file mode 100644 index 00000000..29724539 --- /dev/null +++ b/sqitch/deploy/01-create_migration_table.sql @@ -0,0 +1,18 @@ +-- Deploy website:01-create_migration_table to pg + +BEGIN; + +-- XXX Add DDLs here. +CREATE TABLE IF NOT EXISTS migrations ( + MigrationID SERIAL PRIMARY KEY, + VersionID INTEGER default 0 +); + +DO LANGUAGE plpgsql $$ +BEGIN + IF NOT EXISTS (SELECT FROM migrations WHERE MigrationID = 1) THEN + INSERT INTO migrations (MigrationID, VersionID) VALUES (1, 0); + END IF; +END $$; + +COMMIT; diff --git a/sqitch/deploy/02-create_frontend_table.sql b/sqitch/deploy/02-create_frontend_table.sql new file mode 100644 index 00000000..6b01f39a --- /dev/null +++ b/sqitch/deploy/02-create_frontend_table.sql @@ -0,0 +1,12 @@ +-- Deploy website:02-create_frontend_table to pg +-- requires: 01-create_migration_table + +BEGIN; + +CREATE TABLE IF NOT EXISTS frontend ( + FrontendID SERIAL PRIMARY KEY, + FrontendURL VARCHAR(100) +); +-- XXX Add DDLs here. + +COMMIT; diff --git a/sqitch/deploy/03-create_groups_table.sql b/sqitch/deploy/03-create_groups_table.sql new file mode 100644 index 00000000..6c76d943 --- /dev/null +++ b/sqitch/deploy/03-create_groups_table.sql @@ -0,0 +1,19 @@ +-- Deploy website:03-create_groups_table to pg +-- requires: 02-create_frontend_table + +BEGIN; + +-- XXX Add DDLs here. +CREATE EXTENSION IF NOT EXISTS hstore; +SET timezone = 'Australia/Sydney'; + +DROP TYPE IF EXISTS permissions_enum CASCADE; +CREATE TYPE permissions_enum as ENUM ('read', 'write', 'delete'); + +CREATE TABLE IF NOT EXISTS groups ( + UID SERIAL PRIMARY KEY, + Name VARCHAR(50) NOT NULL, + Permission permissions_enum UNIQUE NOT NULL +); + +COMMIT; diff --git a/sqitch/deploy/04-create_person_table.sql b/sqitch/deploy/04-create_person_table.sql new file mode 100644 index 00000000..b553a415 --- /dev/null +++ b/sqitch/deploy/04-create_person_table.sql @@ -0,0 +1,38 @@ +-- Deploy website:04-create_person_table to pg +-- requires: 03-create_groups_table + +BEGIN; + +-- XXX Add DDLs here. +CREATE TABLE IF NOT EXISTS person ( + UID SERIAL PRIMARY KEY, + Email VARCHAR(50) UNIQUE NOT NULL, + First_name VARCHAR(50) NOT NULL, + Password CHAR(64) NOT NULL, + + isOfGroup INT, + frontendid INT, + + CONSTRAINT fk_AccessLevel FOREIGN KEY (isOfGroup) + REFERENCES groups(UID), + + CONSTRAINT fk_AccessFrontend FOREIGN KEY (frontendid) + REFERENCES frontend(FrontendID), + + /* non duplicate email and password constraints */ + CONSTRAINT no_dupes UNIQUE (Email, Password) +); + +/* create user function plpgsql */ +CREATE OR REPLACE FUNCTION create_normal_user (email VARCHAR, name VARCHAR, password VARCHAR, frontendID INT) RETURNS void +LANGUAGE plpgsql +AS $$ +DECLARE +BEGIN + INSERT INTO person (Email, First_name, Password, isOfGroup, frontendID) + VALUES (email, name, encode(sha256(password::BYTEA), 'hex'), 2, 1); +END $$; + + + +COMMIT; diff --git a/sqitch/deploy/05-create_filesystem_table.sql b/sqitch/deploy/05-create_filesystem_table.sql new file mode 100644 index 00000000..65422e01 --- /dev/null +++ b/sqitch/deploy/05-create_filesystem_table.sql @@ -0,0 +1,93 @@ +-- Deploy website:05-create_filesystem_table to pg +-- requires: 04-create_person_table + +BEGIN; + +-- XXX Add DDLs here. +SET timezone = 'Australia/Sydney'; +CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; + +/* MetaData */ +CREATE TABLE IF NOT EXISTS metadata ( + MetadataID uuid PRIMARY KEY DEFAULT uuid_generate_v4(), + CreatedAt TIMESTAMP NOT NULL DEFAULT NOW() +); + +/** + The filesystem table models all file heirachies in our system +**/ +CREATE TABLE IF NOT EXISTS filesystem ( + EntityID uuid PRIMARY KEY DEFAULT uuid_generate_v4(), + LogicalName VARCHAR(50) NOT NULL, + + IsDocument BOOLEAN DEFAULT false, + IsPublished BOOLEAN DEFAULT false, + CreatedAt TIMESTAMP NOT NULL DEFAULT NOW(), + + /* MetaData */ + -- MetadataID uuid NOT NULL, + + OwnedBy INT, + /* Pain */ + Parent uuid REFERENCES filesystem(EntityID) DEFAULT NULL, + + /* FK Constraint */ + CONSTRAINT fk_owner FOREIGN KEY (OwnedBy) + REFERENCES groups(UID), + + -- CONSTRAINT fk_meta FOREIGN KEY (MetadataID) REFERENCES metadata(MetadataID), + + /* Unique name constraint: there should not exist an entity of the same type with the + same parent and logical name. */ + CONSTRAINT unique_name UNIQUE (Parent, LogicalName, IsDocument) +); + +/* Utility procedure :) */ +CREATE OR REPLACE FUNCTION new_entity (parentP uuid, logicalNameP VARCHAR, ownedByP INT, isDocumentP BOOLEAN DEFAULT false) RETURNS uuid +LANGUAGE plpgsql +AS $$ +DECLARE + newEntityID filesystem.EntityID%type; + parentIsDocument BOOLEAN := (SELECT IsDocument FROM filesystem WHERE EntityID = parentP LIMIT 1); +BEGIN + IF parentIsDocument THEN + /* We shouldnt be delcaring that a document is our parent */ + RAISE EXCEPTION SQLSTATE '90001' USING MESSAGE = 'cannot make parent a document'; + END If; + WITH newEntity AS ( + INSERT INTO filesystem (LogicalName, IsDocument, OwnedBy, Parent) + VALUES (logicalNameP, isDocumentP, ownedByP, parentP) + RETURNING EntityID + ) + + SELECT newEntity.EntityID INTO newEntityID FROM newEntity; + RETURN newEntityID; +END $$; + +/* Another utility procedure */ +CREATE OR REPLACE FUNCTION delete_entity (entityIDP uuid) RETURNS void +LANGUAGE plpgsql +AS $$ +DECLARE + numKids INT := (SELECT COUNT(EntityID) FROM filesystem WHERE Parent = entityIDP); + isRoot BOOLEAN := ((SELECT Parent FROM filesystem WHERE EntityID = entityIDP) IS NULL); +BEGIN + /* If this is a directory and has kids raise an error */ + IF numKids > 0 + THEN + /* entity has children (please dont orphan them O_O ) */ + RAISE EXCEPTION SQLSTATE '90001' USING MESSAGE = 'entity has children (please dont orphan them O_O )'; + END IF; + + IF isRoot THEN + /* stop trying to delete root >:( */ + RAISE EXCEPTION SQLSTATE '90001' USING MESSAGE = 'stop trying to delete root >:('; + END IF; + + DELETE FROM filesystem WHERE EntityID = entityIDP; +END $$; + + + + +COMMIT; diff --git a/sqitch/deploy/06-create_dummy_data.sql b/sqitch/deploy/06-create_dummy_data.sql new file mode 100644 index 00000000..0d1fb12d --- /dev/null +++ b/sqitch/deploy/06-create_dummy_data.sql @@ -0,0 +1,68 @@ +-- Deploy website:06-create_dummy_data to pg +-- requires: 05-create_filesystem_table + +BEGIN; + +-- XXX Add DDLs here. +SET timezone = 'Australia/Sydney'; + +/* Create default groups */ +INSERT INTO groups (Name, Permission) VALUES ('admin', 'delete'); +INSERT INTO groups (name, Permission) VALUES ('user', 'write'); + +/* Setup FS table and modify constraints */ +/* Insert root directory and then add our constraints */ +DO $$ +DECLARE + randomGroup groups.UID%type; + rootID filesystem.EntityID%type; +BEGIN + SELECT groups.UID INTO randomGroup FROM groups WHERE Name = 'admin'::VARCHAR; + /* Insert the root directory */ + INSERT INTO filesystem (EntityID, LogicalName, OwnedBy) + VALUES (uuid_nil(), 'root', randomGroup); + SELECT filesystem.EntityID INTO rootID FROM filesystem WHERE LogicalName = 'root'::VARCHAR; + /* Set parent to uuid_nil() because postgres driver has issue supporting NULL values */ + UPDATE filesystem SET Parent = uuid_nil() WHERE EntityID = rootID; + + /* insert "has parent" constraint*/ + EXECUTE 'ALTER TABLE filesystem + ADD CONSTRAINT has_parent CHECK (Parent != NULL)'; +END $$; + + + +/* create a dummy frontend */ +INSERT INTO frontend (FrontendURL) VALUES ('http://localhost:8080'::VARCHAR); + +/* Insert dummy data */ +DO $$ +DECLARE + rootID filesystem.EntityID%type; + newEntity filesystem.EntityID%type; + wasPopping filesystem.EntityID%type; + oldEntity filesystem.EntityID%type; +BEGIN + SELECT filesystem.EntityID INTO rootID FROM filesystem WHERE EntityID = uuid_nil(); + + newEntity := (SELECT new_entity(rootID, 'downloads'::VARCHAR, 1, false)); + oldEntity := (SELECT new_entity(rootID, 'documents'::VARCHAR, 1, false)); + + wasPopping := (SELECT new_entity(oldEntity, 'cool_document'::VARCHAR, 1, true)); + wasPopping := (SELECT new_entity(oldEntity, 'cool_document_round_2'::VARCHAR, 1, true)); + PERFORM delete_entity(wasPopping); + wasPopping := (SELECT new_entity(oldEntity, 'cool_document_round_2'::VARCHAR, 1, true)); +END $$; + + +/* inserting two accounts into db */ +DO LANGUAGE plpgsql $$ +BEGIN + EXECUTE create_normal_user('z0000000@ad.unsw.edu.au', 'adam', 'password', 1); + EXECUTE create_normal_user('john.smith@gmail.com', 'john', 'password', 1); + EXECUTE create_normal_user('jane.doe@gmail.com', 'jane', 'password', 1); +END $$; + + + +COMMIT; diff --git a/sqitch/revert/01-create_migration_table.sql b/sqitch/revert/01-create_migration_table.sql new file mode 100644 index 00000000..edad4975 --- /dev/null +++ b/sqitch/revert/01-create_migration_table.sql @@ -0,0 +1,8 @@ +-- Revert website:01-create_migration_table from pg + +BEGIN; + +-- XXX Add DDLs here. +DROP TABLE IF EXISTS migrations CASCADE; + +COMMIT; diff --git a/sqitch/revert/02-create_frontend_table.sql b/sqitch/revert/02-create_frontend_table.sql new file mode 100644 index 00000000..b358e341 --- /dev/null +++ b/sqitch/revert/02-create_frontend_table.sql @@ -0,0 +1,8 @@ +-- Revert website:02-create_frontend_table from pg + +BEGIN; + +-- XXX Add DDLs here. +DROP TABLE IF EXISTS frontend; + +COMMIT; diff --git a/sqitch/revert/03-create_groups_table.sql b/sqitch/revert/03-create_groups_table.sql new file mode 100644 index 00000000..cc3857be --- /dev/null +++ b/sqitch/revert/03-create_groups_table.sql @@ -0,0 +1,9 @@ +-- Revert website:03-create_groups_table from pg + +BEGIN; + +-- XXX Add DDLs here. +DROP TYPE IF EXISTS permissions_enum CASCADE; + +DROP TABLE IF EXISTS groups CASCADE; +COMMIT; diff --git a/sqitch/revert/04-create_person_table.sql b/sqitch/revert/04-create_person_table.sql new file mode 100644 index 00000000..76a9c943 --- /dev/null +++ b/sqitch/revert/04-create_person_table.sql @@ -0,0 +1,11 @@ +-- Revert website:04-create_person_table from pg + +BEGIN; + +-- XXX Add DDLs here. +DROP TABLE IF EXISTS person; + +DROP FUNCTION IF EXISTS create_normal_user; + + +COMMIT; diff --git a/sqitch/revert/05-create_filesystem_table.sql b/sqitch/revert/05-create_filesystem_table.sql new file mode 100644 index 00000000..c9e29b8f --- /dev/null +++ b/sqitch/revert/05-create_filesystem_table.sql @@ -0,0 +1,11 @@ +-- Revert website:05-create_filesystem_table from pg + +BEGIN; + +-- XXX Add DDLs here. +DROP TABLE IF EXISTS metadata; +DROP TABLE IF EXISTS filesystem; +DROP FUNCTION IF EXISTS new_entity; +DROP FUNCTION IF EXISTS delete_entity; + +COMMIT; diff --git a/sqitch/revert/06-create_dummy_data.sql b/sqitch/revert/06-create_dummy_data.sql new file mode 100644 index 00000000..1c6baab4 --- /dev/null +++ b/sqitch/revert/06-create_dummy_data.sql @@ -0,0 +1,7 @@ +-- Revert website:06-create_dummy_data from pg + +BEGIN; + +-- XXX Add DDLs here. + +COMMIT; diff --git a/sqitch/sqitch.bat b/sqitch/sqitch.bat new file mode 100644 index 00000000..86fb0fde --- /dev/null +++ b/sqitch/sqitch.bat @@ -0,0 +1,51 @@ +@echo off & setlocal enableextensions enabledelayedexpansion +REM # Determine which Docker image to run. +IF NOT DEFINED SQITCH_IMAGE ( + set SQITCH_IMAGE=website-sqitch:latest +) +REM set SQITCH_IMAGE=website-sqitch:latest + +REM # Set up required pass-through variables. +FOR /F "tokens=*" %%g IN ('whoami') do (SET user=%%g) +set passopt= -e SQITCH_ORIG_SYSUSER="%username%" +FOR /F "tokens=*" %%g IN ('hostname') do (SET machinehostname=%%g) +set passopt=%passopt% -e SQITCH_ORIG_EMAIL="%username%@%machinehostname%" +FOR /F "tokens=*" %%g IN ('tzutil /g') do (SET TZ=%%g) +set passopt=%passopt% -e TZ="%TZ%" +if NOT DEFINED LESS ( + set LESS=-R +) +set passopt=%passopt% -e LESS=%LESS% + +for %%i in ( + SQITCH_CONFIG SQITCH_USERNAME SQITCH_PASSWORD SQITCH_FULLNAME SQITCH_EMAIL SQITCH_TARGET + DBI_TRACE + PGUSER PGPASSWORD PGHOST PGHOSTADDR PGPORT PGDATABASE PGSERVICE PGOPTIONS PGSSLMODE PGREQUIRESSL PGSSLCOMPRESSION PGREQUIREPEER PGKRBSRVNAME PGKRBSRVNAME PGGSSLIB PGCONNECT_TIMEOUT PGCLIENTENCODING PGTARGETSESSIONATTRS + MYSQL_PWD MYSQL_HOST MYSQL_TCP_PORT + TNS_ADMIN TWO_TASK ORACLE_SID + ISC_USER ISC_PASSWORD + VSQL_HOST VSQL_PORT VSQL_USER VSQL_PASSWORD VSQL_SSLMODE + SNOWSQL_ACCOUNT SNOWSQL_USER SNOWSQL_PWD SNOWSQL_HOST SNOWSQL_PORT SNOWSQL_DATABASE SNOWSQL_REGION SNOWSQL_WAREHOUSE SNOWSQL_PRIVATE_KEY_PASSPHRASE +) do if defined %%i ( + echo %%i is defined as !%%i! + SET passopt=!passopt! -e !%%i! +) + +REM # Determine the name of the container home directory. +set homedst=/home +REM if [ $(id -u ${user}) -eq 0 ]; then +REM homedst=/root +REM fi +REM # Set HOME, since the user ID likely won't be the same as for the sqitch user. +set passopt=%passopt% -e HOME="%homedst%" + +echo %passopt% + +REM # Run the container with the current and home directories mounted. +@echo on +docker run -it --rm --network host ^ + --mount "type=bind,src=%cd%,dst=/repo" ^ + --mount "type=bind,src=%UserProfile%,dst=%homedst%" ^ + %passopt% %SQITCH_IMAGE% %* + +@endlocal diff --git a/sqitch/sqitch.conf b/sqitch/sqitch.conf new file mode 100644 index 00000000..4d121dd9 --- /dev/null +++ b/sqitch/sqitch.conf @@ -0,0 +1,10 @@ +[core] + engine = pg + # plan_file = sqitch.plan + # top_dir = . +# [engine "pg"] + # target = db:pg: + # registry = sqitch + # client = psql +[target "test"] + uri = db:pg://postgres:postgres@localhost:5432/test_db diff --git a/sqitch/sqitch.plan b/sqitch/sqitch.plan new file mode 100644 index 00000000..e233ce8e --- /dev/null +++ b/sqitch/sqitch.plan @@ -0,0 +1,9 @@ +%syntax-version=1.0.0 +%project=website + +01-create_migration_table 2023-09-14T13:46:21Z John Doe # Add migration table +02-create_frontend_table [01-create_migration_table] 2023-09-14T13:47:39Z John Doe # Add frontend table +03-create_groups_table [02-create_frontend_table] 2023-09-14T13:50:37Z John Doe # Groups table +04-create_person_table [03-create_groups_table] 2023-09-14T13:52:42Z John Doe # person table +05-create_filesystem_table [04-create_person_table] 2023-09-14T13:54:21Z John Doe # filesystem +06-create_dummy_data [05-create_filesystem_table] 2023-09-14T13:56:23Z John Doe # dummy data diff --git a/sqitch/sqitch.sh b/sqitch/sqitch.sh new file mode 100644 index 00000000..5ab68913 --- /dev/null +++ b/sqitch/sqitch.sh @@ -0,0 +1,68 @@ +#!/usr/bin/env bash + +# Determine which Docker image to run. +SQITCH_IMAGE=${SQITCH_IMAGE:=website-sqitch:latest} + +# Set up required pass-through variables. +user=${USER-$(whoami)} +passopt=( + -e "SQITCH_ORIG_SYSUSER=$user" + -e "SQITCH_ORIG_EMAIL=$user@$(hostname)" + -e "TZ=$(date +%Z)" \ + -e "LESS=${LESS:--R}" \ +) + +# Handle OS-specific options. +case "$(uname -s)" in + Linux*) + passopt+=(-e "SQITCH_ORIG_FULLNAME=$(getent passwd $user | cut -d: -f5 | cut -d, -f1)") + passopt+=(-u $(id -u ${user}):$(id -g ${user})) + ;; + Darwin*) + passopt+=(-e "SQITCH_ORIG_FULLNAME=$(/usr/bin/id -P $user | awk -F '[:]' '{print $8}')") + ;; + MINGW*|CYGWIN*) + passopt+=(-e "SQITCH_ORIG_FULLNAME=$(net user $user)") + ;; + *) + echo "Unknown OS: $(uname -s)" + exit 2 + ;; +esac + +# Iterate over optional Sqitch and engine variables. +for var in \ + SQITCH_CONFIG SQITCH_USERNAME SQITCH_PASSWORD SQITCH_FULLNAME SQITCH_EMAIL SQITCH_TARGET \ + DBI_TRACE \ + PGUSER PGPASSWORD PGHOST PGHOSTADDR PGPORT PGDATABASE PGSERVICE PGOPTIONS PGSSLMODE PGREQUIRESSL PGSSLCOMPRESSION PGREQUIREPEER PGKRBSRVNAME PGKRBSRVNAME PGGSSLIB PGCONNECT_TIMEOUT PGCLIENTENCODING PGTARGETSESSIONATTRS \ + MYSQL_PWD MYSQL_HOST MYSQL_TCP_PORT \ + TNS_ADMIN TWO_TASK ORACLE_SID \ + ISC_USER ISC_PASSWORD \ + VSQL_HOST VSQL_PORT VSQL_USER VSQL_PASSWORD VSQL_SSLMODE \ + SNOWSQL_ACCOUNT SNOWSQL_USER SNOWSQL_PWD SNOWSQL_HOST SNOWSQL_PORT SNOWSQL_DATABASE SNOWSQL_REGION SNOWSQL_WAREHOUSE SNOWSQL_PRIVATE_KEY_PASSPHRASE SNOWSQL_ROLE +do + if [ -n "${!var}" ]; then + passopt+=(-e $var) + fi +done + +# Determine the name of the container home directory. +homedst=/home +if [ $(id -u ${user}) -eq 0 ]; then + homedst=/root +fi +# Set HOME, since the user ID likely won't be the same as for the sqitch user. +passopt+=(-e "HOME=${homedst}") + +# Determine necessary flags when stdin and/or stdout are opened on a TTY. +if [ -t 0 ] && [ -t 1 ]; then + passopt+=(--interactive --tty) +elif [ ! -t 0 ]; then + passopt+=(--interactive) +fi + +# Run the container with the current and home directories mounted. +docker run --rm --network host \ + --mount "type=bind,src=$(pwd),dst=/repo" \ + --mount "type=bind,src=$HOME,dst=$homedst" \ + "${passopt[@]}" "$SQITCH_IMAGE" "$@" \ No newline at end of file diff --git a/sqitch/verify/01-create_migration_table.sql b/sqitch/verify/01-create_migration_table.sql new file mode 100644 index 00000000..9d94d7bb --- /dev/null +++ b/sqitch/verify/01-create_migration_table.sql @@ -0,0 +1,7 @@ +-- Verify website:01-create_migration_table on pg + +BEGIN; + +-- XXX Add verifications here. + +ROLLBACK; diff --git a/sqitch/verify/02-create_frontend_table.sql b/sqitch/verify/02-create_frontend_table.sql new file mode 100644 index 00000000..71177e06 --- /dev/null +++ b/sqitch/verify/02-create_frontend_table.sql @@ -0,0 +1,7 @@ +-- Verify website:02-create_frontend_table on pg + +BEGIN; + +-- XXX Add verifications here. + +ROLLBACK; diff --git a/sqitch/verify/03-create_groups_table.sql b/sqitch/verify/03-create_groups_table.sql new file mode 100644 index 00000000..e2a6d2fb --- /dev/null +++ b/sqitch/verify/03-create_groups_table.sql @@ -0,0 +1,7 @@ +-- Verify website:03-create_groups_table on pg + +BEGIN; + +-- XXX Add verifications here. + +ROLLBACK; diff --git a/sqitch/verify/04-create_person_table.sql b/sqitch/verify/04-create_person_table.sql new file mode 100644 index 00000000..5533ed62 --- /dev/null +++ b/sqitch/verify/04-create_person_table.sql @@ -0,0 +1,7 @@ +-- Verify website:04-create_person_table on pg + +BEGIN; + +-- XXX Add verifications here. + +ROLLBACK; diff --git a/sqitch/verify/05-create_filesystem_table.sql b/sqitch/verify/05-create_filesystem_table.sql new file mode 100644 index 00000000..ab063671 --- /dev/null +++ b/sqitch/verify/05-create_filesystem_table.sql @@ -0,0 +1,7 @@ +-- Verify website:05-create_filesystem_table on pg + +BEGIN; + +-- XXX Add verifications here. + +ROLLBACK; diff --git a/sqitch/verify/06-create_dummy_data.sql b/sqitch/verify/06-create_dummy_data.sql new file mode 100644 index 00000000..cad81be1 --- /dev/null +++ b/sqitch/verify/06-create_dummy_data.sql @@ -0,0 +1,7 @@ +-- Verify website:06-create_dummy_data on pg + +BEGIN; + +-- XXX Add verifications here. + +ROLLBACK;