]> git.openstreetmap.org Git - rails.git/blob - db/migrate/025_add_end_time_to_changesets.rb
Index oauth_tokens and client_applications by user_id
[rails.git] / db / migrate / 025_add_end_time_to_changesets.rb
1 require "migrate"
2
3 class AddEndTimeToChangesets < ActiveRecord::Migration
4   def self.up
5     # swap the boolean closed-or-not for a time when the changeset will
6     # close or has closed.
7     add_column(:changesets, :closed_at, :datetime, :null => false)
8
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)")
14
15     # remove the open column as it is unnecessary now and denormalises
16     # the table.
17     remove_column :changesets, :open
18
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)
24   end
25
26   def self.down
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
32
33     # remove the column for tracking number of changes
34     remove_column :changesets, :num_changes
35   end
36 end