source: subversion/sites/rails_port_branches/api06/db/migrate/025_add_end_time_to_changesets.rb @ 14011

Revision 14011, 1.4 KB checked in by tomhughes, 5 years ago (diff)

Merge 12304:14009 from trunk.

Line 
1class 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()-'1 hour') where open=(1=0)")
11    execute("update changesets set closed_at=(now()+'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
34end
Note: See TracBrowser for help on using the repository browser.