1 class AddRelations < ActiveRecord::Migration[4.2]
3 # enums work like strings but are more efficient
4 create_enumeration :nwr_enum, %w[Node Way Relation]
6 # a relation can have members much like a way can have nodes.
8 # way: only nodes / relation: any kind of member
9 # way: ordered sequence of nodes / relation: free-form "role" string
10 create_table "current_relation_members", :id => false do |t|
11 t.column "id", :bigint, :null => false
12 t.column "member_type", :nwr_enum, :null => false
13 t.column "member_id", :bigint, :null => false
14 t.column "member_role", :string
17 add_primary_key "current_relation_members", %w[id member_type member_id member_role]
18 add_index "current_relation_members", %w[member_type member_id], :name => "current_relation_members_member_idx"
19 # the following is obsolete given the primary key, is it not?
20 # add_index "current_relation_members", ["id"], :name => "current_relation_members_id_idx"
21 create_table "current_relation_tags", :id => false do |t|
22 t.column "id", :bigint, :null => false
23 t.column "k", :string, :default => "", :null => false
24 t.column "v", :string, :default => "", :null => false
27 add_index "current_relation_tags", ["id"], :name => "current_relation_tags_id_idx"
28 add_index "current_relation_tags", "v", :name => "current_relation_tags_v_idx"
30 create_table "current_relations", :id => false do |t|
31 t.column "id", :bigserial, :primary_key => true, :null => false
32 t.column "user_id", :bigint, :null => false
33 t.column "timestamp", :datetime, :null => false
34 t.column "visible", :boolean, :null => false
37 create_table "relation_members", :id => false do |t|
38 t.column "id", :bigint, :default => 0, :null => false
39 t.column "member_type", :nwr_enum, :null => false
40 t.column "member_id", :bigint, :null => false
41 t.column "member_role", :string
42 t.column "version", :bigint, :default => 0, :null => false
45 add_primary_key "relation_members", %w[id version member_type member_id member_role]
46 add_index "relation_members", %w[member_type member_id], :name => "relation_members_member_idx"
48 create_table "relation_tags", :id => false do |t|
49 t.column "id", :bigint, :default => 0, :null => false
50 t.column "k", :string, :null => false, :default => ""
51 t.column "v", :string, :null => false, :default => ""
52 t.column "version", :bigint, :null => false
55 add_index "relation_tags", %w[id version], :name => "relation_tags_id_version_idx"
57 create_table "relations", :id => false do |t|
58 t.column "id", :bigint, :null => false, :default => 0
59 t.column "user_id", :bigint, :null => false
60 t.column "timestamp", :datetime, :null => false
61 t.column "version", :bigint, :null => false
62 t.column "visible", :boolean, :null => false, :default => true
65 add_primary_key "relations", %w[id version]
66 add_index "relations", ["timestamp"], :name => "relations_timestamp_idx"
71 drop_table :current_relations
72 drop_table :relation_tags
73 drop_table :current_relation_tags
74 drop_table :relation_members
75 drop_table :current_relation_members
76 drop_enumeration :nwr_enum