From 6584b37a22852865297145862c255bd8391e4905 Mon Sep 17 00:00:00 2001 From: genofire Date: Wed, 14 Jul 2021 16:14:51 +0200 Subject: [PATCH] CreateTable on Rollback This Library should not crash on rollback (maybe define an extra Error would be an alternative) --- gormigrate.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/gormigrate.go b/gormigrate.go index cba54eb..6f99063 100644 --- a/gormigrate.go +++ b/gormigrate.go @@ -250,6 +250,10 @@ func (g *Gormigrate) RollbackLast() error { g.begin() defer g.rollback() + + if err := g.createMigrationTableIfNotExists(); err != nil { + return err + } lastRunMigration, err := g.getLastRunMigration() if err != nil { @@ -275,6 +279,10 @@ func (g *Gormigrate) RollbackTo(migrationID string) error { g.begin() defer g.rollback() + + if err := g.createMigrationTableIfNotExists(); err != nil { + return err + } for i := len(g.migrations) - 1; i >= 0; i-- { migration := g.migrations[i] @@ -314,6 +322,10 @@ func (g *Gormigrate) getLastRunMigration() (*Migration, error) { func (g *Gormigrate) RollbackMigration(m *Migration) error { g.begin() defer g.rollback() + + if err := g.createMigrationTableIfNotExists(); err != nil { + return err + } if err := g.rollbackMigration(m); err != nil { return err