]> git.openstreetmap.org Git - rails.git/commitdiff
Remove extraneous fields from primary keys for relation members
authorTom Hughes <tom@compton.nu>
Tue, 10 Oct 2023 19:53:20 +0000 (20:53 +0100)
committerTom Hughes <tom@compton.nu>
Thu, 26 Oct 2023 17:08:26 +0000 (18:08 +0100)
app/models/old_relation_member.rb
app/models/relation_member.rb
db/migrate/20231010194809_correct_relation_members_primary_key.rb [new file with mode: 0644]
db/structure.sql

index 4264e022164d8a0acbaed1c3719f21be957c0fc3..5a11566059c94c5479018928e3a6096567805a71 100644 (file)
@@ -20,7 +20,6 @@
 
 class OldRelationMember < ApplicationRecord
   self.table_name = "relation_members"
-  self.primary_key = %w[relation_id version sequence_id]
 
   belongs_to :old_relation, :query_constraints => [:relation_id, :version], :inverse_of => :old_members
   # A bit messy, referring to the current tables, should do for the data browser for now
index 8ff825cee5e3a8105b784f0faa483638cc7361a1..2b72cd2b182595bd6f6abb2d138559c700572103 100644 (file)
@@ -19,7 +19,6 @@
 
 class RelationMember < ApplicationRecord
   self.table_name = "current_relation_members"
-  self.primary_key = %w[relation_id sequence_id]
 
   belongs_to :relation
   belongs_to :member, :polymorphic => true
diff --git a/db/migrate/20231010194809_correct_relation_members_primary_key.rb b/db/migrate/20231010194809_correct_relation_members_primary_key.rb
new file mode 100644 (file)
index 0000000..0987083
--- /dev/null
@@ -0,0 +1,11 @@
+class CorrectRelationMembersPrimaryKey < ActiveRecord::Migration[7.0]
+  def up
+    alter_primary_key :current_relation_members, [:relation_id, :sequence_id]
+    alter_primary_key :relation_members, [:relation_id, :version, :sequence_id]
+  end
+
+  def down
+    alter_primary_key :relation_members, [:relation_id, :version, :member_type, :member_id, :member_role, :sequence_id]
+    alter_primary_key :current_relation_members, [:relation_id, :member_type, :member_id, :member_role, :sequence_id]
+  end
+end
index 467d5143cc427a0a9ad45190b9c260a7c6b7ee10..17f2696667d343f796e7b9917e1278bcf4f82f18 100644 (file)
@@ -1883,7 +1883,7 @@ ALTER TABLE ONLY public.current_nodes
 --
 
 ALTER TABLE ONLY public.current_relation_members
-    ADD CONSTRAINT current_relation_members_pkey PRIMARY KEY (relation_id, member_type, member_id, member_role, sequence_id);
+    ADD CONSTRAINT current_relation_members_pkey PRIMARY KEY (relation_id, sequence_id);
 
 
 --
@@ -2107,7 +2107,7 @@ ALTER TABLE ONLY public.redactions
 --
 
 ALTER TABLE ONLY public.relation_members
-    ADD CONSTRAINT relation_members_pkey PRIMARY KEY (relation_id, version, member_type, member_id, member_role, sequence_id);
+    ADD CONSTRAINT relation_members_pkey PRIMARY KEY (relation_id, version, sequence_id);
 
 
 --
@@ -3437,6 +3437,7 @@ INSERT INTO "schema_migrations" (version) VALUES
 ('23'),
 ('22'),
 ('21'),
+('20231010194809'),
 ('20231007141103'),
 ('20230830115220'),
 ('20230830115219'),