github.com/ladydascalie/elvish@v0.0.0-20170703214355-2964dd3ece7f/store/schema_version.go (about) 1 package store 2 3 import "database/sql" 4 5 // SchemaVersion is the current schema version. It should be bumped every time a 6 // backwards-incompatible change has been made to the schema. 7 const SchemaVersion = 1 8 9 func init() { 10 initDB["record schema version"] = func(db *sql.DB) error { 11 _, err := db.Exec(`CREATE TABLE IF NOT EXISTS schema_version (version integer); INSERT INTO schema_version (version) VALUES(?)`, SchemaVersion) 12 return err 13 } 14 } 15 16 // SchemaUpToDate returns whether the database has the current or newer version 17 // of the schema. 18 func SchemaUpToDate(db *sql.DB) bool { 19 var v int 20 row := db.QueryRow(`SELECT version FROM schema_version`) 21 return row.Scan(&v) == nil && v >= SchemaVersion 22 }