From 30a19650945ec3ce3913bcc1aa700fb7ce2a832a Mon Sep 17 00:00:00 2001 From: Daniel Ponte Date: Wed, 17 Jul 2024 19:51:29 -0400 Subject: [PATCH] Fix primary key --- pkg/gordio/database/models.go | 2 +- sql/postgres/migrations/001_initial.up.sql | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/gordio/database/models.go b/pkg/gordio/database/models.go index e11b14f..82ede4f 100644 --- a/pkg/gordio/database/models.go +++ b/pkg/gordio/database/models.go @@ -63,7 +63,7 @@ type System struct { } type Talkgroup struct { - System int32 + SystemID int32 Tgid int32 Name pgtype.Text Frequency pgtype.Int4 diff --git a/sql/postgres/migrations/001_initial.up.sql b/sql/postgres/migrations/001_initial.up.sql index 2e8b32d..3eca0e0 100644 --- a/sql/postgres/migrations/001_initial.up.sql +++ b/sql/postgres/migrations/001_initial.up.sql @@ -26,7 +26,7 @@ CREATE TABLE IF NOT EXISTS systems( ); CREATE TABLE IF NOT EXISTS talkgroups( - system INTEGER REFERENCES systems(id) NOT NULL, + system_id INTEGER REFERENCES systems(id) NOT NULL, tgid INTEGER, name TEXT, frequency INTEGER, @@ -39,9 +39,9 @@ CREATE TABLE IF NOT EXISTS talkgroups_tags( system_id INTEGER NOT NULL, talkgroup_id INTEGER NOT NULL, tags TEXT[] NOT NULL DEFAULT '{}', - FOREIGN KEY (system_id, talkgroup_id) REFERENCES talkgroups (system, tgid) + FOREIGN KEY (system_id, talkgroup_id) REFERENCES talkgroups (system_id, tgid), + PRIMARY KEY (system_id, talkgroup_id) ); -CREATE UNIQUE INDEX IF NOT EXISTS talkgroups_tags_id_talkgroup_id ON talkgroups_tags(system_id, talkgroup_id); CREATE INDEX IF NOT EXISTS talkgroup_tags_id_tags ON talkgroups_tags USING GIN (tags); CREATE TABLE IF NOT EXISTS calls(