]> git.openstreetmap.org Git - rails.git/blob - db/migrate/005_add_relations.rb
ad396fc1790baef972003d8b49c58bccbefcb9d3
[rails.git] / db / migrate / 005_add_relations.rb
1 class AddRelations < ActiveRecord::Migration
2   def self.up
3     # a relation can have members much like a way can have nodes.
4     # differences:
5     # way: only nodes / relation: any kind of member
6     # way: ordered sequence of nodes / relation: free-form "role" string
7     create_table "current_relation_members", innodb_table do |t|
8       t.column "id",          :bigint, :limit => 64
9       t.column "member_type", :string, :limit => 11
10       t.column "member_id",   :bigint, :limit => 11
11       t.column "member_role", :string
12     end
13     # enums work like strings but are more efficient
14     execute "alter table current_relation_members change column member_type member_type enum('node','way','relation');"
15
16     add_index "current_relation_members", ["member_type", "member_id"], :name => "current_relation_members_member_idx"
17     add_index "current_relation_members", ["id"], :name => "current_relation_members_id_idx"
18
19     create_table "current_relation_tags", myisam_table do |t|
20       t.column "id", :bigint, :limit => 64
21       t.column "k",  :string,                :default => "", :null => false
22       t.column "v",  :string,                :default => "", :null => false
23     end
24
25     add_index "current_relation_tags", ["id"], :name => "current_relation_tags_id_idx"
26     execute "CREATE FULLTEXT INDEX `current_relation_tags_v_idx` ON `current_relation_tags` (`v`)"
27
28     create_table "current_relations", myisam_table do |t|
29       t.column "id",        :bigint,   :limit => 64, :null => false
30       t.column "user_id",   :bigint,   :limit => 20
31       t.column "timestamp", :datetime
32       t.column "visible",   :boolean
33     end
34
35     add_primary_key "current_relations", ["id"]
36
37     change_column "current_relations", "id", :bigint, :limit => 64, :null => false, :options => "AUTO_INCREMENT"
38
39     create_table "relation_members", myisam_table do |t|
40       t.column "id",          :bigint,  :limit => 64, :default => 0, :null => false
41       t.column "member_type", :string, :limit => 11
42       t.column "member_id",   :bigint, :limit => 11
43       t.column "member_role", :string
44       t.column "version",     :bigint,  :limit => 20, :default => 0, :null => false
45     end
46
47     add_primary_key "relation_members", ["id", "version", "member_id", "member_role"]
48     execute "alter table relation_members change column member_type member_type enum('node','way','relation');" 
49
50     create_table "relation_tags", myisam_table do |t|
51       t.column "id",      :bigint,  :limit => 64, :default => 0, :null => false
52       t.column "k",       :string
53       t.column "v",       :string
54       t.column "version", :bigint,  :limit => 20
55     end
56
57     add_index "relation_tags", ["id", "version"], :name => "relation_tags_id_version_idx"
58
59     create_table "relations", myisam_table do |t|
60       t.column "id",        :bigint,   :limit => 64, :default => 0, :null => false
61       t.column "user_id",   :bigint,   :limit => 20
62       t.column "timestamp", :datetime
63       t.column "version",   :bigint,   :limit => 20,                   :null => false
64       t.column "visible",   :boolean,                :default => true
65     end
66
67     add_primary_key "relations", ["id", "version"]
68     add_index "relations", ["id"], :name => "relations_id_version_idx"
69
70     change_column "relations", "version", :bigint, :limit => 20, :null => false, :options => "AUTO_INCREMENT"
71   end
72
73
74   def self.down
75     drop_table :relations
76     drop_table :current_relations
77     drop_table :relation_tags
78     drop_table :current_relation_tags
79     drop_table :relation_members
80     drop_table :current_relation_members
81   end
82 end