3 class TileNodes < ActiveRecord::Migration[4.2]
4 def self.upgrade_table(from_table, to_table, model)
5 if ENV["USE_DB_FUNCTIONS"]
7 INSERT INTO #{to_table} (id, latitude, longitude, user_id, visible, tags, timestamp, tile)
8 SELECT id, ROUND(latitude * 10000000), ROUND(longitude * 10000000),
9 user_id, visible, tags, timestamp,
10 tile_for_point(CAST(ROUND(latitude * 10000000) AS INTEGER),
11 CAST(ROUND(longitude * 10000000) AS INTEGER))
16 INSERT INTO #{to_table} (id, latitude, longitude, user_id, visible, tags, timestamp, tile)
17 SELECT id, ROUND(latitude * 10000000), ROUND(longitude * 10000000),
18 user_id, visible, tags, timestamp, 0
22 model.all.each(&:save!)
26 def self.downgrade_table(from_table, to_table)
28 INSERT INTO #{to_table} (id, latitude, longitude, user_id, visible, tags, timestamp)
29 SELECT id, latitude / 10000000, longitude / 10000000,
30 user_id, visible, tags, timestamp
36 remove_index "current_nodes", :name => "current_nodes_timestamp_idx"
38 rename_table "current_nodes", "current_nodes_v5"
40 create_table "current_nodes", :id => false do |t|
41 t.column "id", :bigserial, :primary_key => true, :null => false
42 t.column "latitude", :integer, :null => false
43 t.column "longitude", :integer, :null => false
44 t.column "user_id", :bigint, :null => false
45 t.column "visible", :boolean, :null => false
46 t.column "tags", :text, :default => "", :null => false
47 t.column "timestamp", :datetime, :null => false
48 t.column "tile", :integer, :null => false
51 add_index "current_nodes", ["timestamp"], :name => "current_nodes_timestamp_idx"
52 add_index "current_nodes", ["tile"], :name => "current_nodes_tile_idx"
54 change_column "current_nodes", "tile", :bigint
56 upgrade_table "current_nodes_v5", "current_nodes", Node
58 drop_table "current_nodes_v5"
60 remove_index "nodes", :name => "nodes_uid_idx"
61 remove_index "nodes", :name => "nodes_timestamp_idx"
62 rename_table "nodes", "nodes_v5"
64 create_table "nodes", :id => false do |t|
65 t.column "id", :bigint, :null => false
66 t.column "latitude", :integer, :null => false
67 t.column "longitude", :integer, :null => false
68 t.column "user_id", :bigint, :null => false
69 t.column "visible", :boolean, :null => false
70 t.column "tags", :text, :default => "", :null => false
71 t.column "timestamp", :datetime, :null => false
72 t.column "tile", :integer, :null => false
75 add_index "nodes", ["id"], :name => "nodes_uid_idx"
76 add_index "nodes", ["timestamp"], :name => "nodes_timestamp_idx"
77 add_index "nodes", ["tile"], :name => "nodes_tile_idx"
79 change_column "nodes", "tile", :bigint
81 upgrade_table "nodes_v5", "nodes", OldNode
87 rename_table "current_nodes", "current_nodes_v6"
89 create_table "current_nodes", :id => false do |t|
90 t.column "id", :bigserial, :primary_key => true, :null => false
91 t.column "latitude", :float, :limit => 53, :null => false
92 t.column "longitude", :float, :limit => 53, :null => false
93 t.column "user_id", :bigint, :null => false
94 t.column "visible", :boolean, :null => false
95 t.column "tags", :text, :default => "", :null => false
96 t.column "timestamp", :datetime, :null => false
99 add_index "current_nodes", %w[latitude longitude], :name => "current_nodes_lat_lon_idx"
100 add_index "current_nodes", ["timestamp"], :name => "current_nodes_timestamp_idx"
102 downgrade_table "current_nodes_v6", "current_nodes"
104 drop_table "current_nodes_v6"
106 rename_table "nodes", "nodes_v6"
108 create_table "nodes", :id => false do |t|
109 t.column "id", :bigint, :null => false
110 t.column "latitude", :float, :limit => 53, :null => false
111 t.column "longitude", :float, :limit => 53, :null => false
112 t.column "user_id", :bigint, :null => false
113 t.column "visible", :boolean, :null => false
114 t.column "tags", :text, :default => "", :null => false
115 t.column "timestamp", :datetime, :null => false
118 add_index "nodes", ["id"], :name => "nodes_uid_idx"
119 add_index "nodes", %w[latitude longitude], :name => "nodes_latlon_idx"
120 add_index "nodes", ["timestamp"], :name => "nodes_timestamp_idx"
122 downgrade_table "nodes_v6", "nodes"
124 drop_table "nodes_v6"