]> git.openstreetmap.org Git - rails.git/blob - db/migrate/023_add_changesets.rb
pass common API error text through to Potlatch so it can be shown to the user
[rails.git] / db / migrate / 023_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_pk,              :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     create_table "changeset_tags", innodb_table do |t|
18       t.column "id", :bigint, :limit => 64, :null => false
19       t.column "k",  :string, :default => "", :null => false
20       t.column "v",  :string, :default => "", :null => false
21     end
22
23     add_index "changeset_tags", ["id"], :name => "changeset_tags_id_idx"
24     
25     #
26     # Initially we will have one changeset for every user containing 
27     # all edits up to the API change,  
28     # all the changesets will have the id of the user that made them.
29     # We need to generate a changeset for each user in the database
30     execute "INSERT INTO changesets (id, user_id, created_at, open)" + 
31       "SELECT id, id, creation_time, false from users;"
32
33     @@conv_user_tables.each { |tbl|
34       rename_column tbl, :user_id, :changeset_id
35       #foreign keys too
36       add_foreign_key tbl, [:changeset_id], :changesets, [:id]
37     }
38   end
39
40   def self.down
41     # It's not easy to generate the user ids from the changesets
42     raise IrreversibleMigration.new
43     #drop_table "changesets"
44     #drop_table "changeset_tags"
45   end
46 end