はじめに
- Dockerで、
rails-erb
を使いER図を作成しようとしたが、Graphvizが必要だとErrorが出た時の対応 - 文字化け出力された時の対応
やりたい事
rails-erd
でER図を作成
環境
- Rails version: 6.1.3
- Ruby version: ruby 3.0.0p0 (2020-12-25 revision 95aff21468)[aarch64-linux-musl]
- mariadb:10.5.8
やったこと
-
bundle exec erd
を実行するもError
# Error
bash-5.0# bundle exec erd
Loading application in 'rails_app'...
ruby/3.0.0 isn't supported by this pry-doc version
Generating entity-relationship diagram for 17 models...
Warning: Ignoring invalid model ActionText::RichText (table action_text_rich_texts does not exist)
Warning: Ignoring invalid model ActionMailbox::InboundEmail (table action_mailbox_inbound_emails does not exist)
Warning: Ignoring invalid model ActiveStorage::Attachment (table active_storage_attachments does not exist)
Warning: Ignoring invalid model ActiveStorage::Blob (table active_storage_blobs does not exist)
Warning: Ignoring invalid model ActiveStorage::VariantRecord (table active_storage_variant_records does not exist)
Warning: Ignoring invalid association :deliveries on User (uninitialized constant User::Delivery)
Warning: Ignoring invalid association :deliveries on Store (uninitialized constant Store::Delivery)
Failed: RuntimeError: Saving diagram failed!
Verify that Graphviz is installed and in your path, or use filetype=dot.
- Error対応:
graphviz
をインストール
Dockerコンテナ内
$ apk add --update --no-cache graphviz
- 再度実行: PDF出力できたと思ったら文字化け。。。
Dockerコンテナ内
# Success
bash-5.0# bundle exec erd
Loading application in 'rails_app'...
ruby/3.0.0 isn't supported by this pry-doc version
Generating entity-relationship diagram for 17 models...
Warning: Ignoring invalid model ActionText::RichText (table action_text_rich_texts does not exist)
Warning: Ignoring invalid model ActionMailbox::InboundEmail (table action_mailbox_inbound_emails does not exist)
Warning: Ignoring invalid model ActiveStorage::Attachment (table active_storage_attachments does not exist)
Warning: Ignoring invalid model ActiveStorage::Blob (table active_storage_blobs does not exist)
Warning: Ignoring invalid model ActiveStorage::VariantRecord (table active_storage_variant_records does not exist)
Warning: Ignoring invalid association :deliveries on User (uninitialized constant User::Delivery)
Warning: Ignoring invalid association :deliveries on Store (uninitialized constant Store::Delivery)
Diagram saved to 'erd.pdf'.
- 参考記事を元にinstall. 中身はよう分からんです。
Dockerコンテナ内
$ apk add --update --no-cache msttcorefonts-installer \
fontconfig \
font-bitstream-type1 \
ghostscript-fonts \
ttf-freefont
$ update-ms-fonts && fc-cache -f && rm -rf /var/cache/*
再出力結果
無事文字化けせずER図出力できました 🙌