CrustyCookies/Makefile
2024-03-17 15:59:58 +01:00

55 lines
1.5 KiB
Makefile

# SQLite database filename
DB_FILE = db.sqlite3
# Directory containing migration SQL script
MIGRATIONS_DIR = migrations
# Clean target
clean:
rm -f db.sqlite3
rm -f diagram*
rm -f plantuml.jar
rm -f erd.png
# Migration target
migrate:
@echo "If this ever fails, run make clean and try again"
@echo "Migrating database $(DB_FILE) using SQL scripts in $(MIGRATIONS_DIR)"
@for file in $(wildcard $(MIGRATIONS_DIR)/*.sql); do \
echo "Applying migration: $$file"; \
sqlite3 $(DB_FILE) < $$file; \
done
# Target added primarily for CI/CD to ensure that the database is created before running tests
db.sqlite3:
make migrate
dbdump:
sqlite3 $(DB_FILE) .dump > database.txt
backup:
mkdir -p backups
sqlite3 $(DB_FILE) .dump | gzip -9 > ./backups/BACKUP_$(DB_FILE)_$(shell date +"%Y-%m-%d_%H:%M:%S").sql.gz
# Restore with:
# gzip -cd BACKUP_FILE.sql.gz | sqlite3 $(DB_FILE)
# Default target
default: migrate
# Generate ERD
# Requires eralchemy2
.PHONY: erd
erd:
eralchemy2 -i sqlite:///db.sqlite3 -o erd.png
# Fetches the latest plantuml.jar and checks its SHA256 hash
plantuml.jar:
curl -sSfL https://github.com/plantuml/plantuml/releases/download/v1.2024.3/plantuml.jar -o plantuml.jar \
&& echo "519a4a7284c6a0357c369e4bb0caf72c4bfbbde851b8c6d6bbdb7af3c01fc82f plantuml.jar" | sha256sum -c
# Generate UML diagrams diagral.png & diagram.svg
.PHONY: uml
uml: plantuml.jar
goplantuml -recursive . > diagram.puml
java -jar plantuml.jar -tpng diagram.puml
java -jar plantuml.jar -tsvg diagram.puml