3 class KeyConstraints < ActiveRecord::Migration[4.2]
6 add_primary_key :current_node_tags, [:id, :k]
7 add_primary_key :current_way_tags, [:id, :k]
8 add_primary_key :current_relation_tags, [:id, :k]
10 add_primary_key :node_tags, [:id, :version, :k]
11 add_primary_key :way_tags, [:id, :version, :k]
12 add_primary_key :relation_tags, [:id, :version, :k]
14 add_primary_key :nodes, [:id, :version]
16 # Remove indexes superseded by primary keys
17 remove_index :current_way_tags, :name => :current_way_tags_id_idx
18 remove_index :current_relation_tags, :name => :current_relation_tags_id_idx
20 remove_index :way_tags, :name => :way_tags_id_version_idx
21 remove_index :relation_tags, :name => :relation_tags_id_version_idx
23 remove_index :nodes, :name => :nodes_uid_idx
25 # Foreign keys (between ways, way_tags, way_nodes, etc.)
26 add_foreign_key :current_node_tags, :current_nodes, :column => :id, :name => "current_node_tags_id_fkey"
27 add_foreign_key :node_tags, :nodes, :column => [:id, :version], :primary_key => [:id, :version], :name => "node_tags_id_fkey"
29 add_foreign_key :current_way_tags, :current_ways, :column => :id, :name => "current_way_tags_id_fkey"
30 add_foreign_key :current_way_nodes, :current_ways, :column => :id, :name => "current_way_nodes_id_fkey"
31 add_foreign_key :way_tags, :ways, :column => [:id, :version], :primary_key => [:id, :version], :name => "way_tags_id_fkey"
32 add_foreign_key :way_nodes, :ways, :column => [:id, :version], :primary_key => [:id, :version], :name => "way_nodes_id_fkey"
34 add_foreign_key :current_relation_tags, :current_relations, :column => :id, :name => "current_relation_tags_id_fkey"
35 add_foreign_key :current_relation_members, :current_relations, :column => :id, :name => "current_relation_members_id_fkey"
36 add_foreign_key :relation_tags, :relations, :column => [:id, :version], :primary_key => [:id, :version], :name => "relation_tags_id_fkey"
37 add_foreign_key :relation_members, :relations, :column => [:id, :version], :primary_key => [:id, :version], :name => "relation_members_id_fkey"
39 # Foreign keys (between different types of primitives)
40 add_foreign_key :current_way_nodes, :current_nodes, :column => :node_id, :name => "current_way_nodes_node_id_fkey"
42 # FIXME: We don't have foreign keys for relation members since the id
43 # might point to a different table depending on the `type' column.
44 # We'd probably need different current_relation_member_nodes,
45 # current_relation_member_ways and current_relation_member_relations
46 # tables for this to work cleanly.
50 raise ActiveRecord::IrreversibleMigration