From 3c3e6e2bf932f7269d3d87112828be46f9babce9 Mon Sep 17 00:00:00 2001 From: talal hussain Date: Mon, 16 Oct 2023 12:47:10 +0500 Subject: [PATCH] fixed version number when migration is down --- collection.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/collection.go b/collection.go index 29c8d99..c053597 100644 --- a/collection.go +++ b/collection.go @@ -559,7 +559,7 @@ func (c *Collection) runUp(db DB, tx *pg.Tx, m *Migration) (int64, error) { }) } -func (c *Collection) runDown(db DB, tx *pg.Tx, m *Migration) (int64, error) { +func (c *Collection) runDown(db DB, tx *pg.Tx, m *Migration, newVersion int64) (int64, error) { if m.DownTx { db = tx } @@ -570,7 +570,7 @@ func (c *Collection) runDown(db DB, tx *pg.Tx, m *Migration) (int64, error) { return 0, err } } - return m.Version - 1, nil + return newVersion, nil }) } @@ -591,8 +591,10 @@ func (c *Collection) down(db DB, tx *pg.Tx, migrations []*Migration, oldVersion } var m *Migration + var newVersion int64 for i := len(migrations) - 1; i >= 0; i-- { mm := migrations[i] + newVersion = migrations[i-1].Version // get the version of migration to one more -1 if mm.Version <= oldVersion { m = mm break @@ -602,7 +604,7 @@ func (c *Collection) down(db DB, tx *pg.Tx, migrations []*Migration, oldVersion if m == nil { return oldVersion, nil } - return c.runDown(db, tx, m) + return c.runDown(db, tx, m, newVersion) } func (c *Collection) schemaExists(db DB) (bool, error) {