From 4f542ef9004cdd37e17734cdd58bb775dd091106 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Tue, 10 Oct 2023 20:53:20 +0100 Subject: [PATCH] Remove extraneous fields from primary keys for relation members --- app/models/old_relation_member.rb | 1 - app/models/relation_member.rb | 1 - ...1010194809_correct_relation_members_primary_key.rb | 11 +++++++++++ db/structure.sql | 5 +++-- 4 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 db/migrate/20231010194809_correct_relation_members_primary_key.rb diff --git a/app/models/old_relation_member.rb b/app/models/old_relation_member.rb index 4264e0221..5a1156605 100644 --- a/app/models/old_relation_member.rb +++ b/app/models/old_relation_member.rb @@ -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 diff --git a/app/models/relation_member.rb b/app/models/relation_member.rb index 8ff825cee..2b72cd2b1 100644 --- a/app/models/relation_member.rb +++ b/app/models/relation_member.rb @@ -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 index 000000000..09870836f --- /dev/null +++ b/db/migrate/20231010194809_correct_relation_members_primary_key.rb @@ -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 diff --git a/db/structure.sql b/db/structure.sql index 467d5143c..17f269666 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -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'), -- 2.39.5