From cc5a05574a8eb5fa958b0b0b18dd038f114f7171 Mon Sep 17 00:00:00 2001 From: ekzyis Date: Thu, 25 Apr 2024 18:20:18 +0200 Subject: [PATCH] Fix unique constraint hit For HN reposts, the same SN dupe was found but since sn_items.id was the primary key, a unique constraint was hit. This meant that posting the same item was attempted over and over again since the HN item id was never found in sn_items. I manually migrated the database. --- db.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/db.go b/db.go index ac79081..734921b 100644 --- a/db.go +++ b/db.go @@ -41,9 +41,10 @@ func migrate(db *sql.DB) { } if _, err := db.Exec(` CREATE TABLE IF NOT EXISTS sn_items ( - id INTEGER PRIMARY KEY, + id INTEGER NOT NULL, created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, - hn_id INTEGER NOT NULL REFERENCES hn_items(id) + hn_id INTEGER NOT NULL REFERENCES hn_items(id), + PRIMARY KEY (id, hn_id) ); `); err != nil { err = fmt.Errorf("error during migration: %w", err)