なるようになるブログ

読書感想文かrailsについてかrubyについてか

rails commit log流し読み(2020/02/25)

2020/02/25分のコミットです。

CHANGELOGにのったコミットは以下の通りです。

activerecord/CHANGELOG.md


Update boolean attributes for actionview tag helper

actionview/lib/action_view/helpers/tag_helper.rbの修正です。

値をbooleanとして扱うattributeの一覧に、allowpaymentrequestnomoduleplaysinlineを追加しています。

参考: HTML Standard


Clarify documentation on ActiveRecord Callbacks

activerecord/lib/active_record/callbacks.rbのdocの修正です。

callbacksのdocについて、グラマー、フォーマットの修正等を行っています。


Fix a doc regression [ci skip]

activerecord/lib/active_record/callbacks.rbのdocの修正です。

先のdocの修正で、callbackの説明の順番、callbackに指定出来る種類の数を誤って修正してしまっていたのを、元の内容に戻しています。


Adds additional database-specific rake tasks for multi-database users

activerecord/lib/active_record/railties/databases.rakeの修正です。

db:schema:dump, db:schema:load, db:structure:dump, db:structure:load, db:test:prepare タスクで、各DB向けのタスク(e.g. db:schema:dump:primarydb:structure:load:animals)を実行出来るよう対応しています。


Deprecate spec_name and use name for configurations

Active Recordの修正です。

configs_forDatabaseConfigspec_nameがdeprecateになりました。今後はnameを使用する必要があります。

db_config = ActiveRecord::Base.configs_for(env_name: "development", spec_name: "primary")
db_config.spec_name

としていたのを、

db_config = ActiveRecord::Base.configs_for(env_name: "development", name: "primary")
db_config.name

とする必要があります。

元々はconnection_specification_namespec_nameを同一のものとして扱えるようにする予定があった為、spec_nameという名前にしたそうなのですが、実際色々対応した結果、それは無理そう、かつ、そうするとspec_nameという名前がconnection_specification_nameと混ざって混乱の元となってしまっている、という事で名前を変更する事に決めたそうです。


Add support for horizontal sharding

Active Recordの修正です。

connects_toconnected_toにhorizontal shardingのサポートを追加しています。

shardは、複数DBと同様にdatabase.ymlに定義します。

production:
  primary:
    database: my_database
  primary_shard_one:
    database: my_database_shard_one

定義したshardを、connects_toconnected_toに指定する事で、そのshardに接続されるようになります。

class ApplicationRecord < ActiveRecord::Base
  self.abstract_class = true
  connects_to shards: {
    default: { writing: :primary },
    shard_one: { writing: :primary_shard_one }
  }
ActiveRecord::Base.connected_to(shard: :shard_one) do
  # Read from shard one
end

なお、今のところ自動でshardを切り替えるようなAPIは準備されておらず、ユーザが独自に処理を行う必要があります。


Normalize resetting schema cache version for YAML and Marshal

activerecord/lib/active_record/connection_adapters/schema_cache.rbの修正です。

schema cacheのversionリセット処理をメソッドに切り出して、YAML / Marshalどちらのフォーマットを使用している場合でもそのメソッドを使用使用するよう修正しています。


Merge pull request #38403 from sikachu/sikachu-update-maintenance-policy-doc

rails guideのMaintenance Policy for Ruby on Railsの修正です。

Security Issuesの項にあるsecurity releaseのexampleのバージョンを1.2.3から1.2.2.1に修正しています。

最近のsecurity releaseは4桁目(e.g. 6.0.2.1)を使用している為。


Use tempfile when writing schema cache

activerecord/lib/active_record/connection_adapters/schema_cache.rbの修正です。

schema cacheを作成する際にFile.atomic_writeを使用するよう修正しています。中途半端な状態のファイルが読まれるのを防ぐ為。


Merge pull request #38566 from kytrinyx/gzip-schema-cache

activerecord/lib/active_record/connection_adapters/schema_cache.rbの修正です。

schema cacheファイルにgzipのサポートを追加しています。

YAML と Marshalどちらのシリアライゼーションの場合も対応しており、ファイルの拡張子がgzの場合、まずgzip形式のファイルとして扱うよう対応しています。


Add TODO for removal of SERVER_ADDR

actionpack/lib/action_dispatch/http/request.rbの修正です。

Rack 2.1のサポートを削除するときにSERVER_ADDRも削除する旨TODOコメントを追加しています。

Rack 2.2でSERVER_ADDRが削除された為。参考: Remove SERVER_ADDR.


Merge pull request #38570 from rails/eeliminate-hash-on-render

activerecord/lib/active_record/railties/collection_cache_association_loading.rbの修正です。

ActiveRecord::Railties::CollectionCacheAssociationLoading moduleでメソッドに引数を渡す際に**を使用していたのを必要な引数だけ明示的に渡すよう修正しています。**を使用するとhash objectの生成が発生してしまう為。


reset_column_information does not reset @predicate_builder

activerecord/test/cases/relation/predicate_builder_test.rbの修正です。

predicate builderのテストの後処理でreset_column_informationを使用していたのを@predicate_builderに明示的にnilを指定するよう修正しています。reset_column_informationだと@predicate_builderがリセットされない為。


Fixup CHANGELOGs [ci skip]

CHANGELOGの修正です。

各エントリーのフォーマット、グラマーの修正等をまとめて行っています。


Fix deprecation warnings in connection_handlers_sharding_db_test.rb

activerecord/test/cases/connection_adapters/connection_handlers_sharding_db_test.rbの修正です。

deprecateになったspec_nameを使用している箇所をnameを使用するよう修正しています。


Remove duplicate part from deprecation warning

activerecord/lib/active_record/database_configurations/database_config.rbactiverecord/lib/active_record/tasks/database_tasks.rbの修正です。

spec_nameを使用した場合に表示されるdeprecation messageから、重複している内容を削除しています。


Clarify the difference between (old) spec_name and connection_specification_name

Active Recordのdocの修正です。

dataase configのnameなのか、connectionのname(connection_specification_name)なのかの説明を追加・修正しています。


Tweak contributing_to_ruby_on_rails.md [ci skip]

rails guideのContributing to Ruby on Railsの修正です。

exampleコードから不要な$を削除、issueをfixした場合のCHANGELOGの例の適切な箇所に改行を追加、を行っています。


More less and lazy allocation for assign_attributes and _assign_attributes

activerecord/lib/active_record/attribute_assignment.rbの修正です。

assign_attributes_assign_attributesでオブジェクトの生成数を減らすようリファクタリングしています。