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_pk_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_index "current_nodes", ["timestamp"], :name => "current_nodes_timestamp_idx"
50 add_index "current_nodes", ["tile"], :name => "current_nodes_tile_idx"
52 change_column "current_nodes", "tile", :integer, :null => false, :unsigned => true
54 upgrade_table "current_nodes_v5", "current_nodes", Node
56 drop_table "current_nodes_v5"
58 rename_table "nodes", "nodes_v5"
60 create_table "nodes", myisam_table do |t|
61 t.column "id", :bigint, :limit => 64, :null => false
62 t.column "latitude", :integer, :null => false
63 t.column "longitude", :integer, :null => false
64 t.column "user_id", :bigint, :limit => 20, :null => false
65 t.column "visible", :boolean, :null => false
66 t.column "tags", :text, :default => "", :null => false
67 t.column "timestamp", :datetime, :null => false
68 t.column "tile", :integer, :null => false
71 add_index "nodes", ["id"], :name => "nodes_uid_idx"
72 add_index "nodes", ["timestamp"], :name => "nodes_timestamp_idx"
73 add_index "nodes", ["tile"], :name => "nodes_tile_idx"
75 change_column "nodes", "tile", :integer, :null => false, :unsigned => true
77 upgrade_table "nodes_v5", "nodes", OldNode
83 rename_table "current_nodes", "current_nodes_v6"
85 create_table "current_nodes", innodb_table do |t|
86 t.column "id", :bigint_pk_64, :null => false
87 t.column "latitude", :double, :null => false
88 t.column "longitude", :double, :null => false
89 t.column "user_id", :bigint, :limit => 20, :null => false
90 t.column "visible", :boolean, :null => false
91 t.column "tags", :text, :default => "", :null => false
92 t.column "timestamp", :datetime, :null => false
95 add_index "current_nodes", ["latitude", "longitude"], :name => "current_nodes_lat_lon_idx"
96 add_index "current_nodes", ["timestamp"], :name => "current_nodes_timestamp_idx"
98 downgrade_table "current_nodes_v6", "current_nodes"
100 drop_table "current_nodes_v6"
102 rename_table "nodes", "nodes_v6"
104 create_table "nodes", myisam_table do |t|
105 t.column "id", :bigint, :limit => 64, :null => false
106 t.column "latitude", :double, :null => false
107 t.column "longitude", :double, :null => false
108 t.column "user_id", :bigint, :limit => 20, :null => false
109 t.column "visible", :boolean, :null => false
110 t.column "tags", :text, :default => "", :null => false
111 t.column "timestamp", :datetime, :null => false
114 add_index "nodes", ["id"], :name => "nodes_uid_idx"
115 add_index "nodes", ["latitude", "longitude"], :name => "nodes_latlon_idx"
116 add_index "nodes", ["timestamp"], :name => "nodes_timestamp_idx"
118 downgrade_table "nodes_v6", "nodes"
120 drop_table "nodes_v6"