proper foreign key
This commit is contained in:
parent
20c21beca9
commit
e9dbfe33e3
3 changed files with 10 additions and 8 deletions
|
@ -82,16 +82,17 @@ func (q *Queries) GetTalkgroupsWithAnyTags(ctx context.Context, tags []string) (
|
|||
}
|
||||
|
||||
const setTalkgroupTags = `-- name: SetTalkgroupTags :exec
|
||||
INSERT INTO talkgroups_tags(talkgroup_id, tags) VALUES($1, $2)
|
||||
ON CONFLICT (talkgroup_id) DO UPDATE SET tags = $2
|
||||
INSERT INTO talkgroups_tags(system_id, talkgroup_id, tags) VALUES($1, $2, $3)
|
||||
ON CONFLICT (system_id, talkgroup_id) DO UPDATE SET tags = $3
|
||||
`
|
||||
|
||||
type SetTalkgroupTagsParams struct {
|
||||
SystemID int32
|
||||
TalkgroupID int32
|
||||
Tags []string
|
||||
}
|
||||
|
||||
func (q *Queries) SetTalkgroupTags(ctx context.Context, arg SetTalkgroupTagsParams) error {
|
||||
_, err := q.db.Exec(ctx, setTalkgroupTags, arg.TalkgroupID, arg.Tags)
|
||||
_, err := q.db.Exec(ctx, setTalkgroupTags, arg.SystemID, arg.TalkgroupID, arg.Tags)
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -36,9 +36,10 @@ CREATE TABLE IF NOT EXISTS talkgroups(
|
|||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS talkgroups_tags(
|
||||
system_id INTEGER NOT NULL REFERENCES systems(id),
|
||||
talkgroup_id INTEGER NOT NULL REFERENCES talkgroups(id),
|
||||
tags TEXT[] NOT NULL DEFAULT '{}'
|
||||
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)
|
||||
);
|
||||
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);
|
||||
|
|
|
@ -11,6 +11,6 @@ SELECT tags FROM talkgroups_tags
|
|||
WHERE talkgroup_id = $1;
|
||||
|
||||
-- name: SetTalkgroupTags :exec
|
||||
INSERT INTO talkgroups_tags(talkgroup_id, tags) VALUES($1, $2)
|
||||
ON CONFLICT (talkgroup_id) DO UPDATE SET tags = $2;
|
||||
INSERT INTO talkgroups_tags(system_id, talkgroup_id, tags) VALUES($1, $2, $3)
|
||||
ON CONFLICT (system_id, talkgroup_id) DO UPDATE SET tags = $3;
|
||||
|
||||
|
|
Loading…
Reference in a new issue