Skip to content

Commit

Permalink
Add suggestions for date-related columns
Browse files Browse the repository at this point in the history
  • Loading branch information
fatkodima committed Feb 15, 2025
1 parent b077bc2 commit 72d815a
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1309,6 +1309,31 @@ class AddFkArticlesToAuthors < ActiveRecord::Migration
end
----

=== Date and Time Columns Naming [[date-and-time-columns-naming]]

Name `date` columns with `_on` suffixes.
Name `datetime` columns with `_at` suffixes.
Name `time` columns (referring to a time of day with no date) with `_time` suffixes.

This enforces consistency and it is easier to tell the type from name without referring to db schema.

[source,ruby]
----
# bad
class AddLastActivityToUsers < ActiveRecord::Migration
def change
add_column :users, :last_activity_at, :date
end
end
# good
class AddLastActivityToUsers < ActiveRecord::Migration
def change
add_column :users, :last_activity_on, :date
end
end
----

=== Reversible Migration [[reversible-migration]]

Don't use non-reversible migration commands in the `change` method.
Expand Down

0 comments on commit 72d815a

Please sign in to comment.