@ledsun blog

無味の味は佳境に入らざればすなわち知れず

ActiveRecordを継承したクラスのクラス図を開くワンライナー

curl -s https://gist.githubusercontent.com/ledsun/76d5485644685f19c98f88000a971d00/raw/ec1251e6b00cda7d9c350178dc445052e87a3e21/class_diagram.rb | bin/rails runner - Computer | browser

実行するとこういう感じです。

gyazo.com

種を明かします。 昨日のスクリプトをmermaid.jsを埋め込んだHTMLファイルを吐き出すように修正しました。

生成したHTMLをパイプで、pipe html to a browser · GitHub に渡すと、ブラウザで開きます。

ここまで来ると大分イケてる感じがしてきました。

ActiveRecordを継承したクラスのmermaid.jsクラス図を作るワンライナー

curl https://gist.githubusercontent.com/ledsun/76d5485644685f19c98f88000a971d00/raw/a1aa3df955ee8829b7041c1c6cda11610978d393/class_diagram.rb
 | bin/rails runner - Computer

実行すると次の感じです。

~ curl https://gist.githubusercontent.com/ledsun/76d5485644685f19c98f88000a971d00/raw/a1aa3df955ee8829b7041c1c6cda11610978d393/class_diagram.rb | bin/rails runner - Computer
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   867  100   867    0     0  12092      0 --:--:-- --:--:-- --:--:-- 12211
Running via Spring preloader in process 13045
classDiagram
class Computer {
   integer id
    string user_name
    string maker
    string memory
   integer release_year
  datetime created_at
  datetime updated_at
}

正体は、以前作った ActiveRecordを継承したクラスからUMLクラス図をMermaid.jsで作る - @ledsun blog をgistに置いただけです。

Railsで静的ファイル配信をするときに圧縮ファイルを優先して返す機能

僕はこの機能の存在を今日知りました。

Railsで、public_file_serverを有効にするとpublicディレクトリ配下にある静的ファイルをファイルを配信できます。 このとき、hoge.cssファイルの代わり(または一緒に)gzip圧縮したhoge.css.gzファイルを置いておくと、gzip圧縮したhoge.cssとして配布してくる機能です。

Rails 4.2から登場していたようです。

https://github.com/rails/rails/blob/v4.2.0/actionpack/CHANGELOG.md

Requests that hit ActionDispatch::Static can now take advantage of gzipped assets on disk. By default a gzip asset will be served if the client supports gzip and a compressed file is on disk.

Rails 6.1からは Brotli 形式のファイルにも対応しています。

https://github.com/rails/rails/blob/v6.1.0/actionpack/CHANGELOG.md

ActionDispatch::Static handles precompiled Brotli (.br) files.

この機能は ActionDispatch::Staticミドルウェアで、実装されています。

ruby-jpのslackで id:willnet さんに AD::Static refactor with precompressed Brotli support by jeremy · Pull Request #38674 · rails/rails · GitHub *1 を教えてもらいました。

*1:Brotli 形式に対応したPRです。

古代武蔵国府の成立と展開

www.douseisha.co.jp

奈良時代の府中の成り立ちを扱っているみたいです。武蔵の国は埼玉を含むので、府中は南の端です。なぜ端っこなのか?古墳時代を考えると多摩川沿いには、勢多、狛江、調布、多摩とほかにも人が住んでいた場所があります。なぜ、他の土地でなく府中なのか?この辺の話が描いてあるようです。

「ようです」というのは https://www.ktr.mlit.go.jp/ktr_content/content/000616577.pdf の中でたくさん引用されているのを読んで推測したからです。

読んでみたいんですけど、8800円かー

参考

jQueryUIダイアログの上に自作モーダルダイアログをつくって要素をフォーカスするときの注意

次のようにjQueryUIダイアログの上にさらに、自作のモーダルダイアログを開く時の話です。

f:id:ledsun:20210608015618p:plain
jQueryUIダイアログの上に自作モーダルダイアログを開く

「すでにjQueryUIダイアログを使っているのだから、自作のモーダルダイアログは要らないだろう?」という疑問はその通りだと思います。すでに作成済みの自作モーダルダイアログ使い回したいときだと、考えてください。

このとき自作モーダルダイアログのinput要素またはbutton要素にフォーカスを当てたいです。 ところがこれが上手く行きません。 jQueryUIダイアログのフォーカスが奪われます。

https://github.com/jquery/jquery-ui/blob/1.12.1/ui/widgets/dialog.js#L868-L879 の実装を見ると

this._on( this.document, {
  focusin: function( event ) {
    if ( isOpening ) {
      return;
    }

    if ( !this._allowInteraction( event ) ) {
      event.preventDefault();
      this._trackingInstances()[ 0 ]._focusTabbable();
    }
  }
} );

documentのfoucsinイベント監視して、フォーカスを戻しています。 しかもやんちゃなことに、キャプチャリングフェーズです。 自作のモーダルダイアログ内のフォーカスを当てたいHTML要素のイベントが届く前に、このコードは実行されます。

jQueryUIダイアログの上のモーダルダイアログではフォーカスをとれないのか?というとそんなことはありません。 例えばjQueryUIダイアログの上に、jQueryUIダイアログを表示することは可能です。 その判定をしているのがthis._allowInteraction( event )です。

https://github.com/jquery/jquery-ui/blob/1.12.1/ui/widgets/dialog.js#L841-L849

_allowInteraction: function( event ) {
  if ( $( event.target ).closest( ".ui-dialog" ).length ) {
    return true;
  }

  // TODO: Remove hack when datepicker implements
  // the .ui-front logic (#8989)
  return !!$( event.target ).closest( ".ui-datepicker" ).length;
},

何を見ているかというとui-dialogクラスの有無です。

つまり、自作のモーダルダイアログにもui-dialogクラスを追加してあげれば、フォーカスを当てられます。

蛇足

jQueryUIは2016年が最後のリリースなので、それ以降はソースコードの修正はあまりしていないと思っていました。 今回ソースコードを見てみると2020年から、ちょこちょこコミットされていることに気がつきました。

f:id:ledsun:20210608021645p:plain
jQueryUIのコミット

https://github.com/jquery/jquery-ui/graphs/code-frequency

バイホットドッグプレス 完全再録! 試みの地平線 2014年 10/17号 [雑誌] Hot-Dog PRESS Selection

1986年〜2002年の人生相談。 395回あるらしい。うち、6回が、分電子書籍化されています。 相談の回答は、色々なところで引用されています。

ですが、相談の最後についている「友として君に贈る言葉」という、まとめの一言は初めて見ました。 1回につき、一個ぐらい身も蓋もなくてウケるギャグ回答がツボにはまりました。

「異常に高い声で悩んでいます。」という体格のいい男子高校生からの「声でなめられて困る」という相談に

なにもいうことはない。おかまになりなさい。

体格のいい声の高い男性より、体格のいい声の高いおかまの方が怖い。 それはそう。しかも弱点を強みに変える妙手。正論です。 だけど、「そういう回答は期待してねえだろ!」と突っ込みたくなる、身も蓋もなさが良かったです。 *1

割とショックだったのは、この回答を書いているころの北方謙三先生は38歳。 僕も、いつの間にか若者に「ソープへ行け!」と言える年になっていたようです。 *2

参考

anond.hatelabo.jp

www.bookaholic.jp

*1:80年代の話だから成り立つので、2020年だったら、この回答はないですよね・・・

*2:年齢の問題ではない

自殺島

ホーリーランドの余勢を駆って読みました。

自殺未遂者を孤島に集めてバトルロワイヤルです。 「登場人物が全員、精神的に弱い」設定は、物語を転がす始点が誰にでもある点が、なかなか興味深いです。

自殺島というタイトルに反して、ホーリーランドより主人公が明いです。 人をバンバン殺す点は過激です。 人を傷つけるたびに苦悩するのは、ホーリーランドに引き続いて丁寧です。

「自殺志願者が、殺し合いを経て、生きる目的を獲得する」というテーマはめちゃくちゃ安易なお話になりそうなものなのに、エンターテインメントとして成立しているの、さすがです。

ホーリーランド

改めて読み直しました。2000年から2008年の作品でです。 リアルタイムで読んでいた頃は「いじめられっ子が格闘技を身につけて強くなる」初期設定に、ちょっと時代遅れ感がありました。

異種格闘技漫画としても後発なんですよね

その中でも、喧嘩や格闘技における「相手を傷つけるストレス」を扱っている点はすごく珍しいです。 「強くなりたい」と「(親しい)相手を傷つけたくない」で矛盾した主人公の葛藤を、緑川ショウゴというライバルキャラをぶち込んで掘り起こしていくところが好きです。

ふつう、強くなることへの葛藤を描いちゃうと、爽快感が減ってエンタテインメントしにくなっちゃうんですよね。 それを主人公の少年から大人への心の成長と絡めてエンタテインメントに仕切ったのすごい。

参考

anond.hatelabo.jp

ActiveRecordを継承したクラスからUMLクラス図をMermaid.jsで作る

PlantUMLは便利なんだけど、見た目を工夫したいので、Mermaid.jsを試してみます。

f:id:ledsun:20210527031831p:plain
Mermaid.jsで作ったクラス図

mermaid-js.github.io

を使いました。

PlantUMLとMermaid.jsのクラス図の文法は、あまり差が無いようです。 @startuml@endumlを消して、1行目にclassDiagramを追加したら動きました。

model_name = ARGV[0]
class_name = Object.const_get model_name
puts 'classDiagram'
puts "class #{class_name} {"

class_name.columns.each do |c|
  printf "  %8s %s\n", c.type, c.name
end

class_name.public_instance_methods(false).each do |m|
  method_parameters = class_name.new.method(m)
                                .parameters
                                .filter{ |a| a[0] == :req }
                                .map { |a| a[1]}.join(', ')
  printf "  %s(%s)\n", m.to_s, method_parameters
end

puts '}'

class_name.reflect_on_all_associations(:belongs_to).each do |a|
  puts "#{class_name} --* #{a.name.to_s.classify}"
end
class_name.reflect_on_all_associations(:has_many).each do |a|
  puts "#{class_name} *-- #{a.name.to_s.classify}"
end
class_name.reflect_on_all_associations(:has_one).each do |a|
  puts "#{class_name} -- #{a.name.to_s.classify}"
end

ActiveRecordを継承したクラスからUMLクラス図を作る

DBの情報からER図を生成するツールはいくつかあります。 またUMLを生成するツールもあります。

同じような感じで、UMLActiveRecordから取得します。 この手法の利点はメソッド情報がとれることにあります。

model_name = ARGV[0]
class_name = Object.const_get model_name
puts '@startuml'
puts "class #{class_name} {"

class_name.columns.each do |c|
  printf "  %8s %s\n", c.type, c.name
end

class_name.public_instance_methods(false).each do |m|
  method_parameters = class_name.new.method(m)
                                .parameters
                                .filter{ |a| a[0] == :req }
                                .map { |a| a[1]}.join(', ')
  printf "  %s(%s)\n", m.to_s, method_parameters
end

puts '}'

class_name.reflect_on_all_associations(:belongs_to).each do |a|
  puts "#{class_name} --* #{a.name.to_s.classify}"
end
class_name.reflect_on_all_associations(:has_many).each do |a|
  puts "#{class_name} *-- #{a.name.to_s.classify}"
end
class_name.reflect_on_all_associations(:has_one).each do |a|
  puts "#{class_name} -- #{a.name.to_s.classify}"
end

puts '@enduml'

ActiveRecordの情報が欲しいので、次のようにrails runnerから起動します。

~ bin/rails runner class_diagram.rb Dictionary

次のようなPlantUMLのテキストを出力します。

@startuml
class Dictionary {
   integer id
    string name
      text description
   integer user_id
   integer entries_num
  datetime created_at
  datetime updated_at
   boolean public
    string license
    string license_url
      text no_term_words
      text no_begin_words
      text no_end_words
   integer tokens_len_min
   integer tokens_len_max
     float threshold
    string language
  editable?(user)
  autosave_associated_records_for_jobs()
  validate_associated_records_for_jobs()
  undo_entry(entry)
  administrable?(user)
  num_gray()
  num_white()
  num_black()
  create_a_black_entry(entry)
  add_entries(hentries)
  new_entry(label, identifier)
  empty_entries()
  sim_string_db_dir()
  tmp_sim_string_db_path()
  compilable?()
  update_stop_words()
  autosave_associated_records_for_user()
  autosave_associated_records_for_associated_managers()
  validate_associated_records_for_associated_managers()
  compile!()
  simstring_method()
  narrow_entries_by_label(str)
  narrow_entries_by_label_prefix(str)
  narrow_entries_by_label_prefix_and_substring(str)
  narrow_entries_by_identifier(str)
  autosave_associated_records_for_associations()
  autosave_associated_records_for_entries()
  validate_associated_records_for_associations()
  validate_associated_records_for_entries()
  search_term(ssdb, term)
  sim_string_db_path()
  additional_entries()
  to_param()
}
Dictionary --* User
Dictionary *-- Association
Dictionary *-- AssociatedManager
Dictionary *-- Entry
Dictionary *-- Job
@enduml

https://planttext.com/ などで、で画像に変換すると次の図が得られます。

f:id:ledsun:20210525234037p:plain
DictionaryモデルのUMLクラス図

この図を見て嬉しいかどうかは難しいところです。

参考

既存のRailsプロジェクトからカラム情報を取得する(成功)

config/database.ymlを直接読み込むと"pool"=>"<%= ENV.fetch(\"RAILS_MAX_THREADS\") { 5 } %>"という謎の情報が取得され、正しいデータベースへの接続情報が得られません。

<%=%>はeRubyスクリプトです。 Railsアプリケーションなdatabase.ymlは厳密にはeRubyスクリプトです。

正しいデータベースへの接続情報を得るには、YAMLファイルとして読み込むまえに、eRubyスクリプトとして実行する必要があります。

次のイメージです。

~ irb -r 'erb' -r 'yaml'
irb(main):001:0> YAML.load ERB.new(File.read('config/database.yml')).result
=>
{"default"=>{"adapter"=>"sqlite3", "pool"=>5, "timeout"=>5000},
 "development"=>{"adapter"=>"sqlite3", "pool"=>5, "timeout"=>5000, "database"=>"db/development.sqlite3"},
 "test"=>{"adapter"=>"sqlite3", "pool"=>5, "timeout"=>5000, "database"=>"db/test.sqlite3"},
 "production"=>{"adapter"=>"sqlite3", "pool"=>5, "timeout"=>5000, "database"=>"db/production.sqlite3"}}

次のスクリプトを書きます。

require 'erb'
require 'yaml'
require 'active_record'

ActiveRecord::Base.establish_connection YAML.load(ERB.new(File.read('config/database.yml')).result)['development']
class Computer < ActiveRecord::Base; end
Computer.columns.each do |c|
  printf "%20s %10s \n", c.name, c.type
end

実行してみます。

~ time ruby computer_columns.rb
                  id    integer
           user_name     string
               maker     string
              memory     string
        release_year    integer
          created_at   datetime
          updated_at   datetime

________________________________________________________
Executed in  666.37 millis    fish           external
   usr time  523.43 millis  127.00 micros  523.31 millis
   sys time  131.81 millis  673.00 micros  131.14 millis

実行時間1秒以下で、Railsアプリケーションのカラム情報が取得できました。

参考

既存のRailsプロジェクトからカラム情報を取得する(原因)

既存のRailsプロジェクトなので、rails consoleで使用しているデータベースへの接続情報を見れば原因がわかるはずです。

~ bin/rails console
Running via Spring preloader in process 24178
Loading development environment (Rails 6.1.3.2)
irb(main):001:0> Computer.connection.instance_variable_get('@config')
   (0.5ms)  SELECT sqlite_version(*)
=> {:adapter=>"sqlite3", :pool=>5, :timeout=>5000, :database=>"/Users/shigerunakajima/pc_management_desk/db/development.sqlite3"}
~ irb -r 'yaml'
irb(main):001:0> YAML.load_file('config/database.yml')['development']
=> {"adapter"=>"sqlite3", "pool"=>"<%= ENV.fetch(\"RAILS_MAX_THREADS\") { 5 } %>", "timeout"=>5000, "database"=>"db/development.sqlite3"}

違いは

  1. pool
  2. database

あとは接続してみればわかります。

ActiveRecord::Base.establish_connection({:adapter=>"sqlite3", :pool=>5000, :timeout=>5000, :database=>"/Users/shigerunakajima/pc_management_desk/db/development.sqlite3"})
ActiveRecord::Base.connection

は成功します。

ActiveRecord::Base.establish_connection({:adapter=>"sqlite3", :pool=>"<%= ENV.fetch(\"RAILS_MAX_THREADS\") { 5 } %>", :timeout=>5000, :database=>"db/development.sqlite3"})
ActiveRecord::Base.connection

は失敗します。エラーメッセージも同じです。

/Users/shigerunakajima/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activerecord-6.1.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:210:in `block in wait_poll': could not obtain a connection from the pool within 5.000 seconds (waited 5.003 seconds); all pooled connections were in use (ActiveRecord::ConnectionTimeoutError)
    from /Users/shigerunakajima/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activerecord-6.1.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:199:in `loop'
    from /Users/shigerunakajima/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activerecord-6.1.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:199:in `wait_poll'
    from /Users/shigerunakajima/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activerecord-6.1.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:160:in `internal_poll'
    from /Users/shigerunakajima/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activerecord-6.1.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:286:in `internal_poll'
    from /Users/shigerunakajima/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activerecord-6.1.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:155:in `block in poll'
    from /Users/shigerunakajima/.rbenv/versions/3.0.1/lib/ruby/3.0.0/monitor.rb:202:in `synchronize'
    from /Users/shigerunakajima/.rbenv/versions/3.0.1/lib/ruby/3.0.0/monitor.rb:202:in `mon_synchronize'
    from /Users/shigerunakajima/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activerecord-6.1.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:164:in `synchronize'
    from /Users/shigerunakajima/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activerecord-6.1.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:155:in `poll'
    from /Users/shigerunakajima/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activerecord-6.1.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:870:in `acquire_connection'
    from /Users/shigerunakajima/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activerecord-6.1.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:588:in `checkout'
    from /Users/shigerunakajima/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activerecord-6.1.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:428:in `connection'
    from /Users/shigerunakajima/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activerecord-6.1.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:1128:in `retrieve_connection'
    from /Users/shigerunakajima/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activerecord-6.1.3.2/lib/active_record/connection_handling.rb:327:in `retrieve_connection'
    from /Users/shigerunakajima/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activerecord-6.1.3.2/lib/active_record/connection_handling.rb:283:in `connection'
    from (irb):5:in `<main>'
    ... 3 levels...

poolの文字列が問題であることがわかりました。

参考

既存のRailsプロジェクトからカラム情報を取得する(失敗)

一般的なRailsアプリケーションはconfig/database.ymlにデータベースへの接続情報があります。 これをつかってすでに存在しているデータベースからカラム情報を取得してみましょう。

必要なライブラリを読み込んでirbを起動します。

~ irb -r 'active_record' -r 'yaml'

データベースに接続します。

irb(main):001:0> ActiveRecord::Base.establish_connection YAML.load_file('config/database.yml')['development']
=>
#<ActiveRecord::ConnectionAdapters::ConnectionPool:0x00007fa3830aeb68
 @automatic_reconnect=true,
 @available=
  #<ActiveRecord::ConnectionAdapters::ConnectionPool::ConnectionLeasingQueue:0x00007fa3830acd18
   @cond=#<MonitorMixin::ConditionVariable:0x00007fa3830acb10 @cond=#<Thread::ConditionVariable:0x00007fa3830ac9d0>, @monitor=#<Monitor:0x00007fa3830adb00>>,
   @lock=#<ActiveRecord::ConnectionAdapters::ConnectionPool:0x00007fa3830aeb68 ...>,
   @num_waiting=0,
   @queue=[]>,
 @checkout_timeout=5.0,
 @connection_klass=ActiveRecord::Base,
 @connections=[],
 @db_config=
  #<ActiveRecord::DatabaseConfigurations::HashConfig:0x00007fa3a3444fc8
   @configuration_hash={:adapter=>"sqlite3", :pool=>"<%= ENV.fetch(\"RAILS_MAX_THREADS\") { 5 } %>", :timeout=>5000, :database=>"db/development.sqlite3"},
   @env_name="default_env",
   @name="primary">,
 @idle_timeout=300.0,
 @lock_thread=false,
 @mon_data=#<Monitor:0x00007fa3830adb00>,
 @mon_data_owner_object_id=380,
 @now_connecting=0,
 @pool_config=
  #<ActiveRecord::ConnectionAdapters::PoolConfig:0x00007fa3830bf5d0
   @_mutex=#<Thread::Mutex:0x00007fa3830bf490>,
   @connection_klass=ActiveRecord::Base,
   @db_config=
    #<ActiveRecord::DatabaseConfigurations::HashConfig:0x00007fa3a3444fc8
     @configuration_hash={:adapter=>"sqlite3", :pool=>"<%= ENV.fetch(\"RAILS_MAX_THREADS\") { 5 } %>", :timeout=>5000, :database=>"db/development.sqlite3"},
     @env_name="default_env",
     @name="primary">,
   @pool=#<ActiveRecord::ConnectionAdapters::ConnectionPool:0x00007fa3830aeb68 ...>>,
 @query_cache_enabled=
  #<Concurrent::Map:0x00007fa3830ad9e8 entries=0 default_proc=#<Proc:0x00007fa3830ad0b0 /Users/shigerunakajima/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activerecord-6.1.3.2/lib/active_record/connection_adapters/abstract/query_cache.rb:32>>,
 @reaper=#<ActiveRecord::ConnectionAdapters::ConnectionPool::Reaper:0x00007fa3830ac728 @frequency=60.0, @pool=#<ActiveRecord::ConnectionAdapters::ConnectionPool:0x00007fa3830aeb68 ...>>,
 @size=0,
 @thread_cached_conns=#<Concurrent::Map:0x00007fa3830aced0 entries=0 default_proc=nil>,
 @threads_blocking_new_connections=0>
irb(main):002:0>

適当なクラスを定義します。

irb(main):002:0> class Computer < ActiveRecord::Base; end

カラム情報を取得しようとするのデータベースへの接続エラーが起きます。

irb(main):003:0> Computer.columns
/Users/shigerunakajima/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activerecord-6.1.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:210:in `block in wait_poll': could not obtain a connection from the pool within 5.000 seconds (waited 5.001 seconds); all pooled connections were in use (ActiveRecord::ConnectionTimeoutError)
  from /Users/shigerunakajima/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activerecord-6.1.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:199:in `loop'
  from /Users/shigerunakajima/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activerecord-6.1.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:199:in `wait_poll'
    from /Users/shigerunakajima/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activerecord-6.1.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:160:in `internal_poll'
  from /Users/shigerunakajima/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activerecord-6.1.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:286:in `internal_poll'
  from /Users/shigerunakajima/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activerecord-6.1.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:155:in `block in poll'
    from /Users/shigerunakajima/.rbenv/versions/3.0.1/lib/ruby/3.0.0/monitor.rb:202:in `synchronize'
  from /Users/shigerunakajima/.rbenv/versions/3.0.1/lib/ruby/3.0.0/monitor.rb:202:in `mon_synchronize'
  from /Users/shigerunakajima/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activerecord-6.1.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:164:in `synchronize'
    from /Users/shigerunakajima/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activerecord-6.1.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:155:in `poll'
  from /Users/shigerunakajima/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activerecord-6.1.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:870:in `acquire_connection'
  from /Users/shigerunakajima/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activerecord-6.1.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:588:in `checkout'
    from /Users/shigerunakajima/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activerecord-6.1.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:428:in `connection'
  from /Users/shigerunakajima/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activerecord-6.1.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:1128:in `retrieve_connection'
  from /Users/shigerunakajima/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activerecord-6.1.3.2/lib/active_record/connection_handling.rb:327:in `retrieve_connection'
    from /Users/shigerunakajima/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activerecord-6.1.3.2/lib/active_record/connection_handling.rb:283:in `connection'
  from /Users/shigerunakajima/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activerecord-6.1.3.2/lib/active_record/model_schema.rb:553:in `load_schema!'
  ... 9 levels...

データベースへの接続情報が正しく取得できていないようです。

参考