fix(store): surface invalid schema_version; split migration test assertion
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -59,7 +59,11 @@ func (s *Store) migrate() error {
|
|||||||
// Fresh database: schemaSQL created all columns already.
|
// Fresh database: schemaSQL created all columns already.
|
||||||
return s.SetSetting("schema_version", strconv.Itoa(schemaVersion))
|
return s.SetSetting("schema_version", strconv.Itoa(schemaVersion))
|
||||||
}
|
}
|
||||||
ver, _ := strconv.Atoi(v)
|
var ver int
|
||||||
|
ver, err = strconv.Atoi(v)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("invalid schema_version %q: %w", v, err)
|
||||||
|
}
|
||||||
if ver < 2 {
|
if ver < 2 {
|
||||||
if _, err := s.db.Exec(`ALTER TABLE accounts ADD COLUMN from_address TEXT`); err != nil {
|
if _, err := s.db.Exec(`ALTER TABLE accounts ADD COLUMN from_address TEXT`); err != nil {
|
||||||
return fmt.Errorf("migrate to v2: %w", err)
|
return fmt.Errorf("migrate to v2: %w", err)
|
||||||
|
|||||||
@@ -158,8 +158,11 @@ INSERT INTO accounts(name,mode,imap_host,imap_port,imap_security,auth_type,usern
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("ListAccounts after migrate: %v", err)
|
t.Fatalf("ListAccounts after migrate: %v", err)
|
||||||
}
|
}
|
||||||
if len(accs) != 1 || accs[0].FromAddress != "" {
|
if len(accs) != 1 {
|
||||||
t.Fatalf("legacy account wrong after migrate: %+v", accs)
|
t.Fatalf("want 1 account after migrate, got %d", len(accs))
|
||||||
|
}
|
||||||
|
if accs[0].FromAddress != "" {
|
||||||
|
t.Fatalf("legacy account FromAddress should be empty, got %q", accs[0].FromAddress)
|
||||||
}
|
}
|
||||||
if got := accs[0].SendFrom(); got != "login@example.com" {
|
if got := accs[0].SendFrom(); got != "login@example.com" {
|
||||||
t.Fatalf("legacy account should send from username, got %q", got)
|
t.Fatalf("legacy account should send from username, got %q", got)
|
||||||
|
|||||||
Reference in New Issue
Block a user