From 882eae8a925eab3d0e5d99eb897b510e5a87cfaa Mon Sep 17 00:00:00 2001 From: Eric Rosas Date: Mon, 15 Apr 2024 15:04:54 -0700 Subject: [PATCH] Updated `Makefile` and updated README.md instrctns Updated `Makefile` and updated README.md instructions --- Makefile | 5 +++-- README.md | 30 ++++++++++++++++++++++++++++++ db/Dockerfile | 3 ++- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index b561374..f3d2f83 100644 --- a/Makefile +++ b/Makefile @@ -8,10 +8,11 @@ clean: clean-images: docker images prune -# Requires argument `dbname` to specify the name of the new DB, usage: `make local-db dbname=my_db` +# Requires argument `dbname` to specify the name of the new DB, usage: `make local-db dbname=my_db dbfile=mydb.sql` +# Requires argument `dbfile` to specify the name of the DB dump file to recreate, usage: `make local-db dbname=my_db dbfile=mydb.sql` local-db: cd db && docker exec --workdir / investigations-api-postgres-1 psql -U craft -c "create database $(dbname);" - cd db && docker exec --workdir / investigations-api-postgres-1 psql -U craft -d $(dbname) -f inv_mar.sql + cd db && docker exec --workdir / investigations-api-postgres-1 psql -U craft -d $(dbname) -f $(dbfile) echo "\n\n\n\nDon't forget to update your docker-compose-local-db.yaml with the DB name: $(dbname)" db-list: diff --git a/README.md b/README.md index b64b5ee..d6c61db 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,36 @@ This project was created with Docker version 20.10.5. ## Set up and run the project locally +#### Make scripts + +--- +To list your local DBs: + +`make db-list` + +--- +To list the databases sitting around in the `prod` environment: + +`make cloud-db-list` + +--- +To export a `prod` database to the `gs://release_db_sql_files/investigations/` bucket: + +`make cloud-db-export dbname=prod_db` + +* The argument `dbname` is required and should be one of the databases listed from `make cloud-db-list` +* Once you download the DB dump file, move it to the `./db/` folder +--- +To recreate a local DB from a dump file located within `./db/`: + +`make local-db dbname=my_new_local_db dbfile=prod.sql` + +* The argument `dbname` is required and will be the name of the newly created database +* The argument `dbfile` is required and should be the name of the DB file to recreate, this file _must_ be in the `./db/` folder +--- +#### Deprecated workflow + +0. Uncomment the `COPY` line in `./db/Dockerfile` 1. Install [Docker](https://docs.docker.com/get-docker/) 2. Clone this repository 3. Add a .env file (based on .env.sample) and provide values appropriate to your local dev environment diff --git a/db/Dockerfile b/db/Dockerfile index d57f01f..15efa7e 100644 --- a/db/Dockerfile +++ b/db/Dockerfile @@ -1,3 +1,4 @@ FROM postgres:13-alpine -COPY db.sql /docker-entrypoint-initdb.d/db.sql \ No newline at end of file +# Commented out so that the Makefile DB scripts can do their thing +# COPY db.sql /docker-entrypoint-initdb.d/db.sql \ No newline at end of file