From b8610614a08c4e506b5530e1850cc2ff003ff8c8 Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Sun, 3 Oct 2021 04:35:01 +0900 Subject: [PATCH] Make `Rails/CreateTableWithTimestamps` respect `active_storage_variant_records` table This PR makes `Rails/CreateTableWithTimestamps` respect `active_storage_variant_records` table of `db/migrate/*_create_active_storage_tables.active_storage.rb` auto-generated by `bin/rails active_storage:install` even if `created_at` is not specified. It suppresses the following offense. ```console % bin/rails -v Rails 6.1.4.1 % bin/rails active_storage:install Copied migration 20210929095151_create_active_storage_tables.active_storage.rb from active_storage % bundle exec rubocop --only Rails/CreateTableWithTimestamps Inspecting 1 file C Offenses: db/migrate/20210929095151_create_active_storage_tables.active_storage.rb:28:5: C: Rails/CreateTableWithTimestamps: Add timestamps when creating a new table. create_table :active_storage_variant_records do |t| ... ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 1 file inspected, 1 offense detected ``` As far as I've heard from Rails committers, `active_storage_variant_records` table hasn't timestamp columns, probably as a result of discussions in the Rails community. If you want to consider the need, please discuss it with https://discuss.rubyonrails.org and give us feedback. --- ...eate_table_with_timestamps_aware_of_ast_variant_records.md | 1 + config/default.yml | 4 ++++ docs/modules/ROOT/pages/cops_rails.adoc | 4 ++++ 3 files changed, 9 insertions(+) create mode 100644 changelog/change_make_create_table_with_timestamps_aware_of_ast_variant_records.md diff --git a/changelog/change_make_create_table_with_timestamps_aware_of_ast_variant_records.md b/changelog/change_make_create_table_with_timestamps_aware_of_ast_variant_records.md new file mode 100644 index 0000000000..5f7ce322d8 --- /dev/null +++ b/changelog/change_make_create_table_with_timestamps_aware_of_ast_variant_records.md @@ -0,0 +1 @@ +* [#570](https://github.com/rubocop/rubocop-rails/pull/570): Make `Rails/CreateTableWithTimestamps` respect `active_storage_variant_records` table of `db/migrate/*_create_active_storage_tables.active_storage.rb` auto-generated by `bin/rails active_storage:install` even if `created_at` is not specified. ([@koic][]) diff --git a/config/default.yml b/config/default.yml index 13f3454afb..b20840459e 100644 --- a/config/default.yml +++ b/config/default.yml @@ -201,6 +201,10 @@ Rails/CreateTableWithTimestamps: VersionAdded: '0.52' Include: - db/migrate/*.rb + Exclude: + # Respect the `active_storage_variant_records` table of `*_create_active_storage_tables.active_storage.rb` + # auto-generated by `bin/rails active_storage:install` even if `created_at` is not specified. + - db/migrate/*_create_active_storage_tables.active_storage.rb Rails/Date: Description: >- diff --git a/docs/modules/ROOT/pages/cops_rails.adoc b/docs/modules/ROOT/pages/cops_rails.adoc index dd0765a1da..26b0448e0a 100644 --- a/docs/modules/ROOT/pages/cops_rails.adoc +++ b/docs/modules/ROOT/pages/cops_rails.adoc @@ -923,6 +923,10 @@ end | Include | `db/migrate/*.rb` | Array + +| Exclude +| `db/migrate/*_create_active_storage_tables.active_storage.rb` +| Array |=== == Rails/Date