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.
This commit is contained in:
Daan Sprenkels 2020-12-31 14:34:33 +01:00
parent f530a543f9
commit 3f09c1517d
1 changed files with 6 additions and 5 deletions

View File

@ -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 {