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 remove_index "current_nodes", :name => "current_nodes_timestamp_idx"
38 rename_table "current_nodes", "current_nodes_v5"
40 create_table "current_nodes", innodb_table do |t|
41 t.column "id", :bigint_pk_64, :null => false
42 t.column "latitude", :integer, :null => false
43 t.column "longitude", :integer, :null => false
44 t.column "user_id", :bigint, :limit => 20, :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", :four_byte_unsigned
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", myisam_table do |t|
65 t.column "id", :bigint, :limit => 64, :null => false
66 t.column "latitude", :integer, :null => false
67 t.column "longitude", :integer, :null => false
68 t.column "user_id", :bigint, :limit => 20, :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", :four_byte_unsigned
81 upgrade_table "nodes_v5", "nodes", OldNode
87 rename_table "current_nodes", "current_nodes_v6"
89 create_table "current_nodes", innodb_table do |t|
90 t.column "id", :bigint_pk_64, :null => false
91 t.column "latitude", :double, :null => false
92 t.column "longitude", :double, :null => false
93 t.column "user_id", :bigint, :limit => 20, :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", ["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", myisam_table do |t|
109 t.column "id", :bigint, :limit => 64, :null => false
110 t.column "latitude", :double, :null => false
111 t.column "longitude", :double, :null => false
112 t.column "user_id", :bigint, :limit => 20, :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", ["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"