]> git.openstreetmap.org Git - rails.git/blob - db/migrate/005_tile_tracepoints.rb
Merge remote-tracking branch 'upstream/pull/4999'
[rails.git] / db / migrate / 005_tile_tracepoints.rb
1 class TileTracepoints < ActiveRecord::Migration[4.2]
2   class Tracepoint < ApplicationRecord
3     self.table_name = "gps_points"
4   end
5
6   def self.up
7     add_column "gps_points", "tile", :bigint
8     add_index "gps_points", ["tile"], :name => "points_tile_idx"
9     remove_index "gps_points", :name => "points_idx"
10
11     Tracepoint.all.each do |tp|
12       tp.latitude = tp.latitude * 10
13       tp.longitude = tp.longitude * 10
14       tp.save!
15     end
16   end
17
18   def self.down
19     Tracepoint.update_all("latitude = latitude / 10, longitude = longitude / 10")
20
21     add_index "gps_points", %w[latitude longitude], :name => "points_idx"
22     remove_index "gps_points", :name => "points_tile_idx"
23     remove_column "gps_points", "tile"
24   end
25 end