1 class AddEndTimeToChangesets < ActiveRecord::Migration[4.2]
3 # swap the boolean closed-or-not for a time when the changeset will
5 add_column(:changesets, :closed_at, :datetime, :null => false)
7 # it appears that execute will only accept string arguments, so
8 # this is an ugly, ugly hack to get some sort of mysql/postgres
9 # independence. now i have to go wash my brain with bleach.
10 execute("update changesets set closed_at=(now()-'1 hour'::interval) where open=(1=0)")
11 execute("update changesets set closed_at=(now()+'1 hour'::interval) where open=(1=1)")
13 # remove the open column as it is unnecessary now and denormalises
15 remove_column :changesets, :open
17 # add a column to keep track of the number of changes in a changeset.
18 # could probably work out how many changes there are here, but i'm not
19 # sure its actually important.
20 add_column(:changesets, :num_changes, :integer,
21 :null => false, :default => 0)
25 # in the reverse direction, we can look at the closed_at to figure out
26 # if changesets are closed or not.
27 add_column(:changesets, :open, :boolean, :null => false, :default => true)
28 execute("update changesets set open=(closed_at > now())")
29 remove_column :changesets, :closed_at
31 # remove the column for tracking number of changes
32 remove_column :changesets, :num_changes