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