1 class TileNodes < ActiveRecord::Migration
2 def self.upgrade_table(from_table, to_table)
4 INSERT INTO #{to_table} (id, latitude, longitude, user_id, visible, tags, timestamp, tile)
5 SELECT id, ROUND(latitude * 10000000), ROUND(longitude * 10000000),
6 user_id, visible, tags, timestamp,
7 tile_for_point(CAST(ROUND(latitude * 10000000) AS UNSIGNED),
8 CAST(ROUND(longitude * 10000000) AS UNSIGNED))
13 def self.downgrade_table(from_table, to_table)
15 INSERT INTO #{to_table} (id, latitude, longitude, user_id, visible, tags, timestamp)
16 SELECT id, latitude / 10000000, longitude / 10000000,
17 user_id, visible, tags, timestamp
23 rename_table "current_nodes", "current_nodes_v5"
25 create_table "current_nodes", innodb_table do |t|
26 t.column "id", :bigint, :limit => 64, :null => false
27 t.column "latitude", :integer, :null => false
28 t.column "longitude", :integer, :null => false
29 t.column "user_id", :bigint, :limit => 20, :null => false
30 t.column "visible", :boolean, :null => false
31 t.column "tags", :text, :default => "", :null => false
32 t.column "timestamp", :datetime, :null => false
33 t.column "tile", :integer, :null => false
36 add_primary_key "current_nodes", ["id"]
37 add_index "current_nodes", ["timestamp"], :name => "current_nodes_timestamp_idx"
38 add_index "current_nodes", ["tile"], :name => "current_nodes_tile_idx"
40 change_column "current_nodes", "id", :bigint, :limit => 64, :null => false, :options => "AUTO_INCREMENT"
41 change_column "current_nodes", "tile", :integer, :null => false, :unsigned => true
43 upgrade_table "current_nodes_v5", "current_nodes"
45 drop_table "current_nodes_v5"
47 rename_table "nodes", "nodes_v5"
49 create_table "nodes", myisam_table do |t|
50 t.column "id", :bigint, :limit => 64, :null => false
51 t.column "latitude", :integer, :null => false
52 t.column "longitude", :integer, :null => false
53 t.column "user_id", :bigint, :limit => 20, :null => false
54 t.column "visible", :boolean, :null => false
55 t.column "tags", :text, :default => "", :null => false
56 t.column "timestamp", :datetime, :null => false
57 t.column "tile", :integer, :null => false
60 add_index "nodes", ["id"], :name => "nodes_uid_idx"
61 add_index "nodes", ["timestamp"], :name => "nodes_timestamp_idx"
62 add_index "nodes", ["tile"], :name => "nodes_tile_idx"
64 change_column "nodes", "tile", :integer, :null => false, :unsigned => true
66 upgrade_table "nodes_v5", "nodes"
72 rename_table "current_nodes", "current_nodes_v6"
74 create_table "current_nodes", innodb_table do |t|
75 t.column "id", :bigint, :limit => 64, :null => false
76 t.column "latitude", :double, :null => false
77 t.column "longitude", :double, :null => false
78 t.column "user_id", :bigint, :limit => 20, :null => false
79 t.column "visible", :boolean, :null => false
80 t.column "tags", :text, :default => "", :null => false
81 t.column "timestamp", :datetime, :null => false
84 add_primary_key "current_nodes", ["id"]
85 add_index "current_nodes", ["latitude", "longitude"], :name => "current_nodes_lat_lon_idx"
86 add_index "current_nodes", ["timestamp"], :name => "current_nodes_timestamp_idx"
88 change_column "current_nodes", "id", :bigint, :limit => 64, :null => false, :options => "AUTO_INCREMENT"
90 downgrade_table "current_nodes_v6", "current_nodes"
92 drop_table "current_nodes_v6"
94 rename_table "nodes", "nodes_v6"
96 create_table "nodes", myisam_table do |t|
97 t.column "id", :bigint, :limit => 64, :null => false
98 t.column "latitude", :double, :null => false
99 t.column "longitude", :double, :null => false
100 t.column "user_id", :bigint, :limit => 20, :null => false
101 t.column "visible", :boolean, :null => false
102 t.column "tags", :text, :default => "", :null => false
103 t.column "timestamp", :datetime, :null => false
106 add_index "nodes", ["id"], :name => "nodes_uid_idx"
107 add_index "nodes", ["latitude", "longitude"], :name => "nodes_latlon_idx"
108 add_index "nodes", ["timestamp"], :name => "nodes_timestamp_idx"
110 downgrade_table "nodes_v6", "nodes"
112 drop_table "nodes_v6"