1 class AddChangesets < ActiveRecord::Migration
2 @@conv_user_tables = ['current_nodes',
3 'current_relations', 'current_ways', 'nodes', 'relations', 'ways' ]
6 create_table "changesets", innodb_table do |t|
7 t.column "user_id", :bigint, :limit => 20, :null => false
8 t.column "created_at", :datetime, :null => false
9 t.column "open", :boolean, :null => false, :default => true
10 t.column "min_lat", :integer, :null => true
11 t.column "max_lat", :integer, :null => true
12 t.column "min_lon", :integer, :null => true
13 t.column "max_lon", :integer, :null => true
15 add_column :changesets, :id, :bigint_pk
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
23 add_index "changeset_tags", ["id"], :name => "changeset_tags_id_idx"
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, 0 from users;"
33 @@conv_user_tables.each { |tbl|
34 rename_column tbl, :user_id, :changeset_id
36 add_foreign_key tbl, [:changeset_id], :changesets, [:id]
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"