]> git.openstreetmap.org Git - rails.git/blob - db/migrate/001_create_osm_db.rb
Remove old create_database.sql script as it no longers matches the
[rails.git] / db / migrate / 001_create_osm_db.rb
1 module ActiveRecord
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})"
9       end
10
11       alias_method :old_add_column_options!, :add_column_options!
12
13       def add_column_options!(sql, options)
14         old_add_column_options!(sql, options)
15         sql << " #{options[:options]}"
16       end
17
18       alias_method :old_options_include_default?, :options_include_default?
19
20       def options_include_default?(options)
21         old_options_include_default?(options) && !(options[:options] =~ /AUTO_INCREMENT/i)
22       end
23     end
24
25     class MysqlAdapter
26       alias_method :old_native_database_types, :native_database_types
27
28       def native_database_types
29         types = old_native_database_types
30         types[:bigint] = { :name => "bigint", :limit => 20 }
31         types
32       end
33     end
34   end
35 end
36
37 class CreateOsmDb < ActiveRecord::Migration
38   def self.up
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" }
41
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
50     end
51
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"
55
56     change_column "current_nodes", "id", :bigint, :limit => 64, :null => false, :options => "AUTO_INCREMENT"
57
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
66     end
67
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"
71
72     change_column "current_segments", "id", :bigint, :limit => 64, :null => false, :options => "AUTO_INCREMENT"
73
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
78     end
79
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"
82
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
87     end
88
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`)"
91
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
97     end
98
99     add_primary_key "current_ways", ["id"], :name => "current_ways_id_idx", :unique => true
100
101     change_column "current_ways", "id", :bigint, :limit => 64, :null => false, :options => "AUTO_INCREMENT"
102
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
110     end
111
112     add_primary_key "diary_entries", ["id"], :name => "diary_entries_id_idx", :unique => true
113
114     change_column "diary_entries", "id", :bigint, :limit => 20, :null => false, :options => "AUTO_INCREMENT"
115
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
120     end
121
122     add_primary_key "friends", ["id"], :name => "friends_id_idx", :unique => true
123     add_index "friends", ["friend_user_id"], :name => "user_id_idx"
124
125     change_column "friends", "id", :bigint, :limit => 20, :null => false, :options => "AUTO_INCREMENT"
126
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
135     end
136
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"
140
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
145     end
146
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"
149
150     change_column "gpx_file_tags", "id", :integer, :limit => 20, :null => false, :options => "AUTO_INCREMENT"
151
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
164     end
165
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"
169
170     change_column "gpx_files", "id", :bigint, :limit => 64, :null => false, :options => "AUTO_INCREMENT"
171
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
176     end
177
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
188     end
189
190     add_primary_key "messages", ["id"], :name => "messages_id_idx", :unique => true
191     add_index "messages", ["from_display_name"], :name => "from_name_idx"
192
193     change_column "messages", "id", :bigint, :limit => 20, :null => false, :options => "AUTO_INCREMENT"
194
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
199     end
200
201     add_primary_key "meta_areas", ["id"], :name => "meta_areas_id_idx", :unique => true
202
203     change_column "meta_areas", "id", :bigint, :limit => 64, :null => false, :options => "AUTO_INCREMENT"
204
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
213     end
214
215     add_index "nodes", ["id"], :name => "nodes_uid_idx"
216     add_index "nodes", ["latitude", "longitude"], :name => "nodes_latlon_idx"
217
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
226     end
227
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"
231
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
249     end
250
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"
254
255     change_column "users", "id", :bigint, :limit => 20, :null => false, :options => "AUTO_INCREMENT"
256
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
262     end
263
264     add_primary_key "way_segments", ["id", "version", "sequence_id"], :name => "way_segments_id_version_sequence_idx", :unique => true
265
266     change_column "way_segments", "sequence_id", :bigint, :limit => 11, :null => false, :options => "AUTO_INCREMENT"
267
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
273     end
274
275     add_index "way_tags", ["id", "version"], :name => "way_tags_id_version_idx"
276
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
283     end
284
285     add_primary_key "ways", ["id", "version"], :name => "ways_primary_idx", :unique => true
286     add_index "ways", ["id"], :name => "ways_id_version_idx"
287
288     change_column "ways", "version", :bigint, :limit => 20, :null => false, :options => "AUTO_INCREMENT"
289   end
290
291   def self.down
292     
293   end
294 end