Fixed bug in publishing issue

This commit is contained in:
2024-03-28 07:34:36 +01:00
parent e82a0c6abe
commit 32d80e87a0
3 changed files with 32 additions and 15 deletions

View File

@ -23,7 +23,6 @@ func (db *DB) AddIssue() (int64, error) {
}
func (db *DB) PublishLatestIssue() error {
var id int64
txOptions := &sql.TxOptions{Isolation: sql.LevelSerializable}
updateQuery := "UPDATE issues SET published = true WHERE published = false"
insertQuery := "INSERT INTO issues (published) VALUES (?)"
@ -35,7 +34,7 @@ func (db *DB) PublishLatestIssue() error {
return fmt.Errorf("error starting transaction: %v", err)
}
if _, err := tx.Exec(updateQuery, id); err != nil {
if _, err := tx.Exec(updateQuery); err != nil {
if rollbackErr := tx.Rollback(); rollbackErr != nil {
log.Fatalf("transaction error: %v, rollback error: %v", err, rollbackErr)
}