Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
人魚とたわむれる
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
muryoimpl
August 16, 2025
Programming
71
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
人魚とたわむれる
Kanazawa.rb meetup #156 祝13周年 LT大会 (石川県立図書館) でやった LT資料。
muryoimpl
August 16, 2025
More Decks by muryoimpl
See All by muryoimpl
Rubyで鍛える仕組み化プロヂュース力
muryoimpl
0
2.5k
Kanzawa.rbのLT大会を支える技術の裏側を変更する Ruby on Rails + Litestream 編
muryoimpl
0
2.4k
Kanazawa.rb LT大会用/kzlt コマンドの説明 2024/01版
muryoimpl
0
3.1k
kzltコマンドの新たなソリューションについて
muryoimpl
0
3.1k
俺とTODOアプリ~Linearの変~
muryoimpl
0
2.9k
POSIX文字クラスでの躓き
muryoimpl
0
2.4k
/kzlt コマンドとは
muryoimpl
0
1.1k
meetup.kzrb.org の更新を考える 事前激闘編
muryoimpl
0
1.7k
meetup.kzrb.org の更新を 考える ゆるふわ編
muryoimpl
0
1.7k
Other Decks in Programming
See All in Programming
iOSDCのペンライトを自動制御したい!
akkeylab
0
350
Apple Intelligence を用いた個人情報誤送信防止、及びユーザーリクエスト体験の改善について
yukiny
0
280
速く作れる。その次は、速く確かめられる開発へ 〜AIネイティブ開発を支える、Shift Down〜 / Can build fast. Next, moving to development where we can verify fast.
rkaga
8
5.4k
設計次第でAIコードの読む量は減らせる / designing-for-code-reading
minodriven
33
14k
JAWS-UG 東京支部が始める、JAWS-UG支部コラボ / JAWS-UG lunchtime LT Collaboration
y0hgi
0
170
仕様駆動開発による爆速プロダクト開発 / Bakusoku Spec Driven Development
kobakei
0
160
Simple Storage Service(S3) is not simple
iwatsukayura
0
120
FreeBSDでZabbixを動かす
kenkino
0
350
標準パッケージに uuid が追加された 背景から見る Go らしい意思決定 / go_127_uuid_decision
convto
5
9.5k
setup-vp GitLab対応の裏側
naokihaba
0
150
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
400
Are APIs Still Relevant in the AI Era?
soyuka
0
400
Featured
See All Featured
Everyday Curiosity
cassininazir
0
340
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
1k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
18k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
440
Ethics towards AI in product and experience design
skipperchong
2
410
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
6
1.2k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
200
The agentic SEO stack - context over prompts
schlessera
0
950
The untapped power of vector embeddings
frankvandijk
2
1.9k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
Making the Leap to Tech Lead
cromwellryan
135
10k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
840
Transcript
人魚とたわむれる Kanazawa.rb meetup #156 祝13周年 LT 大会 石川県立図書館 2025-08-16(Sat) muryoimpl
ある日、DB項目ないの? テーブルに何もってるか知りたいんだけど と、言われる
ないんだわ、これが • 継続的成長を義務付けられたソフトウェアについては、項目書作ったときから陳腐 化する • 生温かい手で作ると工数がとんでもなくかかる • 上記理由から、人類が一から頑張ってつくるものではない そうか、自動生成か …となる
調べると gem はありそうだが … • erd や rails-mermaid_erd 、rails-mermaid_erd_markdown など今使われていそう
な gem はある • ただし、大量のテーブルがあるシステムで、グループ化して表示できないと見づら い。とても見づらい。 • 中身を見ると、オープンクラスを駆使して手を入れるにも改造しにくそうな作りになっ てる • インフラ構築を前提とした環境にしたくないな。 • 出力対象外にしたいテーブルがある。日本語名も併記したい
やはり自作するしかないか!
DB情報からテーブルと関連の情報を作って出力するぞ • モデル とモデル同士の関連の情報から、mermaid の ER図を、日本語併記で出力 する • 普段は Notion
を使っているので、Notion のページに language: mermaid として 記述する ◦ 定期実行で更新できそうだしよさそう • i18n の日本語辞書を使い、翻訳がある場合はそれを併記する • ER図にしたのは、クラス図と違ってカラムを足すことができるため ◦ 追加したカラムに日本語名を出す
というので作った https://gist.github.com/muryoimpl/1 d2f325e11074529dab55011967b91b2 TODO: 後でSlack に貼るぞい
つくりはこんな感じ • ApplicationRecord を継承したモデル(テーブルに対応したモデル)を抽出する • column でカラム情報、relations で関連情報を抽出する • i18n
でテーブル、カラムの日本語名を当てる。なければ日本語名を出さない • 設定YAML で、グループ化と無視するテーブルを指定する • has_many, has_one, belongs_to から関連する線の種類を判別して出力する • 一旦、Notion 反映は待って、単純にグループ毎に markdown を出力する
erDiagram "channels: channel" { integer id "" string name "channel名"
string slack_channel_id "チャネルID" integer workspace_id "ワークスペースID" datetime created_at "作成日時" datetime updated_at "更新日時" } "entries: エントリー" { integer id "" string title "発表タイトル" integer status "ステータス" integer channel_id "チャネルID" integer user_id "発表者" datetime created_at "作成日時" datetime updated_at "更新日時" } "users: 発表者" { integer id "" string name "ユーザー名" string slack_user_id "user_id" datetime created_at "作成日時" datetime updated_at "更新日時" } "workspaces: workspace" { integer id "" string name "ワークスペース名" datetime created_at "作成日時" datetime updated_at "更新日時" string slack_team_id "team_id" } "channels: channel" ||--o{ "entries: エントリー" : "" "users: 発表者" ||--o{ "entries: エントリー" : "" "workspaces: workspace" ||--o{ "channels: channel" : ""
erd_mermaid.yml にgroupsに配列を渡 すことで複数のテーブルをグループ化し、 別々のファイルに出力することができる ```yaml groups: environment: - workspaces -
channels entries: - users - entries ```
感想 • has_and_belongs_to_many は未対応で、本体は 300 行くらいで実装できた • モデル情報と関連情報を扱うモデル、出力モデルを分けると、複数の出力形式に 対応できそうですね。 •
i18n 対応と、mermaid で日本語を扱うときの制限が辛かった ◦ 日本語は “あああ” のようにダブルクウォートで囲む必要がある ◦ 関連に名前を付けるの必須だと!? ただし、”” で空文字にできる ◦ Notionだと、direction 指定が使えない。(オブジェクトとして判定されちゃった) • 早くNotion連携版を作らねばならぬ
2につづく