db migration fixes
- fix offbyone for executing migrations - fix user_version setter not working - add one more migration for WIP weather table
This commit is contained in:
parent
62e162e939
commit
9280067d87
|
@ -65,7 +65,7 @@ func (tdb *TelemDb) GetVersion() (int, error) {
|
|||
}
|
||||
|
||||
func (tdb *TelemDb) SetVersion(version int) error {
|
||||
stmt := fmt.Sprintf("PRAGMA user_version %d", version)
|
||||
stmt := fmt.Sprintf("PRAGMA user_version = %d", version)
|
||||
_, err := tdb.db.Exec(stmt)
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -100,7 +100,7 @@ func RunMigrations(tdb *TelemDb) (finalVer int, err error) {
|
|||
if err != nil {
|
||||
return
|
||||
}
|
||||
for v := currentVer + 1; v < finalVer; v++ {
|
||||
for v := currentVer + 1; v <= finalVer; v++ {
|
||||
// attempt to get the "up" migration.
|
||||
mMap, ok := migrations[v]
|
||||
if !ok {
|
||||
|
|
|
@ -6,6 +6,8 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
// import just the first and second migrations to ensure stability.
|
||||
//
|
||||
//go:embed migrations/1_*.sql
|
||||
//go:embed migrations/2_*.sql
|
||||
var testFs embed.FS
|
||||
|
|
1
internal/db/migrations/3_weather_down.sql
Normal file
1
internal/db/migrations/3_weather_down.sql
Normal file
|
@ -0,0 +1 @@
|
|||
DROP TABLE "weather_station_logs";
|
6
internal/db/migrations/3_weather_up.sql
Normal file
6
internal/db/migrations/3_weather_up.sql
Normal file
|
@ -0,0 +1,6 @@
|
|||
CREATE TABLE "weather_station_logs" (
|
||||
"ts" INTEGER NOT NULL,
|
||||
"wind_speed" REAL,
|
||||
"ground speed" REAL,
|
||||
"heading" REAL
|
||||
);
|
Loading…
Reference in a new issue