From e4b20efd04c95b65935caea0c6d15c9a9bb5661a Mon Sep 17 00:00:00 2001 From: rgarcia Date: Wed, 13 Dec 2017 12:24:08 +0100 Subject: [PATCH 1/2] adds timestamps to polls --- db/migrate/20171212193323_add_timestamps_to_polls.rb | 5 +++++ db/schema.rb | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20171212193323_add_timestamps_to_polls.rb diff --git a/db/migrate/20171212193323_add_timestamps_to_polls.rb b/db/migrate/20171212193323_add_timestamps_to_polls.rb new file mode 100644 index 000000000..9c955b278 --- /dev/null +++ b/db/migrate/20171212193323_add_timestamps_to_polls.rb @@ -0,0 +1,5 @@ +class AddTimestampsToPolls < ActiveRecord::Migration + def change + add_timestamps :polls, null: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 4d426cf9e..b9bfe1c21 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20171127230716) do +ActiveRecord::Schema.define(version: 20171212193323) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -798,6 +798,8 @@ ActiveRecord::Schema.define(version: 20171127230716) do t.datetime "hidden_at" t.boolean "results_enabled", default: false t.boolean "stats_enabled", default: false + t.datetime "created_at" + t.datetime "updated_at" end add_index "polls", ["starts_at", "ends_at"], name: "index_polls_on_starts_at_and_ends_at", using: :btree From a6a71c996a55a76ced1c3982479f431877a343e3 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Wed, 13 Dec 2017 19:39:54 +0100 Subject: [PATCH 2/2] adds rake task to initialise all polls' timestamps --- lib/tasks/polls.rake | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 lib/tasks/polls.rake diff --git a/lib/tasks/polls.rake b/lib/tasks/polls.rake new file mode 100644 index 000000000..cf10afffd --- /dev/null +++ b/lib/tasks/polls.rake @@ -0,0 +1,6 @@ +namespace :polls do + desc "Adds created_at and updated_at values to existing polls" + task initialize_timestamps: :environment do + Poll.update_all(created_at: Time.current, updated_at: Time.current) + end +end