Last active
June 26, 2024 04:32
-
-
Save vinaysshenoy/b02bff9e1642692d74307e049203b2e7 to your computer and use it in GitHub Desktop.
Generate DB docs automatically
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- name: Check DB schema docs | |
run: | | |
DOCS_FOLDER="/tmp/qweebi-docs-gen/" | |
mkdir -p $DOCS_FOLDER | |
chmod 777 $DOCS_FOLDER | |
./flyway/generate_db_docs.sh versions.env -nohtml $DOCS_FOLDER | |
GENERATED_SCHEMA_HASH=$(md5sum -t /tmp/qweebi-docs-gen/db.public.xml | cut -c 1-32) | |
EXISTING_SCHEMA_HASH=$(md5sum -t ./flyway/docs/db.public.xml | cut -c 1-32) | |
echo "Generated schema hash: $GENERATED_SCHEMA_HASH, Saved schema hash: $EXISTING_SCHEMA_HASH" | |
if [[ "$GENERATED_SCHEMA_HASH" == "$EXISTING_SCHEMA_HASH" ]]; then | |
exit 0 | |
else | |
echo $'Database schema has been modified without updating the docs. Run `npm run updateDbSchemaDocs` and commit the results to update the docs!' | |
exit 1 | |
fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
./flyway/generate_db_docs.sh versions.env "" ./flyway/docs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
export $(grep -v '^#' $1 | xargs) | |
POSTGRES_USER="postgres" | |
POSTGRES_PASSWORD="password" | |
POSTGRES_DB="db" | |
DOCS_FOLDER=$3 | |
echo "Start Postgres server locally" | |
docker run --name postgres-schemaspy -e POSTGRES_PASSWORD=$POSTGRES_PASSWORD -e POSTGRES_USER=$POSTGRES_USER -e POSTGRES_DB=$POSTGRES_DB -p 5432:5432 -d postgres:$POSTGRES_VERSION | |
# We need to wait for postgres to start | |
WAIT_FOR=10 | |
COUNTER=0 | |
until docker container exec postgres-schemaspy pg_isready; do | |
>&2 echo "#$COUNTER: Postgres is unavailable - waiting for it... 😴" | |
sleep 1 | |
let COUNTER++ | |
if [[ "$COUNTER" -eq $WAIT_FOR ]]; then | |
docker rm --force postgres-schemaspy | |
exit 1 | |
fi | |
done | |
# Run DB migrations | |
$(pwd)/db-migrations/gradlew --project-dir $(pwd)/db-migrations run --args="-h=localhost -p=5432 -d=$POSTGRES_DB -u=$POSTGRES_USER -w=$POSTGRES_PASSWORD -m=$(pwd)/flyway/sql" | |
echo "Generate docs using Schema Spy" | |
docker run --rm --network=host -v "$DOCS_FOLDER:/output" schemaspy/schemaspy:$SCHEMASPY_VERSION -t pgsql11 -host localhost -port 5432 -db $POSTGRES_DB -u $POSTGRES_USER -p $POSTGRES_PASSWORD -vizjs $2 | |
echo "Teardown postgres server" | |
docker rm --force postgres-schemaspy |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
POSTGRES_VERSION=14.10 | |
SCHEMASPY_VERSION=6.2.4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment