Execute migrations in a transaction
This commit is contained in:
		
							parent
							
								
									3e164bcdfa
								
							
						
					
					
						commit
						e7ee10deb1
					
				| @ -100,8 +100,16 @@ func UpgradeFromXToY(db *sqlx.DB, x uint, y uint) { | |||||||
| 		fmt.Println((*migrations)[i]) | 		fmt.Println((*migrations)[i]) | ||||||
| 		fmt.Print(ColorReset) | 		fmt.Print(ColorReset) | ||||||
| 
 | 
 | ||||||
| 		db.MustExec((*migrations)[i]) | 		// Execute the migration in a transaction | ||||||
| 		db.MustExec("update db_version set version = ?", i+1) | 		tx, err := db.Beginx() | ||||||
|  | 		if err != nil { | ||||||
|  | 			panic(err) | ||||||
|  | 		} | ||||||
|  | 		tx.MustExec((*migrations)[i]) | ||||||
|  | 		tx.MustExec("update db_version set version = ?", i+1) | ||||||
|  | 		if err := tx.Commit(); err != nil { | ||||||
|  | 			panic(err) | ||||||
|  | 		} | ||||||
| 
 | 
 | ||||||
| 		fmt.Print(ColorYellow) | 		fmt.Print(ColorYellow) | ||||||
| 		fmt.Printf("Now at database schema version %d.\n", i+1) | 		fmt.Printf("Now at database schema version %d.\n", i+1) | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user