Fix column drop on sqlite3 db update

This commit is contained in:
Yannik Sembritzki 2021-07-16 19:55:52 +02:00
parent 68bb6ab654
commit 0f19619d26

19
db.go
View File

@ -156,6 +156,25 @@ func (d *acmedb) handleDBUpgradeTo1() error {
if Config.Database.Engine != "sqlite3" {
_, _ = tx.Exec("ALTER TABLE records DROP COLUMN IF EXISTS Value")
_, _ = tx.Exec("ALTER TABLE records DROP COLUMN IF EXISTS LastActive")
} else {
_, err = tx.Exec("ALTER TABLE records RENAME TO records_old")
if err != nil {
return err
}
_, err = tx.Exec(userTable)
if err != nil {
return err
}
insertSQL := `INSERT INTO records (Username, Password, Subdomain, AllowFrom)
SELECT Username, Password, Subdomain, AllowFrom FROM records_old`
_, err = tx.Exec(insertSQL)
if err != nil {
return err
}
_, err = tx.Exec("DROP TABLE records_old")
if err != nil {
return err
}
}
_, err = tx.Exec("UPDATE acmedns SET Value='1' WHERE Name='db_version'")
return err