Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Rails と人魚の話/rails-and-mermaid
Search
Masatoshi Moritsuka
April 04, 2024
Programming
0
160
Rails と人魚の話/rails-and-mermaid
Masatoshi Moritsuka
April 04, 2024
Tweet
Share
More Decks by Masatoshi Moritsuka
See All by Masatoshi Moritsuka
パターンマッチ使ってるかい?(kyobashi.rb)/use-ruby-s-pattern-matching-on-kyobashi-rb
sanfrecce_osaka
0
69
ApplicationController の継承を分割してエラーを減らした話/dividing-application-controller
sanfrecce_osaka
1
160
Input object ではじめる入力値検証/input-value-validation-using-input-object
sanfrecce_osaka
0
330
実例で学ぶRailsアプリケーションデバッグ入門 〜ログインできちゃってました編〜/rails-application-debug-introduction
sanfrecce_osaka
2
630
String#split何もわかっていなかった/didn_t_know_anything_about_string_split
sanfrecce_osaka
0
110
String#split何もわかっていなかった/didn-t-know-anything-about-string-split
sanfrecce_osaka
0
50
パターンマッチ使ってるかい?/use-ruby-s-pattern-matching?
sanfrecce_osaka
0
700
新しいコミュニティを立ち上げるぞい/launch-new-community
sanfrecce_osaka
0
130
コミュニティ・勉強会の情報収集について/about-collecting-community-information
sanfrecce_osaka
0
87
Other Decks in Programming
See All in Programming
Introduction of Happy Eyeballs Version 2 (RFC8305) to the Socket library
coe401_
1
220
Rubyのパフォーマンスプロファイリングの改善 / Enhancing performance profiling for Ruby
osyoyu
1
410
MIERUNE BBQにおけるユーザー中心設計()
mierune
PRO
1
110
Findy - エンジニア向け会社紹介 / Findy Letter for Engineers
findyinc
2
81k
開発部に不満を持っていたCSがエンジニアにジョブチェンしてわかった「勝手に諦めない」ことの大切さ
sakuraikotone
28
16k
12年前の『型システム入門』翻訳の思い出話
mame
11
1.2k
feature環境をGitHub ActionsとCloudFormationでいい感じに管理する
nealle
2
310
初心者がおさえておきたいAWS CDKのベストプラクティス 2024
konokenj
15
7.3k
リハビリmruby
kishima
1
160
OpenAI/Gemini APIを使って EPUBを翻訳するCLIツールをつくってみた
tomiyan
0
790
Activities at Cairo Library
cairolibrary720
0
1.2k
しくじり先生 Image Matching Challenge 2024 編
goosehaaan
0
810
Featured
See All Featured
Designing for humans not robots
tammielis
247
25k
Practical Orchestrator
shlominoach
185
10k
Why You Should Never Use an ORM
jnunemaker
PRO
51
8.9k
How To Stay Up To Date on Web Technology
chriscoyier
784
250k
Principles of Awesome APIs and How to Build Them.
keavy
124
16k
Clear Off the Table
cherdarchuk
89
320k
A Modern Web Designer's Workflow
chriscoyier
689
190k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
277
13k
Atom: Resistance is Futile
akmur
261
25k
Intergalactic Javascript Robots from Outer Space
tanoku
266
26k
WebSockets: Embracing the real-time Web
robhawkes
59
7.2k
The Invisible Customer
myddelton
117
13k
Transcript
Rails と人魚の話 森塚 真年(@sanfrecce_osaka) 2024/04/04 Omotesando.rb#96 #omotesandorb
自己紹介 森塚 真年 @sanfrecce-osaka or @sanfrecce_osaka from: 大阪府枚方市 趣味: コミュニティ・勉強会
Machida.rb ・Hirakata.rb 株式会社エンペイ Ruby3.2/Rails7.0 Node.js v18/Vue.js 3.3/Vuetify 3.4 最近 Layout Cop を全部ドキュメント読んで設 定した
本編
ER 図
何使ってますか?
選択肢 gem gem 以外 DB クライアント(e.g. table plus) rails-erd erd
rails_erd_mermaid rails-mermaid_erd plant_erd
そもそもの要件 graphviz への依存がない エンジニア以外も触れるようにしたい エンペイではエンジニア以外も SQL を書いて いる
選ばれたのは
rails-mermaid_erd でした
rails-mermaid_erd 導入の手順 Gemfile に gem "rails-mermaid_erd", group: :development を追加 bin/rails
mermaid_erd Rails のER 図をMermaid で柔軟に生成できるGem を 作りました Repository Demo Page
できること ER 図の各種エクスポート・コピー Mermaid ・Markdown ・SVG ・PNG リレーションのプレビュー リレーションのコメントの表示 カラムの非表示
キーの表示 カラムコメントの表示 表示対象の絞り込み
できないこと テーブルのコメントの表示 mermaid のコメントとしてなら吐けるので PR 出す予定
裏側の仕組み 1. で model の 定義から Hash を組み立て 2. の
window.SCHEMA_DATA に 1 で組み立てた Hash を json に変換して bind 3. ファイルとして出力(JS 部分は cdn の Vue を使っ ているので html ファイル単体で動く) RailsMermaidErd::Builder.model_data templates/index.html.erb
ところで
そもそもの要件 graphviz への依存がない エンジニア以外も触れるようにしたい エンペイではエンジニア以外も SQL を書いて いる
🤔
そうだ!
migration に hook させて git で 管理しよう! %w(db:migrate db:schema:load).each do
|task| Rake::Task[task].enhance do Rake::Task['mermaid_erd'].invoke if Rails.env.development? end end
あとはこうして models/documentation.rb module Documentation; end
こうして ActiveAdmin.register Documentation do actions :index controller do def index
redirect_to admin_documentations_erd_path end end end
こうして config/routes.rb namespace :admin do namespace :documentations do resource :erd,
only: :show, format: 'html' end end
こうじゃ! config/mermaid_erd.yml result_path: app/views/admin/documentations/erds/show.html.erb
最後に rails-mermaid_erd べんり migration に hook させて更新して git 管理すれば view
として扱える activeadmin 等の管理画面の view ファイルとして 扱えば認証も解決 ( 今後は) 社内で ER 図 の勉強会 をやっていき!
ご清聴 ありがとうございました
None