なるようになるブログ

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

rails commit log流し読み(2016/04/17)

2016/04/17分のコミットです。

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

activerecord/CHANGELOG.md


[ci skip] docs for add_references index option

activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rbのdoc及び guides/source/active_record_migrations.mdの修正です。

add_referenceメソッドindexオプションを指定した場合のexampleを追加、及びActive Record Migrations guideのCreating a Migrationの項に http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/SchemaStatements.html#method-i-add_reference へのリンクを追加しています。


Merge pull request #24574 from y-yagi/donot_remove_cable.js

actioncable/lib/rails/generators/channel/channel_generator.rbの修正です。

Action Cableのchannel generatorで、destroyアクション実行時にapp/assets/javascripts/cable.jsを削除しないよう修正しています。

app/assets/javascripts/cable.jsは他のchannelでも使用されるファイルの為。


Merge pull request #22911 from Envek/database_comments

Active Recordの修正です。

database objects(tables, columns, indexes)にコメントを指定出来るよう対応しています。

以下PostgreSQLの場合の例。

create_table :pages, force: :cascade, comment: 'CMS content pages' do |t|
  t.string :path,   comment: 'Path fragment of page URL used for routing'
  t.string :locale, comment: 'RFC 3066 locale code of website language section'
  t.index [:path, :locale], comment: 'Look up pages by URI'

  t.timestamps
end

上記migrationを実行した場合。

master_postgresql_development=# \d+
                                  List of relations
 Schema |         Name         |   Type   |  Owner   |    Size    |    Description
--------+----------------------+----------+----------+------------+-------------------
 public | ar_internal_metadata | table    | yaginuma | 16 kB      |
 public | pages                | table    | yaginuma | 8192 bytes | CMS content pages
 public | pages_id_seq         | sequence | yaginuma | 8192 bytes |
 public | schema_migrations    | table    | yaginuma | 16 kB      |


master_postgresql_development=# \d+ pages
                                                                            Table "public.pages"
   Column   |            Type             |                     Modifiers                      | Storage  | Stats target |                   Description
------------+-----------------------------+----------------------------------------------------+----------+--------------+--------------------------------------------------
 id         | integer                     | not null default nextval('pages_id_seq'::regclass) | plain    |              |
 path       | character varying           |                                                    | extended |              | Path fragment of page URL used for routing
 locale     | character varying           |                                                    | extended |              | RFC 3066 locale code of website language section
 created_at | timestamp without time zone | not null                                           | plain    |              |
 updated_at | timestamp without time zone | not null                                           | plain    |              |
Indexes:
    "pages_pkey" PRIMARY KEY, btree (id)
    "index_pages_on_path_and_locale" btree (path, locale)

master_postgresql_development=# SELECT distinct i.relname, d.indisunique, d.indkey, pg_get_indexdef(d.indexrelid), t.oid, pg_catalog.obj_description(i.oid, 'pg_class') AS comment FROM pg_class t
master_postgresql_development-# INNER JOIN pg_index d ON t.oid = d.indrelid
master_postgresql_development-# INNER JOIN pg_class i ON d.indexrelid = i.oid
master_postgresql_development-# LEFT JOIN pg_namespace n ON n.oid = i.relnamespace
master_postgresql_development-# WHERE i.relkind = 'i'   AND d.indisprimary = 'f' AND t.relname = 'pages';
            relname             | indisunique | indkey |                                 pg_get_indexdef                                 |  oid   |       comment
--------------------------------+-------------+--------+---------------------------------------------------------------------------------+--------+----------------------
 index_pages_on_path_and_locale | f           | 2 3    | CREATE INDEX index_pages_on_path_and_locale ON pages USING btree (path, locale) | 804578 | Look up pages by URI
(1 row)

おお、ちゃんと指定した値が入ってますね。

なお、現状サポートしているDBはMySQLPostgreSQLのみです。


Stop passing unused payloads to instrumentation block in cache

activesupport/lib/active_support/cache.rbの修正です。

#instrumentメソッドを使用している箇所から、使用していないpayload変数を削除しています。


Add render allows unicode text name in partials - 🍣

actionview/test/template/render_test.rbの修正です。

partial templateのテンプレート名にunicode textを使用出来る事を確認する為のテストを追加しています。