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