Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pixeltrix/b197fa5d0bed86a9c5b9ac99ed43bfc0 to your computer and use it in GitHub Desktop.
Save pixeltrix/b197fa5d0bed86a9c5b9ac99ed43bfc0 to your computer and use it in GitHub Desktop.
Migration to add timestamps easily to a bunch of tables
class AddTimestampsEverywhere < ActiveRecord::Migration[5.1]
def change
now = Time.current
%i[
candidates
evaluations
interviewers
questions
responses
stages
workflows
].each do |table|
change_table table do |t|
t.timestamps null: true
end
klass = Class.new(ActiveRecord::Base) do
self.table_name = table
end
klass.update_all(created_at: now, updated_at: now)
change_column_null(table, :created_at, false)
change_column_null(table, :updated_at, false)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment