From 8cb3c43e75a92b1d9c2eb0c79e0c6416de9d0a60 Mon Sep 17 00:00:00 2001 From: Splines Date: Thu, 3 Oct 2024 17:14:17 +0200 Subject: [PATCH] Init support for entity-relationship-diagram creation --- .config/commands/utils.justfile | 71 +++++++++++++++++++++++++++++++++ .justfile | 3 ++ docker/development/Dockerfile | 2 +- 3 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 .config/commands/utils.justfile diff --git a/.config/commands/utils.justfile b/.config/commands/utils.justfile new file mode 100644 index 000000000..1e5e29b9d --- /dev/null +++ b/.config/commands/utils.justfile @@ -0,0 +1,71 @@ +# Prints this help message +[private] +help: + @just --list --justfile {{source_file()}} + +# Generates entity-relationship diagrams (ERD) of the database +erd: + #!/usr/bin/env bash + + # Make sure the mampf dev container is running + cd {{justfile_directory()}}/docker/development/ + if [ -z "$(docker compose ps --services --filter 'status=running' | grep mampf)" ]; then + echo "The mampf dev container is not running. Please start it first (use 'just docker')." + exit 1 + fi + + mkdir -p {{justfile_directory()}}/tmp/erd/ + + # ▶ Generate ERDs + # Customize it with options from here: https://voormedia.github.io/rails-erd/customise.html + # Also see the output from: 'bundle exec erd --help' (inside the dev container) + + # Ignore some tables + ignored_thredded="Thredded::Post,Thredded::UserPostNotification,Thredded::PrivateUser,Thredded::UserPrivateTopicReadState,Thredded::PrivateTopic,Thredded::MessageboardUser,Thredded::PrivatePost,Thredded:UserDetail,Thredded::MessageboardGroup,Thredded::Messageboard,Thredded::Category,Thredded::TopicCategory,Thredded::Topic,Thredded::UserTopicReadState,Thredded::UserTopicFollow,Thredded::NotificationsForFollowedTopics,Thredded::MessageboardNotificationsForFollowedTopics,Thredded::UserPreference,Thredded::UserMessageboardPreference,Thredded::NotificationsForPrivateTopics,Thredded::PostModerationRecord,Thredded::UserDetail" + ignored_translation="Mobility::Backends::ActiveRecord::Table::Translation,Subject::Translation,Program::Translation,Division::Translation" + ignored_commontator="Commontable,Votable,Subscriber,Creator" + other_ignored="ActionMailbox::Record,ActionText::Record,ActiveStorage::Record,Sluggable,FriendlyId::Slug,ApplicationRecord,InteractionsRecord" + exclude_default="${ignored_thredded},${ignored_translation},${ignored_commontator},${other_ignored}" + + # 🌟 Overview with attributes (warnings will be printed only here) + docker compose exec -it mampf rake erd \ + title=false filename=/usr/src/app/tmp/erd/mampf-erd-overview-with-attributes \ + inheritance=false polymorphism=true indirect=false attributes=content \ + exclude="${exclude_default}" + + # 🌟 Generic Overview + docker compose exec -it mampf rake erd warn=false \ + title=false filename=/usr/src/app/tmp/erd/mampf-erd-overview \ + inheritance=false polymorphism=true indirect=false attributes=false \ + exclude="${exclude_default}" + + # 🌟 Vouchers + docker compose exec -it mampf rake erd warn=false \ + title="Vouchers" filename=/usr/src/app/tmp/erd/mampf-erd-vouchers \ + inheritance=true polymorphism=true indirect=true attributes=content \ + exclude="${exclude_default},Teachable,Editable" \ + only="User,Claim,Voucher,Redemption,Lecture,Tutorial,Talk" + + # 🌟 Tutorials + docker compose exec -it mampf rake erd warn=false \ + title="Tutorials" filename=/usr/src/app/tmp/erd/mampf-erd-tutorials \ + inheritance=true polymorphism=true indirect=true attributes=content \ + exclude="${exclude_default},Claimable,Editable,Teachable" \ + only="User,Lecture,Tutorial,Submission,Assignment,TutorTutorialJoin,UserSubmissionJoin" + + # 🌟 Courses + docker compose exec -it mampf rake erd warn=false \ + title="Courses" filename=/usr/src/app/tmp/erd/mampf-erd-courses \ + inheritance=true polymorphism=true indirect=true attributes=content \ + exclude="${exclude_default},Claimable,Editable" \ + only="Subject,Program,Division,DivisionCourseJoin,Course,Lecture,CourseSelfJoin,Lesson" + + # 🌟 Lectures + docker compose exec -it mampf rake erd warn=false \ + title="Lectures" filename=/usr/src/app/tmp/erd/mampf-erd-lectures \ + inheritance=true polymorphism=true indirect=true attributes=content \ + exclude="${exclude_default},Claimable,Editable,Teachable" \ + only="Lecture,Lesson,Chapter,Section,Item,LessonSectionJoin,Term" + + echo "📂 Diagrams are ready for you in the folder {{justfile_directory()}}/tmp/erd/" + echo "🔀 For the meanings of the arrows, refer to https://voormedia.github.io/rails-erd/gallery.html#notations" diff --git a/.justfile b/.justfile index 5b36d3496..db8231023 100644 --- a/.justfile +++ b/.justfile @@ -13,6 +13,9 @@ mod test ".config/commands/test.justfile" # Docker-related commands mod docker ".config/commands/docker.justfile" +# Some utils, e.g. ERD-generation etc. +mod utils ".config/commands/utils.justfile" + # Opens the MaMpf wiki in the default browser wiki: #!/usr/bin/env bash diff --git a/docker/development/Dockerfile b/docker/development/Dockerfile index 8b6201bd7..7a3efdf5b 100644 --- a/docker/development/Dockerfile +++ b/docker/development/Dockerfile @@ -53,7 +53,7 @@ RUN yarn set version "${YARN_VERSION}" RUN apt update && \ apt-get install -y --no-install-recommends \ ffmpeg imagemagick pdftk ghostscript shared-mime-info \ - libarchive-tools postgresql-client-13 wget wait-for-it + libarchive-tools postgresql-client-13 wget wait-for-it graphviz # Setup ImageMagick RUN sed -i '/disable ghostscript format types/,+6d' /etc/ImageMagick-6/policy.xml