1 class KeyConstraints < ActiveRecord::Migration
4 add_primary_key :current_node_tags, [:id, :k]
5 add_primary_key :current_way_tags, [:id, :k]
6 add_primary_key :current_relation_tags, [:id, :k]
8 add_primary_key :node_tags, [:id, :version, :k]
9 add_primary_key :way_tags, [:id, :version, :k]
10 add_primary_key :relation_tags, [:id, :version, :k]
12 add_primary_key :nodes, [:id, :version]
14 # Remove indexes superseded by primary keys
15 remove_index :current_way_tags, :name => :current_way_tags_id_idx
16 remove_index :current_relation_tags, :name => :current_relation_tags_id_idx
18 remove_index :way_tags, :name => :way_tags_id_version_idx
19 remove_index :relation_tags, :name => :relation_tags_id_version_idx
21 remove_index :nodes, :name => :nodes_uid_idx
23 # Foreign keys (between ways, way_tags, way_nodes, etc.)
24 add_foreign_key :current_node_tags, [:id], :current_nodes
25 add_foreign_key :node_tags, [:id, :version], :nodes
27 add_foreign_key :current_way_tags, [:id], :current_ways
28 add_foreign_key :current_way_nodes, [:id], :current_ways
29 add_foreign_key :way_tags, [:id, :version], :ways
30 add_foreign_key :way_nodes, [:id, :version], :ways
32 add_foreign_key :current_relation_tags, [:id], :current_relations
33 add_foreign_key :current_relation_members, [:id], :current_relations
34 add_foreign_key :relation_tags, [:id, :version], :relations
35 add_foreign_key :relation_members, [:id, :version], :relations
37 # Foreign keys (between different types of primitives)
38 add_foreign_key :current_way_nodes, [:node_id], :current_nodes, [:id]
40 # FIXME: We don't have foreign keys for relation members since the id
41 # might point to a different table depending on the `type' column.
42 # We'd probably need different current_relation_member_nodes,
43 # current_relation_member_ways and current_relation_member_relations
44 # tables for this to work cleanly.
48 raise IrreversibleMigration.new