1 class AddChangesets < ActiveRecord::Migration[4.2]
2 @conv_user_tables = %w[current_nodes current_relations current_ways nodes relations ways]
5 create_table "changesets", :id => false do |t|
6 t.column "id", :bigserial, :primary_key => true, :null => false
7 t.column "user_id", :bigint, :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
16 create_table "changeset_tags", :id => false do |t|
17 t.column "id", :bigint, :null => false
18 t.column "k", :string, :default => "", :null => false
19 t.column "v", :string, :default => "", :null => false
22 add_index "changeset_tags", ["id"], :name => "changeset_tags_id_idx"
25 # Initially we will have one changeset for every user containing
26 # all edits up to the API change,
27 # all the changesets will have the id of the user that made them.
28 # We need to generate a changeset for each user in the database
29 execute "INSERT INTO changesets (id, user_id, created_at, open)" \
30 "SELECT id, id, creation_time, false from users;"
32 @conv_user_tables.each do |tbl|
33 rename_column tbl, :user_id, :changeset_id
35 add_foreign_key tbl, :changesets, :name => "#{tbl}_changeset_id_fkey"
40 # It's not easy to generate the user ids from the changesets
41 raise ActiveRecord::IrreversibleMigration
42 # drop_table "changesets"
43 # drop_table "changeset_tags"