Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add suggestions for date-related columns #364

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 the name without referring to the database 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