3 class AddChangesets < ActiveRecord::Migration
4 @@conv_user_tables = ['current_nodes',
5 'current_relations', 'current_ways', 'nodes', 'relations', 'ways' ]
8 create_table "changesets", innodb_table do |t|
9 t.column "id", :bigint_pk, :null => false
10 t.column "user_id", :bigint, :limit => 20, :null => false
11 t.column "created_at", :datetime, :null => false
12 t.column "open", :boolean, :null => false, :default => true
13 t.column "min_lat", :integer, :null => true
14 t.column "max_lat", :integer, :null => true
15 t.column "min_lon", :integer, :null => true
16 t.column "max_lon", :integer, :null => true
19 create_table "changeset_tags", innodb_table do |t|
20 t.column "id", :bigint, :limit => 64, :null => false
21 t.column "k", :string, :default => "", :null => false
22 t.column "v", :string, :default => "", :null => false
25 add_index "changeset_tags", ["id"], :name => "changeset_tags_id_idx"
28 # Initially we will have one changeset for every user containing
29 # all edits up to the API change,
30 # all the changesets will have the id of the user that made them.
31 # We need to generate a changeset for each user in the database
32 execute "INSERT INTO changesets (id, user_id, created_at, open)" +
33 "SELECT id, id, creation_time, false from users;"
35 @@conv_user_tables.each { |tbl|
36 rename_column tbl, :user_id, :changeset_id
38 add_foreign_key tbl, [:changeset_id], :changesets, [:id]
43 # It's not easy to generate the user ids from the changesets
44 raise ActiveRecord::IrreversibleMigration
45 #drop_table "changesets"
46 #drop_table "changeset_tags"