]> git.openstreetmap.org Git - rails.git/blob - db/migrate/001_create_osm_db.rb
Primary keys can't have names so don't pretend otherwise.
[rails.git] / db / migrate / 001_create_osm_db.rb
1 require 'lib/migrate'
2
3 class CreateOsmDb < ActiveRecord::Migration
4   def self.up
5     myisam_table = { :id => false, :force => true, :options => "ENGINE=MyIsam DEFAULT CHARSET=utf8" }
6     innodb_table = { :id => false, :force => true, :options => "ENGINE=InnoDB DEFAULT CHARSET=utf8" }
7
8     create_table "current_nodes", innodb_table do |t|
9       t.column "id",        :bigint,   :limit => 64,                 :null => false
10       t.column "latitude",  :double
11       t.column "longitude", :double
12       t.column "user_id",   :bigint,   :limit => 20
13       t.column "visible",   :boolean
14       t.column "tags",      :text,                   :default => "", :null => false
15       t.column "timestamp", :datetime
16     end
17
18     add_index "current_nodes", ["id"], :name => "current_nodes_id_idx"
19     add_index "current_nodes", ["latitude", "longitude"], :name => "current_nodes_lat_lon_idx"
20     add_index "current_nodes", ["timestamp"], :name => "current_nodes_timestamp_idx"
21
22     change_column "current_nodes", "id", :bigint, :limit => 64, :null => false, :options => "AUTO_INCREMENT"
23
24     create_table "current_segments", innodb_table do |t|
25       t.column "id",        :bigint,   :limit => 64,                 :null => false
26       t.column "node_a",    :bigint,   :limit => 64
27       t.column "node_b",    :bigint,   :limit => 64
28       t.column "user_id",   :bigint,   :limit => 20
29       t.column "visible",   :boolean
30       t.column "tags",      :text,                   :default => "", :null => false
31       t.column "timestamp", :datetime
32     end
33
34     add_index "current_segments", ["id", "visible"], :name => "current_segments_id_visible_idx"
35     add_index "current_segments", ["node_a"], :name => "current_segments_a_idx"
36     add_index "current_segments", ["node_b"], :name => "current_segments_b_idx"
37
38     change_column "current_segments", "id", :bigint, :limit => 64, :null => false, :options => "AUTO_INCREMENT"
39
40     create_table "current_way_segments", innodb_table do |t|
41       t.column "id",          :bigint, :limit => 64
42       t.column "segment_id",  :bigint, :limit => 11
43       t.column "sequence_id", :bigint, :limit => 11
44     end
45
46     add_index "current_way_segments", ["segment_id"], :name => "current_way_segments_seg_idx"
47     add_index "current_way_segments", ["id"], :name => "current_way_segments_id_idx"
48
49     create_table "current_way_tags", myisam_table do |t|
50       t.column "id", :bigint, :limit => 64
51       t.column "k",  :string,                :default => "", :null => false
52       t.column "v",  :string,                :default => "", :null => false
53     end
54
55     add_index "current_way_tags", ["id"], :name => "current_way_tags_id_idx"
56     execute "CREATE FULLTEXT INDEX `current_way_tags_v_idx` ON `current_way_tags` (`v`)"
57
58     create_table "current_ways", myisam_table do |t|
59       t.column "id",        :bigint,   :limit => 64, :null => false
60       t.column "user_id",   :bigint,   :limit => 20
61       t.column "timestamp", :datetime
62       t.column "visible",   :boolean
63     end
64
65     add_primary_key "current_ways", ["id"]
66
67     change_column "current_ways", "id", :bigint, :limit => 64, :null => false, :options => "AUTO_INCREMENT"
68
69     create_table "diary_entries", myisam_table do |t|
70       t.column "id",         :bigint,   :limit => 20, :null => false
71       t.column "user_id",    :bigint,   :limit => 20, :null => false
72       t.column "title",      :string
73       t.column "body",       :text
74       t.column "created_at", :datetime
75       t.column "updated_at", :datetime
76     end
77
78     add_primary_key "diary_entries", ["id"]
79
80     change_column "diary_entries", "id", :bigint, :limit => 20, :null => false, :options => "AUTO_INCREMENT"
81
82     create_table "friends", myisam_table do |t|
83       t.column "id",             :bigint,  :limit => 20, :null => false
84       t.column "user_id",        :bigint,  :limit => 20, :null => false
85       t.column "friend_user_id", :bigint,  :limit => 20, :null => false
86     end
87
88     add_primary_key "friends", ["id"]
89     add_index "friends", ["friend_user_id"], :name => "user_id_idx"
90
91     change_column "friends", "id", :bigint, :limit => 20, :null => false, :options => "AUTO_INCREMENT"
92
93     create_table "gps_points", myisam_table do |t|
94       t.column "altitude",  :float
95       t.column "user_id",   :integer,  :limit => 20
96       t.column "trackid",   :integer
97       t.column "latitude",  :integer
98       t.column "longitude", :integer
99       t.column "gpx_id",    :integer,  :limit => 20
100       t.column "timestamp", :datetime
101     end
102
103     add_index "gps_points", ["latitude", "longitude", "user_id"], :name => "points_idx"
104     add_index "gps_points", ["user_id"], :name => "points_uid_idx"
105     add_index "gps_points", ["gpx_id"], :name => "points_gpxid_idx"
106
107     create_table "gpx_file_tags", myisam_table do |t|
108       t.column "gpx_id", :bigint,  :limit => 64, :default => 0, :null => false
109       t.column "tag",    :string
110       t.column "id",     :integer, :limit => 20, :null => false
111     end
112
113     add_primary_key "gpx_file_tags", ["id"]
114     add_index "gpx_file_tags", ["gpx_id"], :name => "gpx_file_tags_gpxid_idx"
115
116     change_column "gpx_file_tags", "id", :integer, :limit => 20, :null => false, :options => "AUTO_INCREMENT"
117
118     create_table "gpx_files", myisam_table do |t|
119       t.column "id",          :bigint,   :limit => 64,                   :null => false
120       t.column "user_id",     :bigint,   :limit => 20
121       t.column "visible",     :boolean,                :default => true, :null => false
122       t.column "name",        :string,                 :default => "",   :null => false
123       t.column "size",        :bigint,   :limit => 20
124       t.column "latitude",    :double
125       t.column "longitude",   :double
126       t.column "timestamp",   :datetime
127       t.column "public",      :boolean,                :default => true, :null => false
128       t.column "description", :string,                 :default => ""
129       t.column "inserted",    :boolean
130     end
131
132     add_primary_key "gpx_files", ["id"]
133     add_index "gpx_files", ["timestamp"], :name => "gpx_files_timestamp_idx"
134     add_index "gpx_files", ["visible", "public"], :name => "gpx_files_visible_public_idx"
135
136     change_column "gpx_files", "id", :bigint, :limit => 64, :null => false, :options => "AUTO_INCREMENT"
137
138     create_table "gpx_pending_files", myisam_table do |t|
139       t.column "originalname", :string
140       t.column "tmpname",      :string
141       t.column "user_id",      :bigint,  :limit => 20
142     end
143
144     create_table "messages", myisam_table do |t|
145       t.column "id",                :bigint,   :limit => 20,                    :null => false
146       t.column "user_id",           :bigint,   :limit => 20,                    :null => false
147       t.column "from_user_id",      :bigint,   :limit => 20,                    :null => false
148       t.column "from_display_name", :string,                 :default => ""
149       t.column "title",             :string
150       t.column "body",              :text
151       t.column "sent_on",           :datetime
152       t.column "message_read",      :boolean,                :default => false
153       t.column "to_user_id",        :bigint,   :limit => 20,                    :null => false
154     end
155
156     add_primary_key "messages", ["id"]
157     add_index "messages", ["from_display_name"], :name => "from_name_idx"
158
159     change_column "messages", "id", :bigint, :limit => 20, :null => false, :options => "AUTO_INCREMENT"
160
161     create_table "meta_areas", myisam_table do |t|
162       t.column "id",        :bigint,  :limit => 64, :null => false
163       t.column "user_id",   :bigint,  :limit => 20
164       t.column "timestamp", :datetime
165     end
166
167     add_primary_key "meta_areas", ["id"]
168
169     change_column "meta_areas", "id", :bigint, :limit => 64, :null => false, :options => "AUTO_INCREMENT"
170
171     create_table "nodes", myisam_table do |t|
172       t.column "id",        :bigint,  :limit => 64
173       t.column "latitude",  :double
174       t.column "longitude", :double
175       t.column "user_id",   :bigint,  :limit => 20
176       t.column "visible",   :boolean
177       t.column "tags",      :text,                  :default => "", :null => false
178       t.column "timestamp", :datetime
179     end
180
181     add_index "nodes", ["id"], :name => "nodes_uid_idx"
182     add_index "nodes", ["latitude", "longitude"], :name => "nodes_latlon_idx"
183
184     create_table "segments", myisam_table do |t|
185       t.column "id",        :bigint,  :limit => 64
186       t.column "node_a",    :bigint,  :limit => 64
187       t.column "node_b",    :bigint,  :limit => 64
188       t.column "user_id",   :bigint,  :limit => 20
189       t.column "visible",   :boolean
190       t.column "tags",      :text,                  :default => "", :null => false
191       t.column "timestamp", :datetime
192     end
193
194     add_index "segments", ["node_a"], :name => "street_segments_nodea_idx"
195     add_index "segments", ["node_b"], :name => "street_segments_nodeb_idx"
196     add_index "segments", ["id"], :name => "street_segment_uid_idx"
197
198     create_table "users", innodb_table do |t|
199       t.column "email",         :string
200       t.column "id",            :bigint,   :limit => 20,                    :null => false
201       t.column "token",         :string
202       t.column "active",        :integer,                :default => 0,     :null => false
203       t.column "pass_crypt",    :string
204       t.column "creation_time", :datetime
205       t.column "timeout",       :datetime
206       t.column "display_name",  :string,                 :default => ""
207       t.column "preferences",   :text
208       t.column "data_public",   :boolean,                :default => false
209       t.column "description",   :text,                   :default => "",    :null => false
210       t.column "home_lat",      :double,                 :default => 1
211       t.column "home_lon",      :double,                 :default => 1
212       t.column "within_lon",    :double
213       t.column "within_lat",    :double
214       t.column "home_zoom",     :integer,  :limit => 2,  :default => 3
215     end
216
217     add_primary_key "users", ["id"]
218     add_index "users", ["email"], :name => "users_email_idx"
219     add_index "users", ["display_name"], :name => "users_display_name_idx"
220
221     change_column "users", "id", :bigint, :limit => 20, :null => false, :options => "AUTO_INCREMENT"
222
223     create_table "way_segments", myisam_table do |t|
224       t.column "id",          :bigint,  :limit => 64, :default => 0, :null => false
225       t.column "segment_id",  :integer
226       t.column "version",     :bigint,  :limit => 20, :default => 0, :null => false
227       t.column "sequence_id", :bigint,  :limit => 11,                :null => false
228     end
229
230     add_primary_key "way_segments", ["id", "version", "sequence_id"]
231
232     change_column "way_segments", "sequence_id", :bigint, :limit => 11, :null => false, :options => "AUTO_INCREMENT"
233
234     create_table "way_tags", myisam_table do |t|
235       t.column "id",      :bigint,  :limit => 64, :default => 0, :null => false
236       t.column "k",       :string
237       t.column "v",       :string
238       t.column "version", :bigint,  :limit => 20
239     end
240
241     add_index "way_tags", ["id", "version"], :name => "way_tags_id_version_idx"
242
243     create_table "ways", myisam_table do |t|
244       t.column "id",        :bigint,   :limit => 64, :default => 0, :null => false
245       t.column "user_id",   :bigint,   :limit => 20
246       t.column "timestamp", :datetime
247       t.column "version",   :bigint,   :limit => 20,                   :null => false
248       t.column "visible",   :boolean,                :default => true
249     end
250
251     add_primary_key "ways", ["id", "version"]
252     add_index "ways", ["id"], :name => "ways_id_version_idx"
253
254     change_column "ways", "version", :bigint, :limit => 20, :null => false, :options => "AUTO_INCREMENT"
255   end
256
257   def self.down
258     
259   end
260 end