Skip to content

Commit

Permalink
done
Browse files Browse the repository at this point in the history
  • Loading branch information
sheenarbw committed Nov 18, 2024
1 parent 92d4487 commit a6412d4
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 0 deletions.
39 changes: 39 additions & 0 deletions dev_db/README.md
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 3 additions & 0 deletions dev_db/bin_sh.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

docker exec -it dev_db_dbs_1
5 changes: 5 additions & 0 deletions dev_db/cleanup_devdb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

docker kill dev_db_dbs_1
docker rm dev_db_dbs_1
sudo rm -r ./gitignore
12 changes: 12 additions & 0 deletions dev_db/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -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"
3 changes: 3 additions & 0 deletions dev_db/docker-entrypoint-initdb.d/create-test-db.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CREATE DATABASE test_db;
grant all privileges on database test_db to pguser;
-- ALTER USER user WITH SUPERUSER;

0 comments on commit a6412d4

Please sign in to comment.