From a6412d47ad5d7e0e3e64810688865be9f146a144 Mon Sep 17 00:00:00 2001 From: Sheena Date: Mon, 18 Nov 2024 09:49:10 +0200 Subject: [PATCH] done --- dev_db/README.md | 39 +++++++++++++++++++ dev_db/bin_sh.sh | 3 ++ dev_db/cleanup_devdb.sh | 5 +++ dev_db/docker-compose.yaml | 12 ++++++ .../create-test-db.sql | 3 ++ 5 files changed, 62 insertions(+) create mode 100644 dev_db/README.md create mode 100755 dev_db/bin_sh.sh create mode 100755 dev_db/cleanup_devdb.sh create mode 100644 dev_db/docker-compose.yaml create mode 100644 dev_db/docker-entrypoint-initdb.d/create-test-db.sql diff --git a/dev_db/README.md b/dev_db/README.md new file mode 100644 index 0000000..adaf7d8 --- /dev/null +++ b/dev_db/README.md @@ -0,0 +1,39 @@ +# Development Database + +If you are running the Django development server or the unit tests then you will need to run a database. + +## Prerequisites for running this database + +1. Install Docker +2. Install Docker-compose + +## How about I just install postgres on my operating system? + +You can do that if you really want to BUT then you are on your own when you break it. + +Docker is nice because absolutely everything you need to run a properly configured database is in this directory. And if you break it or want a clean system then resetting the db is trivial. + +## Commands + +To run the db: + +``` +docker-compose up +``` + +To reset your development databases so that they are fresh and clean: + +``` +./cleanup_devdb.sh +docker-compose up +``` + +## Interacting with the databases via django + +Once your composition is up and running: + +``` +python manage.py [any command that interacts with the database] +``` + +This just works. diff --git a/dev_db/bin_sh.sh b/dev_db/bin_sh.sh new file mode 100755 index 0000000..345ecc5 --- /dev/null +++ b/dev_db/bin_sh.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +docker exec -it dev_db_dbs_1 \ No newline at end of file diff --git a/dev_db/cleanup_devdb.sh b/dev_db/cleanup_devdb.sh new file mode 100755 index 0000000..b6ebff2 --- /dev/null +++ b/dev_db/cleanup_devdb.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +docker kill dev_db_dbs_1 +docker rm dev_db_dbs_1 +sudo rm -r ./gitignore \ No newline at end of file diff --git a/dev_db/docker-compose.yaml b/dev_db/docker-compose.yaml new file mode 100644 index 0000000..d836029 --- /dev/null +++ b/dev_db/docker-compose.yaml @@ -0,0 +1,12 @@ +services: + postgres: + image: postgres:12 + environment: + - POSTGRES_USER=pguser + - POSTGRES_PASSWORD=password + - POSTGRES_DB=db + volumes: + - ./gitignore/postgresql:/var/lib/postgresql/data + - ./docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d + ports: + - "6543:5432" diff --git a/dev_db/docker-entrypoint-initdb.d/create-test-db.sql b/dev_db/docker-entrypoint-initdb.d/create-test-db.sql new file mode 100644 index 0000000..13f6268 --- /dev/null +++ b/dev_db/docker-entrypoint-initdb.d/create-test-db.sql @@ -0,0 +1,3 @@ +CREATE DATABASE test_db; +grant all privileges on database test_db to pguser; +-- ALTER USER user WITH SUPERUSER;