]> git.openstreetmap.org Git - rails.git/blob - db/migrate/025_add_end_time_to_changesets.rb
Fixed problem with Time vs. DateTime classes in fixtures. Weirdly only affected mysql...
[rails.git] / db / migrate / 025_add_end_time_to_changesets.rb
1 class AddEndTimeToChangesets < ActiveRecord::Migration
2   def self.up
3     # swap the boolean closed-or-not for a time when the changeset will
4     # close or has closed.
5     add_column(:changesets, :closed_at, :datetime, :null => false)
6     
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()-#{interval_constant('1 hour')}) where open=(1=0)")
11     execute("update changesets set closed_at=(now()+#{interval_constant('1 hour')}) where open=(1=1)")
12
13     # remove the open column as it is unnecessary now and denormalises 
14     # the table.
15     remove_column :changesets, :open
16
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)
22   end
23
24   def self.down
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
30
31     # remove the column for tracking number of changes
32     remove_column :changesets, :num_changes
33   end
34 end