]> git.openstreetmap.org Git - rails.git/blob - db/migrate/020_add_changesets.rb
Added min_lat > max_lat test.
[rails.git] / db / migrate / 020_add_changesets.rb
1 class AddChangesets < ActiveRecord::Migration
2   @@conv_user_tables = ['current_nodes',
3   'current_relations', 'current_ways', 'nodes', 'relations', 'ways' ]
4   
5   def self.up
6     create_table "changesets", innodb_table do |t|
7       t.column "id",             :bigint,   :limit => 20, :null => false
8       t.column "user_id",        :bigint,   :limit => 20, :null => false
9       t.column "created_at",     :datetime,               :null => false
10       t.column "open",           :boolean,                :null => false, :default => true
11       t.column "min_lat",        :integer,                :null => true
12       t.column "max_lat",        :integer,                :null => true
13       t.column "min_lon",        :integer,                :null => true
14       t.column "max_lon",        :integer,                :null => true
15     end
16
17     add_primary_key "changesets", ["id"]
18     # FIXME add indexes?
19
20     change_column "changesets", "id", :bigint, :limit => 20, :null => false, :options => "AUTO_INCREMENT"
21
22     create_table "changeset_tags", innodb_table do |t|
23       t.column "id", :bigint, :limit => 64, :null => false
24       t.column "k",  :string, :default => "", :null => false
25       t.column "v",  :string, :default => "", :null => false
26     end
27
28     add_index "changeset_tags", ["id"], :name => "changeset_tags_id_idx"
29     
30     #
31     # Initially we will have one changeset for every user containing 
32     # all edits up to the API change,  
33     # all the changesets will have the id of the user that made them.
34     # We need to generate a changeset for each user in the database
35     execute "INSERT INTO changesets (id, user_id, created_at, open)" + 
36       "SELECT id, id, creation_time, 0 from users;"
37
38     @@conv_user_tables.each { |tbl|
39       rename_column tbl, :user_id, :changeset_id
40       #foreign keys too
41       add_foreign_key tbl, [:changeset_id], :changesets, [:id]
42     }
43   end
44
45   def self.down
46     # It's not easy to generate the user ids from the changesets
47     raise IrreversibleMigration.new
48     #drop_table "changesets"
49     #drop_table "changeset_tags"
50   end
51 end