Skip to content

Commit 23635d4

Browse files
committed
add version in Migration rolled back log
1 parent f075972 commit 23635d4

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-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, err)
95+
rollbackAndLog(c, currentMigration, sqlTx, err)
9696

9797
return
9898
}

pkg/gofr/migration/sql.go

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

102-
func rollbackAndLog(c *container.Container, tx *gofrSql.Tx, err error) {
102+
func rollbackAndLog(c *container.Container, version int64, tx *gofrSql.Tx, err error) {
103103
c.Logger.Error(err)
104104

105105
if tx == nil {
@@ -110,22 +110,22 @@ func rollbackAndLog(c *container.Container, tx *gofrSql.Tx, err error) {
110110
c.Logger.Error("unable to rollback transaction: %v", err)
111111
}
112112

113-
c.Logger.Error("Migration rolled back")
113+
c.Logger.Errorf("Migration %v rolled back", version)
114114
}
115115

116116
func sqlPostRun(c *container.Container, tx *gofrSql.Tx, currentMigration int64, start time.Time) {
117117
switch c.SQL.Driver().(type) {
118118
case *mysql.MySQLDriver:
119119
err := insertMigrationRecord(tx, insertGoFrMigrationRowMySQL, currentMigration, start)
120120
if err != nil {
121-
rollbackAndLog(c, tx, err)
121+
rollbackAndLog(c, currentMigration, tx, err)
122122

123123
return
124124
}
125125
case *pq.Driver:
126126
err := insertMigrationRecord(tx, insertGoFrMigrationRowPostgres, currentMigration, start)
127127
if err != nil {
128-
rollbackAndLog(c, tx, err)
128+
rollbackAndLog(c, currentMigration, tx, err)
129129

130130
return
131131
}

0 commit comments

Comments
 (0)