From f527f2fb384fbb9e73c749f3f19b2566f8e2b5b8 Mon Sep 17 00:00:00 2001 From: Daan Sprenkels Date: Thu, 17 Dec 2020 15:14:45 +0100 Subject: [PATCH] Automigrate when opening db --- cmd/rushlink/main.go | 6 ++++++ internal/db/paste_test.go | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/cmd/rushlink/main.go b/cmd/rushlink/main.go index 9494922..d21b000 100644 --- a/cmd/rushlink/main.go +++ b/cmd/rushlink/main.go @@ -6,6 +6,7 @@ import ( "gitea.hashru.nl/dsprenkels/rushlink" "gitea.hashru.nl/dsprenkels/rushlink/internal/db" + "github.com/pkg/errors" ) var ( @@ -26,6 +27,11 @@ func main() { log.Fatalln(err) } + migrate := db.Gormigrate(database) + if err := migrate.Migrate(); err != nil { + log.Fatal(errors.Wrap(err, "migrating database")) + } + go rushlink.StartMetricsServer(*metricsListen, database, filestore) rushlink.StartMainServer(*httpListen, database, filestore, *rootURL) } diff --git a/internal/db/paste_test.go b/internal/db/paste_test.go index 2d266db..26e7800 100644 --- a/internal/db/paste_test.go +++ b/internal/db/paste_test.go @@ -13,6 +13,10 @@ func OpenTemporaryDB() (*Database, error) { if err != nil { return nil, err } + migrate := Gormigrate(db) + if err := migrate.Migrate(); err != nil { + return nil, err + } return db, nil }