diff --git a/db/README.md b/db/README.md new file mode 100644 index 000000000..b868fea11 --- /dev/null +++ b/db/README.md @@ -0,0 +1,62 @@ +# WFPrev Local PostGIS Setup + +This guide will help you build a local instance of PostGIS, set up the database, and apply the model using Liquibase from the change log. + +## Prerequisites + +- Docker installed on your local machine. +- `Dockerfile.liquibase.local`, `main-changelog.json`, and the `scripts` folder available in your repository. + +## Project Structure + +- **`main-changelog.json`**: The main Liquibase changelog file, which includes the following changes: + - Creates logins using SQL scripts. + - Creates roles. + - Creates the `wfprev` schema. + - Adds required extensions. +- **`Dockerfile.liquibase.local`**: Dockerfile for running Liquibase commands. +- **`scripts` folder**: Contains the SQL scripts for various database changes as referenced in `main-changelog.json`. + +## Step 1: Pull and Run PostGIS + +1. **Pull the PostGIS Image**: + + ```bash + docker pull postgis/postgis:16-3.4 + +2. **Run the PostGIS Containe**: + + ```bash + docker run --name wfprev-postgres -e POSTGRES_USER=wfprev -e POSTGRES_PASSWORD=password -p 5432:5432 -d postgis/postgis:16-3.4 + +## Step 2: Find the IP Address + +1. **Get the Container ID:** : + docker ps + +2. **Inspect the Container for IP Address:** : + docker inspect + +## Step 3: Set Up and Run Liquibase + +1. **Build the Liquibase Docker Image** : +Create a Dockerfile.liquibase.local with the following content: + +FROM liquibase/liquibase +COPY ./scripts ./scripts +COPY ./main-changelog*.json . +COPY ./liquibase.properties . + +ENTRYPOINT [ "sh", "-c", "liquibase $COMMAND $TARGET_LIQUIBASE_TAG --changelog-file=$CHANGELOG_FILE -Dschemaname=$SCHEMA_NAME" ] + +Build the Liquibase Docker image: +docker build -t liquibase -f Dockerfile.liquibase.local . + +2. ** Run Liquibase Update:**: + +docker run --rm liquibase \ + --url=jdbc:postgresql://:5432/wfprev \ + --changelog-file=main-changelog.json \ + --username=wfprev \ + --password=password \ + update \ No newline at end of file diff --git a/db/README.txt b/db/README.txt deleted file mode 100644 index 8b089d7a1..000000000 --- a/db/README.txt +++ /dev/null @@ -1,28 +0,0 @@ -To build a local instance of Postgis and create the model from the liquibase change log: - -// pull the postgis image -docker pull postgis/postgis:16-3.4 - -// run it -docker run --name wfprev-postgres -e POSTGRES_USER=wfprev -e POSTGRES_PASSWORD=password -p 5432:5432 -d postgis/postgis:16-3.4 - - -//If you want to mount a data directory, add this additional config: -``` --v /data:/var/lib/postgresql/data -``` - -// to find the IP address -docker ps -docker inspect -~ or ~ -docker exec -it /bin/bash -ip -4 -o address -exit - -// then create the liquibase image and run that - -docker build -t liquibase -f Dockerfile.liquibase.local . -docker run --rm liquibase --url=jdbc:postgresql://172.17.0.2:5432/wfprev --changelog-file=main-changelog.json --username=wfprev --password=password update - -// Data load coming soon... \ No newline at end of file