3 class TileNodes < ActiveRecord::Migration[4.2]
4 class Node < ActiveRecord::Base
5 self.table_name = "current_nodes"
8 class OldNode < ActiveRecord::Base
9 self.table_name = "nodes"
12 def self.upgrade_table(from_table, to_table, model)
13 if ENV["USE_DB_FUNCTIONS"]
15 INSERT INTO #{to_table} (id, latitude, longitude, user_id, visible, tags, timestamp, tile)
16 SELECT id, ROUND(latitude * 10000000), ROUND(longitude * 10000000),
17 user_id, visible, tags, timestamp,
18 tile_for_point(CAST(ROUND(latitude * 10000000) AS INTEGER),
19 CAST(ROUND(longitude * 10000000) AS INTEGER))
24 INSERT INTO #{to_table} (id, latitude, longitude, user_id, visible, tags, timestamp, tile)
25 SELECT id, ROUND(latitude * 10000000), ROUND(longitude * 10000000),
26 user_id, visible, tags, timestamp, 0
30 model.all.each(&:save!)
34 def self.downgrade_table(from_table, to_table)
36 INSERT INTO #{to_table} (id, latitude, longitude, user_id, visible, tags, timestamp)
37 SELECT id, latitude / 10000000, longitude / 10000000,
38 user_id, visible, tags, timestamp
44 remove_index "current_nodes", :name => "current_nodes_timestamp_idx"
46 rename_table "current_nodes", "current_nodes_v5"
48 create_table "current_nodes", :id => false do |t|
49 t.column "id", :bigserial, :primary_key => true, :null => false
50 t.column "latitude", :integer, :null => false
51 t.column "longitude", :integer, :null => false
52 t.column "user_id", :bigint, :null => false
53 t.column "visible", :boolean, :null => false
54 t.column "tags", :text, :default => "", :null => false
55 t.column "timestamp", :datetime, :null => false
56 t.column "tile", :integer, :null => false
59 add_index "current_nodes", ["timestamp"], :name => "current_nodes_timestamp_idx"
60 add_index "current_nodes", ["tile"], :name => "current_nodes_tile_idx"
62 change_column "current_nodes", "tile", :bigint
64 upgrade_table "current_nodes_v5", "current_nodes", Node
66 drop_table "current_nodes_v5"
68 remove_index "nodes", :name => "nodes_uid_idx"
69 remove_index "nodes", :name => "nodes_timestamp_idx"
70 rename_table "nodes", "nodes_v5"
72 create_table "nodes", :id => false do |t|
73 t.column "id", :bigint, :null => false
74 t.column "latitude", :integer, :null => false
75 t.column "longitude", :integer, :null => false
76 t.column "user_id", :bigint, :null => false
77 t.column "visible", :boolean, :null => false
78 t.column "tags", :text, :default => "", :null => false
79 t.column "timestamp", :datetime, :null => false
80 t.column "tile", :integer, :null => false
83 add_index "nodes", ["id"], :name => "nodes_uid_idx"
84 add_index "nodes", ["timestamp"], :name => "nodes_timestamp_idx"
85 add_index "nodes", ["tile"], :name => "nodes_tile_idx"
87 change_column "nodes", "tile", :bigint
89 upgrade_table "nodes_v5", "nodes", OldNode
95 rename_table "current_nodes", "current_nodes_v6"
97 create_table "current_nodes", :id => false do |t|
98 t.column "id", :bigserial, :primary_key => true, :null => false
99 t.column "latitude", :float, :limit => 53, :null => false
100 t.column "longitude", :float, :limit => 53, :null => false
101 t.column "user_id", :bigint, :null => false
102 t.column "visible", :boolean, :null => false
103 t.column "tags", :text, :default => "", :null => false
104 t.column "timestamp", :datetime, :null => false
107 add_index "current_nodes", %w[latitude longitude], :name => "current_nodes_lat_lon_idx"
108 add_index "current_nodes", ["timestamp"], :name => "current_nodes_timestamp_idx"
110 downgrade_table "current_nodes_v6", "current_nodes"
112 drop_table "current_nodes_v6"
114 rename_table "nodes", "nodes_v6"
116 create_table "nodes", :id => false do |t|
117 t.column "id", :bigint, :null => false
118 t.column "latitude", :float, :limit => 53, :null => false
119 t.column "longitude", :float, :limit => 53, :null => false
120 t.column "user_id", :bigint, :null => false
121 t.column "visible", :boolean, :null => false
122 t.column "tags", :text, :default => "", :null => false
123 t.column "timestamp", :datetime, :null => false
126 add_index "nodes", ["id"], :name => "nodes_uid_idx"
127 add_index "nodes", %w[latitude longitude], :name => "nodes_latlon_idx"
128 add_index "nodes", ["timestamp"], :name => "nodes_timestamp_idx"
130 downgrade_table "nodes_v6", "nodes"
132 drop_table "nodes_v6"