Skip to content

Commit 90ff2ce

Browse files
committed
Add suggestions for date-related columns
1 parent b077bc2 commit 90ff2ce

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

README.adoc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,6 +1309,31 @@ class AddFkArticlesToAuthors < ActiveRecord::Migration
13091309
end
13101310
----
13111311

1312+
=== Date and Time Columns Naming [[date-and-time-columns-naming]]
1313+
1314+
Name `date` columns with `_on` suffixes.
1315+
Name `datetime` columns with `_at` suffixes.
1316+
Name `time` columns (referring to a time of day with no date) with `_time` suffixes.
1317+
1318+
This enforces consistency and it is easier to tell the type from the name without referring to the database schema.
1319+
1320+
[source,ruby]
1321+
----
1322+
# bad
1323+
class AddLastActivityToUsers < ActiveRecord::Migration
1324+
def change
1325+
add_column :users, :last_activity_at, :date
1326+
end
1327+
end
1328+
1329+
# good
1330+
class AddLastActivityToUsers < ActiveRecord::Migration
1331+
def change
1332+
add_column :users, :last_activity_on, :date
1333+
end
1334+
end
1335+
----
1336+
13121337
=== Reversible Migration [[reversible-migration]]
13131338

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

0 commit comments

Comments
 (0)