File tree 1 file changed +25
-0
lines changed
1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -1309,6 +1309,31 @@ class AddFkArticlesToAuthors < ActiveRecord::Migration
1309
1309
end
1310
1310
----
1311
1311
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
+
1312
1337
=== Reversible Migration [[reversible-migration]]
1313
1338
1314
1339
Don't use non-reversible migration commands in the `change` method.
You can’t perform that action at this time.
0 commit comments