]> git.openstreetmap.org Git - rails.git/blob - db/migrate/006_tile_nodes.rb
removed LOCAL from LOAD DATA INFILE
[rails.git] / db / migrate / 006_tile_nodes.rb
1 class TileNodes < ActiveRecord::Migration
2   def self.upgrade_table(from_table, to_table)
3     execute <<-END_SQL
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))
9     FROM #{from_table}
10     END_SQL
11   end
12
13   def self.downgrade_table(from_table, to_table)
14     execute <<-END_SQL
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
18     FROM #{from_table}
19     END_SQL
20   end
21
22   def self.up
23     rename_table "current_nodes", "current_nodes_v5"
24
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
34     end
35
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"
39
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
42
43     upgrade_table "current_nodes_v5", "current_nodes"
44
45     drop_table "current_nodes_v5"
46
47     rename_table "nodes", "nodes_v5"
48
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
58     end
59
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"
63
64     change_column "nodes", "tile", :integer, :null => false, :unsigned => true
65
66     upgrade_table "nodes_v5", "nodes"
67
68     drop_table "nodes_v5"
69   end
70
71   def self.down
72     rename_table "current_nodes", "current_nodes_v6"
73
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
82     end
83
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"
87
88     change_column "current_nodes", "id", :bigint, :limit => 64, :null => false, :options => "AUTO_INCREMENT"
89
90     downgrade_table "current_nodes_v6", "current_nodes"
91
92     drop_table "current_nodes_v6"
93
94     rename_table "nodes", "nodes_v6"
95
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
104     end
105
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"
109
110     downgrade_table "nodes_v6", "nodes"
111
112     drop_table "nodes_v6"
113   end
114 end