Skip to content

Commit 6f05e44

Browse files
neil-iohkstevenj
andauthored
refactor: update sql schema autogen tool (#331)
* chore(tooling): swap out dbviz custom database diagram tool for SchemaSpy, remove dependencies in catalyst-ci postgresql base * chore(tooling): swap out dbviz custom database diagram tool for SchemaSpy, remove dependencies in catalyst-ci postgresql base * chore(tooling): refactored how the dependencies are downloaded and cached to avoid apt install executing every run (reduced network calls) * chore(tooling): refactored how the dependencies are downloaded and cached to avoid apt install executing every run (reduced network calls) * chore(tooling): Fix markdown warnings breaking the CI build. No warnings required on md file as it is just a container for SchemaSpy * chore(tooling): fix breaking CI issues * chore(tooling): fix breaking CI issues * refactor(tooling): modified approach to align with repo goals based on PR feedback. Removed seperate layers for package installs * refactor(tooling): re-ordered package install and download steps for improved caching * refactor(tooling): removed dbviz utility from repository, dbviz is no longer required and has been replaced with SchemaSpy for database schema visualizations diagram generation --------- Co-authored-by: Steven Johnson <[email protected]>
1 parent 9550d36 commit 6f05e44

22 files changed

+148
-1590
lines changed

.config/dictionaries/project.dic

+3-1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ rustflags
9595
rustfmt
9696
rustup
9797
sanchonet
98+
schemaspy
9899
sqlfluff
99100
stdcfgs
100101
subproject
@@ -120,4 +121,5 @@ WORKDIR
120121
xerrors
121122
xvfb
122123
zstd
123-
zstdcat
124+
zstdcat
125+
JDBC

earthly/java/Earthfile

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
VERSION 0.8
2+
3+
# Base image for Java used in other targets to avoid improve caching
4+
java-base:
5+
FROM openjdk:21-jdk-slim
6+
7+
SAVE ARTIFACT /usr/local/openjdk-21 /java
8+
9+
COPY_DEPS:
10+
FUNCTION
11+
COPY +java-base/java /usr/local/openjdk-21
12+
13+
# Set environment variables for Java
14+
ENV JAVA_HOME=/usr/local/openjdk-21
15+
ENV PATH=$JAVA_HOME/bin:$PATH

earthly/postgresql/Earthfile

+33-15
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22
VERSION 0.8
33

44
IMPORT ../rust/tools AS rust-tools
5-
IMPORT ../../utilities/dbviz AS dbviz
65
IMPORT ../../utilities/scripts AS scripts
6+
IMPORT ../java AS java
77

8-
# cspell: words psycopg dbviz
8+
# cspell: words psycopg
99

1010
postgres-base:
1111
FROM postgres:16.4-bookworm
1212

13+
ARG SCHEMASPY_VERSION=6.2.4
14+
ARG POSTGRESQL_JDBC_VERSION=42.7.4
15+
1316
WORKDIR /root
1417

1518
# Install necessary packages
@@ -22,7 +25,7 @@ postgres-base:
2225
colordiff \
2326
findutils \
2427
fontconfig \
25-
fonts-liberation2 \
28+
fonts-liberation2 \
2629
graphviz \
2730
libssl-dev \
2831
mold \
@@ -36,17 +39,20 @@ postgres-base:
3639
pipx \
3740
&& rm -rf /var/lib/apt/lists/*
3841

42+
# Use the cached java installation from the java Earthfile
43+
DO java+COPY_DEPS
44+
3945
# Install SQLFluff - Check
4046
ENV PATH="/root/.local/bin:${PATH}"
4147
RUN pipx install sqlfluff==3.1.1 && sqlfluff version
4248

49+
# Install SchemaSpy and required Postgresql JDBC driver
50+
RUN wget -O /bin/postgresql.jar https://jdbc.postgresql.org/download/postgresql-${POSTGRESQL_JDBC_VERSION}.jar
51+
RUN wget -O /bin/schemaspy.jar https://github.com/schemaspy/schemaspy/releases/download/v${SCHEMASPY_VERSION}/schemaspy-${SCHEMASPY_VERSION}.jar
52+
4353
# Get refinery
4454
COPY rust-tools+tool-refinery/refinery /bin
4555

46-
# Get dbviz
47-
COPY dbviz+build/dbviz /bin
48-
RUN dbviz --help
49-
5056
# Copy our set SQL files
5157
COPY --dir sql /sql
5258

@@ -56,7 +62,11 @@ postgres-base:
5662
DO scripts+ADD_BASH_SCRIPTS
5763
DO scripts+ADD_PYTHON_SCRIPTS
5864

65+
# Copy templates to the working directory
66+
COPY --dir templates /templates
67+
5968
SAVE ARTIFACT /scripts /scripts
69+
SAVE ARTIFACT /templates /templates
6070

6171
# Common build setup steps.
6272
# Arguments:
@@ -82,8 +92,13 @@ BUILDER:
8292

8393
# DOCS - FUNCTION to build the docs, needs to be run INSIDE the BUILDER like so:
8494
#
85-
# 1. Create a ./docs/diagrams.json which has the options needed to run to generate the docs to /docs
86-
# 2. Define the following targets in your earthfile
95+
# This function uses SchemaSpy to generate database documentation.
96+
# SchemaSpy creates detailed, Discoverable ER diagrams and schema documentation.
97+
#
98+
# To use this function:
99+
# 1. Ensure your migrations are in the ./migrations directory
100+
# 2. Have a refinery.toml file to configure the migrations
101+
# 3. Define the following targets in your earthfile:
87102
#
88103
# builder:
89104
# DO github.com/input-output-hk/catalyst-ci/earthly/postgresql:<ver>+BUILDER --sqlfluff_cfg=./../../+repo-config/repo/.sqlfluff
@@ -93,25 +108,27 @@ BUILDER:
93108
#
94109
# DO github.com/input-output-hk/catalyst-ci/earthly/postgresql:<ver>+BUILD --image_name=<name>
95110
# DO github.com/input-output-hk/catalyst-ci/earthly/postgresql:<ver>+DOCS
111+
#
112+
# The generated documentation will be saved in the ./docs artifact.
96113
DOCS:
97114
FUNCTION
98115

99-
ARG diagrams=./diagrams.json
100116
ARG migrations=./migrations
101117
ARG refinery_toml=./refinery.toml
102118

119+
FROM +postgres-base
120+
103121
USER postgres:postgres
104122
WORKDIR /docs
105123

106-
COPY $diagrams ./diagrams.json
107124
COPY --dir $migrations .
108125
COPY --dir $refinery_toml .
109126

110-
RUN /scripts/std_docs.py ./diagrams.json
111-
112-
SAVE ARTIFACT docs /docs
113-
127+
RUN /scripts/std_docs.py
128+
# Pull templates artifact from postgres-base
129+
COPY +postgres-base/templates/schema.md ./docs/schema.md
114130

131+
SAVE ARTIFACT docs ./docs
115132

116133
# Linter checks for sql files
117134
CHECK:
@@ -171,3 +188,4 @@ BUILD:
171188
# Push the container...
172189
SAVE IMAGE ${image_name}:latest
173190

191+

0 commit comments

Comments
 (0)