From c9995b30f8f28e2d7fdc4d2087936cc9a78beb8c Mon Sep 17 00:00:00 2001 From: Orion Kindel Date: Thu, 8 Jun 2023 15:44:06 -0500 Subject: [PATCH] init --- .env.local | 6 ++++++ .gitignore | 1 + docker-compose.yml | 22 ++++++++++++++++++++++ migrations/000_thread_kind.sql | 5 +++++ migrations/010_thread.sql | 5 +++++ reference/Dockerfile | 1 + scripts/build-reference.sh | 21 +++++++++++++++++++++ 7 files changed, 61 insertions(+) create mode 100644 .env.local create mode 100644 .gitignore create mode 100644 docker-compose.yml create mode 100644 migrations/000_thread_kind.sql create mode 100644 migrations/010_thread.sql create mode 100644 reference/Dockerfile create mode 100755 scripts/build-reference.sh diff --git a/.env.local b/.env.local new file mode 100644 index 0000000..de42e97 --- /dev/null +++ b/.env.local @@ -0,0 +1,6 @@ +FLYWAY_URL=jdbc:postgresql://db:5432/dnim +FLYWAY_USER=postgres +FLYWAY_PASSWORD=password +POSTGRES_USER=postgres +POSTGRES_PASSWORD=password +POSTGRES_DB=dnim diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4c49bd7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.env diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..578b231 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,22 @@ +version: "3" +name: "dnim_db" +services: + base: + container_name: "base" + image: "postgres:15.3-bullseye" + ports: + - "5433:5432" + volumes: + - "./data/base:/var/lib/postgres/data" + env_file: + - "./.env" + head: + container_name: "head" + image: "postgres:15.3-bullseye" + restart: "always" + ports: + - "5432:5432" + volumes: + - "./data/head:/var/lib/postgres/data" + env_file: + - "./.env" diff --git a/migrations/000_thread_kind.sql b/migrations/000_thread_kind.sql new file mode 100644 index 0000000..32a3b15 --- /dev/null +++ b/migrations/000_thread_kind.sql @@ -0,0 +1,5 @@ +create type public.thread_kind as enum + ( 'post' + , 'short' + , 'message' + ); diff --git a/migrations/010_thread.sql b/migrations/010_thread.sql new file mode 100644 index 0000000..bc20ab2 --- /dev/null +++ b/migrations/010_thread.sql @@ -0,0 +1,5 @@ +create table public.thread + ( id int not null generated always as identity + , uid uuid not null default gen_random_uuid() + , kind thread_kind not null + ); diff --git a/reference/Dockerfile b/reference/Dockerfile new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/reference/Dockerfile @@ -0,0 +1 @@ + diff --git a/scripts/build-reference.sh b/scripts/build-reference.sh new file mode 100755 index 0000000..23e697e --- /dev/null +++ b/scripts/build-reference.sh @@ -0,0 +1,21 @@ +#! /usr/bin/bash + +$rev=${1:-HEAD} + +if [ "$rev" = "HEAD" ]; then + $port = 5432 +else + $port = 5433 +fi + +while read line; do export $line; done < ./.env + +psql \ + --echo-all \ + postgres://$POSTGRES_USER:$POSTGRES_PASSWORD@localhost:$port/$POSTGRES_DB \ + --command="drop schema public cascade; create schema public;" + +ls ./migrations/ | xargs -I{} psql \ + --echo-all \ + postgres://$POSTGRES_USER:$POSTGRES_PASSWORD@localhost:5433/$POSTGRES_DB \ + --file=./migrations/{}