1 class TileNodes < ActiveRecord::Migration
2 def self.upgrade_table(from_table, to_table, model)
5 INSERT INTO #{to_table} (id, latitude, longitude, user_id, visible, tags, timestamp, tile)
6 SELECT id, ROUND(latitude * 10000000), ROUND(longitude * 10000000),
7 user_id, visible, tags, timestamp,
8 tile_for_point(CAST(ROUND(latitude * 10000000) AS UNSIGNED),
9 CAST(ROUND(longitude * 10000000) AS UNSIGNED))
12 rescue ActiveRecord::StatementInvalid => ex
14 INSERT INTO #{to_table} (id, latitude, longitude, user_id, visible, tags, timestamp, tile)
15 SELECT id, ROUND(latitude * 10000000), ROUND(longitude * 10000000),
16 user_id, visible, tags, timestamp, 0
20 model.find(:all).each do |n|
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 rename_table "current_nodes", "current_nodes_v5"
38 create_table "current_nodes", innodb_table do |t|
39 t.column "id", :bigint, :limit => 64, :null => false
40 t.column "latitude", :integer, :null => false
41 t.column "longitude", :integer, :null => false
42 t.column "user_id", :bigint, :limit => 20, :null => false
43 t.column "visible", :boolean, :null => false
44 t.column "tags", :text, :default => "", :null => false
45 t.column "timestamp", :datetime, :null => false
46 t.column "tile", :integer, :null => false
49 add_primary_key "current_nodes", ["id"]
50 add_index "current_nodes", ["timestamp"], :name => "current_nodes_timestamp_idx"
51 add_index "current_nodes", ["tile"], :name => "current_nodes_tile_idx"
53 change_column "current_nodes", "id", :bigint, :limit => 64, :null => false, :options => "AUTO_INCREMENT"
54 change_column "current_nodes", "tile", :integer, :null => false, :unsigned => true
56 upgrade_table "current_nodes_v5", "current_nodes", Node
58 drop_table "current_nodes_v5"
60 rename_table "nodes", "nodes_v5"
62 create_table "nodes", myisam_table do |t|
63 t.column "id", :bigint, :limit => 64, :null => false
64 t.column "latitude", :integer, :null => false
65 t.column "longitude", :integer, :null => false
66 t.column "user_id", :bigint, :limit => 20, :null => false
67 t.column "visible", :boolean, :null => false
68 t.column "tags", :text, :default => "", :null => false
69 t.column "timestamp", :datetime, :null => false
70 t.column "tile", :integer, :null => false
73 add_index "nodes", ["id"], :name => "nodes_uid_idx"
74 add_index "nodes", ["timestamp"], :name => "nodes_timestamp_idx"
75 add_index "nodes", ["tile"], :name => "nodes_tile_idx"
77 change_column "nodes", "tile", :integer, :null => false, :unsigned => true
79 upgrade_table "nodes_v5", "nodes", OldNode
85 rename_table "current_nodes", "current_nodes_v6"
87 create_table "current_nodes", innodb_table do |t|
88 t.column "id", :bigint, :limit => 64, :null => false
89 t.column "latitude", :double, :null => false
90 t.column "longitude", :double, :null => false
91 t.column "user_id", :bigint, :limit => 20, :null => false
92 t.column "visible", :boolean, :null => false
93 t.column "tags", :text, :default => "", :null => false
94 t.column "timestamp", :datetime, :null => false
97 add_primary_key "current_nodes", ["id"]
98 add_index "current_nodes", ["latitude", "longitude"], :name => "current_nodes_lat_lon_idx"
99 add_index "current_nodes", ["timestamp"], :name => "current_nodes_timestamp_idx"
101 change_column "current_nodes", "id", :bigint, :limit => 64, :null => false, :options => "AUTO_INCREMENT"
103 downgrade_table "current_nodes_v6", "current_nodes"
105 drop_table "current_nodes_v6"
107 rename_table "nodes", "nodes_v6"
109 create_table "nodes", myisam_table do |t|
110 t.column "id", :bigint, :limit => 64, :null => false
111 t.column "latitude", :double, :null => false
112 t.column "longitude", :double, :null => false
113 t.column "user_id", :bigint, :limit => 20, :null => false
114 t.column "visible", :boolean, :null => false
115 t.column "tags", :text, :default => "", :null => false
116 t.column "timestamp", :datetime, :null => false
119 add_index "nodes", ["id"], :name => "nodes_uid_idx"
120 add_index "nodes", ["latitude", "longitude"], :name => "nodes_latlon_idx"
121 add_index "nodes", ["timestamp"], :name => "nodes_timestamp_idx"
123 downgrade_table "nodes_v6", "nodes"
125 drop_table "nodes_v6"