Add Timestamps to Existing Tables in Rails
1.6.2018
Have you ever gotten deep into a Rails project before realizing that you forgot to add timestamps to some (or all) of your tables? Yes, me too. We all have. Adding them to a few tables is not so bad, but if you have a huge schema file, doing all the digging and column adding can be a pain.
I wrote a short & sweet database migration that will find all tables lacking created_at
and/or updated_at
, and add those accordingly.
You can check out the gist here.
I originally thought about turning this into gem, but that's probably overkill. One caveat is that this doesn't include null: false
. I ran into errors when adding that (specifically on schema_migrations
), so if you wanted to add the null
option, you may have to skip that table.
Other Posts
The Best Projects Can Be Done in a Weekend
Everyone Has Something To Offer
Book Thoughts: Capital and Ideology
Naive Diffie-Hellman Implementation in Ruby
When Does the Magic Comment Work, and When Does it Not?
Benchmarking Arrays Full of Nils
Go, and When It's Okay to Learn New Things
Grouping Records by Month with Ruby
The Busy and (Somewhat) Fit Developer
TuxedoCSS and the Rails Asset Pipeline
Gem You Should Know About: auto_html
Querying for Today's Date with ActiveRecord