diff --git a/internal/db/db.go b/internal/db/db.go index d30153f..0272ea3 100644 --- a/internal/db/db.go +++ b/internal/db/db.go @@ -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 } diff --git a/internal/db/migration.go b/internal/db/migration.go index b81e924..ef0c355 100644 --- a/internal/db/migration.go +++ b/internal/db/migration.go @@ -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 { diff --git a/internal/db/migration_test.go b/internal/db/migration_test.go index cfd935f..51e018b 100644 --- a/internal/db/migration_test.go +++ b/internal/db/migration_test.go @@ -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 diff --git a/internal/db/migrations/3_weather_down.sql b/internal/db/migrations/3_weather_down.sql new file mode 100644 index 0000000..1c4ad6b --- /dev/null +++ b/internal/db/migrations/3_weather_down.sql @@ -0,0 +1 @@ +DROP TABLE "weather_station_logs"; \ No newline at end of file diff --git a/internal/db/migrations/3_weather_up.sql b/internal/db/migrations/3_weather_up.sql new file mode 100644 index 0000000..839efcb --- /dev/null +++ b/internal/db/migrations/3_weather_up.sql @@ -0,0 +1,6 @@ +CREATE TABLE "weather_station_logs" ( + "ts" INTEGER NOT NULL, + "wind_speed" REAL, + "ground speed" REAL, + "heading" REAL +); \ No newline at end of file