Skip to content

Commit f075972

Browse files
committed
log errors as well when migrations are rolled back
1 parent a0151e2 commit f075972

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

pkg/gofr/migration/migration.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func Run(migrationsMap map[int64]Migrate, c *container.Container) {
9292

9393
err = migrationsMap[currentMigration].UP(datasource)
9494
if err != nil {
95-
rollbackAndLog(c, sqlTx)
95+
rollbackAndLog(c, sqlTx, err)
9696

9797
return
9898
}

pkg/gofr/migration/sql.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ func insertMigrationRecord(tx *gofrSql.Tx, query string, version int64, startTim
9999
return err
100100
}
101101

102-
func rollbackAndLog(c *container.Container, tx *gofrSql.Tx) {
102+
func rollbackAndLog(c *container.Container, tx *gofrSql.Tx, err error) {
103+
c.Logger.Error(err)
104+
103105
if tx == nil {
104106
return
105107
}
@@ -108,22 +110,22 @@ func rollbackAndLog(c *container.Container, tx *gofrSql.Tx) {
108110
c.Logger.Error("unable to rollback transaction: %v", err)
109111
}
110112

111-
c.Logger.Error("Migration transaction rolled back")
113+
c.Logger.Error("Migration rolled back")
112114
}
113115

114116
func sqlPostRun(c *container.Container, tx *gofrSql.Tx, currentMigration int64, start time.Time) {
115117
switch c.SQL.Driver().(type) {
116118
case *mysql.MySQLDriver:
117119
err := insertMigrationRecord(tx, insertGoFrMigrationRowMySQL, currentMigration, start)
118120
if err != nil {
119-
rollbackAndLog(c, tx)
121+
rollbackAndLog(c, tx, err)
120122

121123
return
122124
}
123125
case *pq.Driver:
124126
err := insertMigrationRecord(tx, insertGoFrMigrationRowPostgres, currentMigration, start)
125127
if err != nil {
126-
rollbackAndLog(c, tx)
128+
rollbackAndLog(c, tx, err)
127129

128130
return
129131
}

0 commit comments

Comments
 (0)