diff --git a/Makefile b/Makefile index cee71afc..d14df6f3 100644 --- a/Makefile +++ b/Makefile @@ -7,10 +7,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 / rubin-obs-api-postgres-1 psql -U craft -c "create database $(dbname);" - cd db && docker exec --workdir / rubin-obs-api-postgres-1 psql -U craft -d $(dbname) -f inv_mar.sql + cd db && docker exec --workdir / rubin-obs-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 896dba63..b834bc43 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,36 @@ This project was created with Docker version 20.10.5. ### To use a local db +#### 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/rubinobs/` 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 d57f01f3..15efa7eb 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