From 3f09c1517dc35158e9f1cba046a6bbb13bdc1818 Mon Sep 17 00:00:00 2001 From: Daan Sprenkels Date: Thu, 31 Dec 2020 14:34:33 +0100 Subject: [PATCH] migrate: Fix 'no such table: migrations' err Apparently, if you CREATE TABLE inside of a transaction, and then (in the same transaction) do a SELECT on the same table before committing, the table will not exist yet. Now we do the migration in two steps: first initialize the schema; then migrate the data. --- cmd/rushlink-migrate-db/main.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/cmd/rushlink-migrate-db/main.go b/cmd/rushlink-migrate-db/main.go index 4650994..35f0f53 100644 --- a/cmd/rushlink-migrate-db/main.go +++ b/cmd/rushlink-migrate-db/main.go @@ -33,14 +33,15 @@ func main() { log.Fatalln(err) } + // Migrate database schema + m := db.Gormigrate(sqlDB) + if err := m.MigrateTo("202010251337"); err != nil { + log.Fatalln(err) + } + // Migrate all files in filestorage if err := sqlDB.Transaction(func(sqlTx *gorm.DB) error { return boltDB.Bolt.View(func(boltTx *bolt.Tx) error { - // Migrate database schema - m := db.Gormigrate(sqlTx) - if err := m.MigrateTo("202010251337"); err != nil { - return err - } // Migrate all the file uploads allFUs, err := boltdb.AllFileUploads(boltTx) if err != nil {