From 65b234f7aa07dffe19f8f87fe73d5c059cf0bb07 Mon Sep 17 00:00:00 2001 From: raul Date: Fri, 6 Dec 2024 09:03:49 +0100 Subject: [PATCH] Add PostgreSQL setup files --- .env.example | 2 ++ .gitignore | 3 +++ db-config/db-data/.blank | 0 db-config/init.sql | 12 ++++++++++++ docker-compose.yml | 13 +++++++++++++ 5 files changed, 30 insertions(+) create mode 100644 .env.example create mode 100644 db-config/db-data/.blank create mode 100644 db-config/init.sql create mode 100644 docker-compose.yml diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..d297b14 --- /dev/null +++ b/.env.example @@ -0,0 +1,2 @@ +POSTGRES_USER=username +POSTGRES_PASSWORD=password diff --git a/.gitignore b/.gitignore index adf8f72..c18b2fc 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,6 @@ # Go workspace file go.work +db-config/db-data/** +!db-config/db-data/.blank +.env diff --git a/db-config/db-data/.blank b/db-config/db-data/.blank new file mode 100644 index 0000000..e69de29 diff --git a/db-config/init.sql b/db-config/init.sql new file mode 100644 index 0000000..0ab903e --- /dev/null +++ b/db-config/init.sql @@ -0,0 +1,12 @@ +-- create a table +CREATE TABLE test( + id INT PRIMARY KEY GENERATED ALWAYS AS IDENTITY, + name TEXT NOT NULL, + archived BOOLEAN NOT NULL DEFAULT FALSE +); + +-- add test data +INSERT INTO test (name, archived) + VALUES ('test row 1', true), + ('test row 2', false); + diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..35005ca --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,13 @@ +services: + postgres: + image: 'postgres:latest' + ports: + - 5432:5432 + environment: + POSTGRES_DB: drahoot + env_file: + - .env + volumes: + - ./db-config/db-data/:/var/lib/postgresql/data/ + - ./db-config/init.sql:/docker-entrypoint-initdb.d/init.sql + user: "1000:1000"