2 module ConnectionAdapters
3 module SchemaStatements
4 def add_primary_key(table_name, column_name, options = {})
5 index_name = options[:name]
6 column_names = Array(column_name)
7 quoted_column_names = column_names.map { |e| quote_column_name(e) }.join(", ")
8 execute "ALTER TABLE #{table_name} ADD PRIMARY KEY #{quote_column_name(index_name)} (#{quoted_column_names})"
11 alias_method :old_add_column_options!, :add_column_options!
13 def add_column_options!(sql, options)
14 old_add_column_options!(sql, options)
15 sql << " #{options[:options]}"
18 alias_method :old_options_include_default?, :options_include_default?
20 def options_include_default?(options)
21 old_options_include_default?(options) && !(options[:options] =~ /AUTO_INCREMENT/i)
26 alias_method :old_native_database_types, :native_database_types
28 def native_database_types
29 types = old_native_database_types
30 types[:bigint] = { :name => "bigint", :limit => 20 }
37 class CreateOsmDb < ActiveRecord::Migration
39 myisam_table = { :id => false, :force => true, :options => "ENGINE=MyIsam DEFAULT CHARSET=utf8" }
40 innodb_table = { :id => false, :force => true, :options => "ENGINE=InnoDB DEFAULT CHARSET=utf8" }
42 create_table "current_nodes", innodb_table do |t|
43 t.column "id", :bigint, :limit => 64, :null => false
44 t.column "latitude", :double
45 t.column "longitude", :double
46 t.column "user_id", :bigint, :limit => 20
47 t.column "visible", :boolean
48 t.column "tags", :text, :default => "", :null => false
49 t.column "timestamp", :datetime
52 add_index "current_nodes", ["id"], :name => "current_nodes_id_idx"
53 add_index "current_nodes", ["latitude", "longitude"], :name => "current_nodes_lat_lon_idx"
54 add_index "current_nodes", ["timestamp"], :name => "current_nodes_timestamp_idx"
56 change_column "current_nodes", "id", :bigint, :limit => 64, :null => false, :options => "AUTO_INCREMENT"
58 create_table "current_segments", innodb_table do |t|
59 t.column "id", :bigint, :limit => 64, :null => false
60 t.column "node_a", :bigint, :limit => 64
61 t.column "node_b", :bigint, :limit => 64
62 t.column "user_id", :bigint, :limit => 20
63 t.column "visible", :boolean
64 t.column "tags", :text, :default => "", :null => false
65 t.column "timestamp", :datetime
68 add_index "current_segments", ["id", "visible"], :name => "current_segments_id_visible_idx"
69 add_index "current_segments", ["node_a"], :name => "current_segments_a_idx"
70 add_index "current_segments", ["node_b"], :name => "current_segments_b_idx"
72 change_column "current_segments", "id", :bigint, :limit => 64, :null => false, :options => "AUTO_INCREMENT"
74 create_table "current_way_segments", innodb_table do |t|
75 t.column "id", :bigint, :limit => 64
76 t.column "segment_id", :bigint, :limit => 11
77 t.column "sequence_id", :bigint, :limit => 11
80 add_index "current_way_segments", ["segment_id"], :name => "current_way_segments_seg_idx"
81 add_index "current_way_segments", ["id"], :name => "current_way_segments_id_idx"
83 create_table "current_way_tags", myisam_table do |t|
84 t.column "id", :bigint, :limit => 64
85 t.column "k", :string, :default => "", :null => false
86 t.column "v", :string, :default => "", :null => false
89 add_index "current_way_tags", ["id"], :name => "current_way_tags_id_idx"
90 execute "CREATE FULLTEXT INDEX `current_way_tags_v_idx` ON `current_way_tags` (`v`)"
92 create_table "current_ways", myisam_table do |t|
93 t.column "id", :bigint, :limit => 64, :null => false
94 t.column "user_id", :bigint, :limit => 20
95 t.column "timestamp", :datetime
96 t.column "visible", :boolean
99 add_primary_key "current_ways", ["id"], :name => "current_ways_id_idx", :unique => true
101 change_column "current_ways", "id", :bigint, :limit => 64, :null => false, :options => "AUTO_INCREMENT"
103 create_table "diary_entries", myisam_table do |t|
104 t.column "id", :bigint, :limit => 20, :null => false
105 t.column "user_id", :bigint, :limit => 20, :null => false
106 t.column "title", :string
107 t.column "body", :text
108 t.column "created_at", :datetime
109 t.column "updated_at", :datetime
112 add_primary_key "diary_entries", ["id"], :name => "diary_entries_id_idx", :unique => true
114 change_column "diary_entries", "id", :bigint, :limit => 20, :null => false, :options => "AUTO_INCREMENT"
116 create_table "friends", myisam_table do |t|
117 t.column "id", :bigint, :limit => 20, :null => false
118 t.column "user_id", :bigint, :limit => 20, :null => false
119 t.column "friend_user_id", :bigint, :limit => 20, :null => false
122 add_primary_key "friends", ["id"], :name => "friends_id_idx", :unique => true
123 add_index "friends", ["friend_user_id"], :name => "user_id_idx"
125 change_column "friends", "id", :bigint, :limit => 20, :null => false, :options => "AUTO_INCREMENT"
127 create_table "gps_points", myisam_table do |t|
128 t.column "altitude", :float
129 t.column "user_id", :integer, :limit => 20
130 t.column "trackid", :integer
131 t.column "latitude", :integer
132 t.column "longitude", :integer
133 t.column "gpx_id", :integer, :limit => 20
134 t.column "timestamp", :datetime
137 add_index "gps_points", ["latitude", "longitude", "user_id"], :name => "points_idx"
138 add_index "gps_points", ["user_id"], :name => "points_uid_idx"
139 add_index "gps_points", ["gpx_id"], :name => "points_gpxid_idx"
141 create_table "gpx_file_tags", myisam_table do |t|
142 t.column "gpx_id", :bigint, :limit => 64, :default => 0, :null => false
143 t.column "tag", :string
144 t.column "id", :integer, :limit => 20, :null => false
147 add_primary_key "gpx_file_tags", ["id"], :name => "gpx_file_tags_id_idx", :unique => true
148 add_index "gpx_file_tags", ["gpx_id"], :name => "gpx_file_tags_gpxid_idx"
150 change_column "gpx_file_tags", "id", :integer, :limit => 20, :null => false, :options => "AUTO_INCREMENT"
152 create_table "gpx_files", myisam_table do |t|
153 t.column "id", :bigint, :limit => 64, :null => false
154 t.column "user_id", :bigint, :limit => 20
155 t.column "visible", :boolean, :default => true, :null => false
156 t.column "name", :string, :default => "", :null => false
157 t.column "size", :bigint, :limit => 20
158 t.column "latitude", :double
159 t.column "longitude", :double
160 t.column "timestamp", :datetime
161 t.column "public", :boolean, :default => true, :null => false
162 t.column "description", :string, :default => ""
163 t.column "inserted", :boolean
166 add_primary_key "gpx_files", ["id"], :name => "gpx_files_id_idx", :unique => true
167 add_index "gpx_files", ["timestamp"], :name => "gpx_files_timestamp_idx"
168 add_index "gpx_files", ["visible", "public"], :name => "gpx_files_visible_public_idx"
170 change_column "gpx_files", "id", :bigint, :limit => 64, :null => false, :options => "AUTO_INCREMENT"
172 create_table "gpx_pending_files", myisam_table do |t|
173 t.column "originalname", :string
174 t.column "tmpname", :string
175 t.column "user_id", :bigint, :limit => 20
178 create_table "messages", myisam_table do |t|
179 t.column "id", :bigint, :limit => 20, :null => false
180 t.column "user_id", :bigint, :limit => 20, :null => false
181 t.column "from_user_id", :bigint, :limit => 20, :null => false
182 t.column "from_display_name", :string, :default => ""
183 t.column "title", :string
184 t.column "body", :text
185 t.column "sent_on", :datetime
186 t.column "message_read", :boolean, :default => false
187 t.column "to_user_id", :bigint, :limit => 20, :null => false
190 add_primary_key "messages", ["id"], :name => "messages_id_idx", :unique => true
191 add_index "messages", ["from_display_name"], :name => "from_name_idx"
193 change_column "messages", "id", :bigint, :limit => 20, :null => false, :options => "AUTO_INCREMENT"
195 create_table "meta_areas", myisam_table do |t|
196 t.column "id", :bigint, :limit => 64, :null => false
197 t.column "user_id", :bigint, :limit => 20
198 t.column "timestamp", :datetime
201 add_primary_key "meta_areas", ["id"], :name => "meta_areas_id_idx", :unique => true
203 change_column "meta_areas", "id", :bigint, :limit => 64, :null => false, :options => "AUTO_INCREMENT"
205 create_table "nodes", myisam_table do |t|
206 t.column "id", :bigint, :limit => 64
207 t.column "latitude", :double
208 t.column "longitude", :double
209 t.column "user_id", :bigint, :limit => 20
210 t.column "visible", :boolean
211 t.column "tags", :text, :default => "", :null => false
212 t.column "timestamp", :datetime
215 add_index "nodes", ["id"], :name => "nodes_uid_idx"
216 add_index "nodes", ["latitude", "longitude"], :name => "nodes_latlon_idx"
218 create_table "segments", myisam_table do |t|
219 t.column "id", :bigint, :limit => 64
220 t.column "node_a", :bigint, :limit => 64
221 t.column "node_b", :bigint, :limit => 64
222 t.column "user_id", :bigint, :limit => 20
223 t.column "visible", :boolean
224 t.column "tags", :text, :default => "", :null => false
225 t.column "timestamp", :datetime
228 add_index "segments", ["node_a"], :name => "street_segments_nodea_idx"
229 add_index "segments", ["node_b"], :name => "street_segments_nodeb_idx"
230 add_index "segments", ["id"], :name => "street_segment_uid_idx"
232 create_table "users", innodb_table do |t|
233 t.column "email", :string
234 t.column "id", :bigint, :limit => 20, :null => false
235 t.column "token", :string
236 t.column "active", :integer, :default => 0, :null => false
237 t.column "pass_crypt", :string
238 t.column "creation_time", :datetime
239 t.column "timeout", :datetime
240 t.column "display_name", :string, :default => ""
241 t.column "preferences", :text
242 t.column "data_public", :boolean, :default => false
243 t.column "description", :text, :default => "", :null => false
244 t.column "home_lat", :double, :default => 1
245 t.column "home_lon", :double, :default => 1
246 t.column "within_lon", :double
247 t.column "within_lat", :double
248 t.column "home_zoom", :integer, :limit => 2, :default => 3
251 add_primary_key "users", ["id"], :name => "users_id_idx", :unique => true
252 add_index "users", ["email"], :name => "users_email_idx"
253 add_index "users", ["display_name"], :name => "users_display_name_idx"
255 change_column "users", "id", :bigint, :limit => 20, :null => false, :options => "AUTO_INCREMENT"
257 create_table "way_segments", myisam_table do |t|
258 t.column "id", :bigint, :limit => 64, :default => 0, :null => false
259 t.column "segment_id", :integer
260 t.column "version", :bigint, :limit => 20, :default => 0, :null => false
261 t.column "sequence_id", :bigint, :limit => 11, :null => false
264 add_primary_key "way_segments", ["id", "version", "sequence_id"], :name => "way_segments_id_version_sequence_idx", :unique => true
266 change_column "way_segments", "sequence_id", :bigint, :limit => 11, :null => false, :options => "AUTO_INCREMENT"
268 create_table "way_tags", myisam_table do |t|
269 t.column "id", :bigint, :limit => 64, :default => 0, :null => false
270 t.column "k", :string
271 t.column "v", :string
272 t.column "version", :bigint, :limit => 20
275 add_index "way_tags", ["id", "version"], :name => "way_tags_id_version_idx"
277 create_table "ways", myisam_table do |t|
278 t.column "id", :bigint, :limit => 64, :default => 0, :null => false
279 t.column "user_id", :bigint, :limit => 20
280 t.column "timestamp", :datetime
281 t.column "version", :bigint, :limit => 20, :null => false
282 t.column "visible", :boolean, :default => true
285 add_primary_key "ways", ["id", "version"], :name => "ways_primary_idx", :unique => true
286 add_index "ways", ["id"], :name => "ways_id_version_idx"
288 change_column "ways", "version", :bigint, :limit => 20, :null => false, :options => "AUTO_INCREMENT"