]> git.openstreetmap.org Git - rails.git/blob - db/migrate/007_add_relations.rb
Add a user index to diary comments
[rails.git] / db / migrate / 007_add_relations.rb
1 require 'lib/migrate'
2
3 class AddRelations < ActiveRecord::Migration
4   def self.up
5     # enums work like strings but are more efficient
6     create_enumeration :nwr_enum, ["Node", "Way", "Relation"]
7
8     # a relation can have members much like a way can have nodes.
9     # differences:
10     # way: only nodes / relation: any kind of member
11     # way: ordered sequence of nodes / relation: free-form "role" string
12     create_table "current_relation_members", innodb_table do |t|
13       t.column "id",          :bigint,   :limit => 64, :null => false
14       t.column "member_type", :nwr_enum, :null => false
15       t.column "member_id",   :bigint,   :limit => 11, :null => false
16       t.column "member_role", :string
17     end
18
19     add_primary_key "current_relation_members", ["id", "member_type", "member_id", "member_role"]
20     add_index "current_relation_members", ["member_type", "member_id"], :name => "current_relation_members_member_idx"
21     # the following is obsolete given the primary key, is it not?
22     # add_index "current_relation_members", ["id"], :name => "current_relation_members_id_idx"
23     create_table "current_relation_tags", myisam_table do |t|
24       t.column "id", :bigint, :limit => 64, :null => false
25       t.column "k",  :string, :default => "", :null => false
26       t.column "v",  :string, :default => "", :null => false
27     end
28
29     add_index "current_relation_tags", ["id"], :name => "current_relation_tags_id_idx"
30     add_fulltext_index "current_relation_tags", "v"
31
32     create_table "current_relations", innodb_table do |t|
33       t.column "id",        :bigint_pk_64,           :null => false
34       t.column "user_id",   :bigint,   :limit => 20, :null => false
35       t.column "timestamp", :datetime, :null => false
36       t.column "visible",   :boolean,  :null => false
37     end
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", :nwr_enum, :null => false
42       t.column "member_id",   :bigint,   :limit => 11, :null => false
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_type", "member_id", "member_role"]
48     add_index "relation_members", ["member_type", "member_id"], :name => "relation_members_member_idx"
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, :null => false, :default => ""
53       t.column "v",       :string, :null => false, :default => ""
54       t.column "version", :bigint,  :limit => 20, :null => false
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, :null => false, :default => 0
61       t.column "user_id",   :bigint,   :limit => 20, :null => false
62       t.column "timestamp", :datetime,               :null => false
63       t.column "version",   :bigint,   :limit => 20, :null => false
64       t.column "visible",   :boolean,                :null => false, :default => true
65     end
66
67     add_primary_key "relations", ["id", "version"]
68     add_index "relations", ["timestamp"], :name => "relations_timestamp_idx"
69     
70     change_column "relations", "version", :bigint_auto_20
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     drop_enumeration :nwr_enum
82   end
83 end