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.
This commit is contained in:
ekzyis 2024-04-25 18:20:18 +02:00
parent 0a0470ae67
commit cc5a05574a
1 changed files with 3 additions and 2 deletions

5
db.go
View File

@ -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)