mirror of
https://github.com/binwiederhier/ntfy.git
synced 2026-03-18 21:30:44 +01:00
Simplify schema reading
This commit is contained in:
@@ -216,24 +216,13 @@ func setupSQLite(db *sql.DB, startupQueries string, cacheDuration time.Duration)
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// If 'messages' table does not exist, this must be a new database
|
// If 'messages' table does not exist, this must be a new database
|
||||||
rowsMC, err := db.Query(sqliteSelectMessagesCountQuery)
|
var messagesCount int
|
||||||
if err != nil {
|
if err := db.QueryRow(sqliteSelectMessagesCountQuery).Scan(&messagesCount); err != nil {
|
||||||
return setupNewSQLite(db)
|
return setupNewSQLite(db)
|
||||||
}
|
}
|
||||||
rowsMC.Close()
|
// If 'messages' table exists (schema >= 0), check 'schemaVersion' table
|
||||||
// If 'messages' table exists, check 'schemaVersion' table
|
var schemaVersion int
|
||||||
schemaVersion := 0
|
db.QueryRow(sqliteSelectSchemaVersionQuery).Scan(&schemaVersion) // Error means schema version is zero!
|
||||||
rowsSV, err := db.Query(sqliteSelectSchemaVersionQuery)
|
|
||||||
if err == nil {
|
|
||||||
defer rowsSV.Close()
|
|
||||||
if !rowsSV.Next() {
|
|
||||||
return fmt.Errorf("cannot determine schema version: cache file may be corrupt")
|
|
||||||
}
|
|
||||||
if err := rowsSV.Scan(&schemaVersion); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
rowsSV.Close()
|
|
||||||
}
|
|
||||||
// Do migrations
|
// Do migrations
|
||||||
if schemaVersion == sqliteCurrentSchemaVersion {
|
if schemaVersion == sqliteCurrentSchemaVersion {
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
Reference in New Issue
Block a user