From ed1503eff6a94b745c1f11bf4cc223c906d56823 Mon Sep 17 00:00:00 2001 From: Luke Baker Date: Wed, 7 Mar 2012 12:31:01 -0500 Subject: [PATCH] add find ambiguous times task --- lib/tasks/prune_db.rake | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+), 0 deletions(-) diff --git a/lib/tasks/prune_db.rake b/lib/tasks/prune_db.rake index 600b6fd..4f9b1c1 100644 --- a/lib/tasks/prune_db.rake +++ b/lib/tasks/prune_db.rake @@ -1,5 +1,31 @@ namespace :prune_db do + desc "Finds ambiguous times due to daylight savings time" + task :find_ambiguous_times => :environment do + datetime_fields = { + :appearances => ['created_at', 'updated_at'], + :choices => ['created_at', 'updated_at'], + :clicks => ['created_at', 'updated_at'], + :densities => ['created_at', 'updated_at'], + :flags => ['created_at', 'updated_at'], + :prompts => ['created_at', 'updated_at'], + :skips => ['created_at', 'updated_at'], + :votes => ['created_at', 'updated_at'], + :visitors => ['created_at', 'updated_at'], + :users => ['created_at', 'updated_at'], + :questions => ['created_at', 'updated_at'], + :question_versions => ['created_at', 'updated_at'], + :delayed_jobs => ['created_at', 'updated_at', 'run_at', 'locked_at', 'failed_at'], + } + datetime_fields.each do |table, columns| + where = columns.map{|c| "((#{c} > '2010-11-07 00:59:59' AND #{c} < '2010-11-07 02:00:00') OR (#{c} > '2011-11-06 00:59:59' AND #{c} < '2011-11-06 02:00:00'))"}.join(" OR ") + rows = ActiveRecord::Base.connection.select_all( + "SELECT id, #{columns.join(", ")} FROM #{table} WHERE #{where}" + ) + puts rows.inspect if rows.length > 0 + end + end + desc "Converts all dates from PT to UTC" task :convert_dates_to_utc => :environment do time_spans = [ -- libgit2 0.21.2