fix(store): add the outbox post_id and priority columns separately
The two columns were added in one non-transactional Exec guarded by post_id alone. A crash between the two statements left a database with post_id but no priority, and every later start failed at CREATE INDEX outbox_due_prio. Each column is now checked and added on its own, as the members columns are.
This commit is contained in:
parent
bc1ea2e7c3
commit
c66fd427b2
2 changed files with 28 additions and 2 deletions
|
|
@ -717,3 +717,25 @@ func TestConfirmPendingIsSingleUseUnderConcurrency(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMigrationAddsTheOutboxPriorityAloneAfterAHalfDoneUpgrade(t *testing.T) {
|
||||
// A crash between adding post_id and priority leaves outbox with the first and not the second.
|
||||
path := t.TempDir() + "/old.db"
|
||||
s, _ := Open(path)
|
||||
if _, err := s.db.Exec(`DROP INDEX outbox_due_prio`); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := s.db.Exec(`ALTER TABLE outbox DROP COLUMN priority`); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
s.Close()
|
||||
|
||||
s2, err := Open(path)
|
||||
if err != nil {
|
||||
t.Fatalf("migrate: %v", err)
|
||||
}
|
||||
defer s2.Close()
|
||||
if ok, err := hasColumn(s2.db, "outbox", "priority"); err != nil || !ok {
|
||||
t.Fatalf("priority is added back: %v %v", ok, err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -325,8 +325,12 @@ func migrate(db *sql.DB) error {
|
|||
}
|
||||
}
|
||||
if has, _ := hasColumn(db, "outbox", "post_id"); !has {
|
||||
if _, err := db.Exec(`ALTER TABLE outbox ADD COLUMN post_id INTEGER NOT NULL DEFAULT 0;
|
||||
ALTER TABLE outbox ADD COLUMN priority INTEGER NOT NULL DEFAULT 0;`); err != nil {
|
||||
if _, err := db.Exec(`ALTER TABLE outbox ADD COLUMN post_id INTEGER NOT NULL DEFAULT 0`); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if has, _ := hasColumn(db, "outbox", "priority"); !has {
|
||||
if _, err := db.Exec(`ALTER TABLE outbox ADD COLUMN priority INTEGER NOT NULL DEFAULT 0`); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue