3 class TileNodes < ActiveRecord::Migration
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
28 def self.downgrade_table(from_table, to_table)
30 INSERT INTO #{to_table} (id, latitude, longitude, user_id, visible, tags, timestamp)
31 SELECT id, latitude / 10000000, longitude / 10000000,
32 user_id, visible, tags, timestamp
38 remove_index "current_nodes", :name => "current_nodes_timestamp_idx"
40 rename_table "current_nodes", "current_nodes_v5"
42 create_table "current_nodes", :id => false do |t|
43 t.column "id", :bigserial, :primary_key => true, :null => false
44 t.column "latitude", :integer, :null => false
45 t.column "longitude", :integer, :null => false
46 t.column "user_id", :bigint, :null => false
47 t.column "visible", :boolean, :null => false
48 t.column "tags", :text, :default => "", :null => false
49 t.column "timestamp", :datetime, :null => false
50 t.column "tile", :integer, :null => false
53 add_index "current_nodes", ["timestamp"], :name => "current_nodes_timestamp_idx"
54 add_index "current_nodes", ["tile"], :name => "current_nodes_tile_idx"
56 change_column "current_nodes", "tile", :bigint
58 upgrade_table "current_nodes_v5", "current_nodes", Node
60 drop_table "current_nodes_v5"
62 remove_index "nodes", :name=> "nodes_uid_idx"
63 remove_index "nodes", :name=> "nodes_timestamp_idx"
64 rename_table "nodes", "nodes_v5"
66 create_table "nodes", :id => false do |t|
67 t.column "id", :bigint, :null => false
68 t.column "latitude", :integer, :null => false
69 t.column "longitude", :integer, :null => false
70 t.column "user_id", :bigint, :null => false
71 t.column "visible", :boolean, :null => false
72 t.column "tags", :text, :default => "", :null => false
73 t.column "timestamp", :datetime, :null => false
74 t.column "tile", :integer, :null => false
77 add_index "nodes", ["id"], :name => "nodes_uid_idx"
78 add_index "nodes", ["timestamp"], :name => "nodes_timestamp_idx"
79 add_index "nodes", ["tile"], :name => "nodes_tile_idx"
81 change_column "nodes", "tile", :bigint
83 upgrade_table "nodes_v5", "nodes", OldNode
89 rename_table "current_nodes", "current_nodes_v6"
91 create_table "current_nodes", :id => false do |t|
92 t.column "id", :bigserial, :primary_key => true, :null => false
93 t.column "latitude", :float, :limit => 53, :null => false
94 t.column "longitude", :float, :limit => 53, :null => false
95 t.column "user_id", :bigint, :null => false
96 t.column "visible", :boolean, :null => false
97 t.column "tags", :text, :default => "", :null => false
98 t.column "timestamp", :datetime, :null => false
101 add_index "current_nodes", ["latitude", "longitude"], :name => "current_nodes_lat_lon_idx"
102 add_index "current_nodes", ["timestamp"], :name => "current_nodes_timestamp_idx"
104 downgrade_table "current_nodes_v6", "current_nodes"
106 drop_table "current_nodes_v6"
108 rename_table "nodes", "nodes_v6"
110 create_table "nodes", :id => false do |t|
111 t.column "id", :bigint, :null => false
112 t.column "latitude", :float, :limit => 53, :null => false
113 t.column "longitude", :float, :limit => 53, :null => false
114 t.column "user_id", :bigint, :null => false
115 t.column "visible", :boolean, :null => false
116 t.column "tags", :text, :default => "", :null => false
117 t.column "timestamp", :datetime, :null => false
120 add_index "nodes", ["id"], :name => "nodes_uid_idx"
121 add_index "nodes", ["latitude", "longitude"], :name => "nodes_latlon_idx"
122 add_index "nodes", ["timestamp"], :name => "nodes_timestamp_idx"
124 downgrade_table "nodes_v6", "nodes"
126 drop_table "nodes_v6"