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