0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Rails rails-erd で ER図出力 ( Docker, alpine )

Last updated at Posted at 2021-03-19

はじめに

  • 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図出力できました 🙌

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?