mirror of
https://github.com/StarFleetCPTN/GoMFT.git
synced 2026-09-08 15:41:20 +02:00
fix: Improve migration process by handling potential leftover temporary tables
- Added logic to drop any existing temporary tables from previous failed migration runs before renaming the current table. - Enhanced error logging to provide warnings if the drop operation fails, ensuring smoother migration execution. https://github.com/StarFleetCPTN/GoMFT/issues/72
This commit is contained in:
@@ -178,6 +178,12 @@ func AlterBooleanDefaults() *gormigrate.Migration {
|
||||
fmt.Printf("Recreating table %s...\n", tableName)
|
||||
oldTableName := fmt.Sprintf("_%s_old", tableName)
|
||||
|
||||
// Drop the old temp table if it exists from a previous failed run
|
||||
if err := tx.Exec(fmt.Sprintf("DROP TABLE IF EXISTS %s", oldTableName)).Error; err != nil {
|
||||
// Log the error but proceed, as the rename might still work or fail for the intended reason
|
||||
fmt.Printf("Warning: failed to drop potential leftover table %s: %v\n", oldTableName, err)
|
||||
}
|
||||
|
||||
// Rename old table
|
||||
if err := tx.Exec(fmt.Sprintf("ALTER TABLE %s RENAME TO %s", tableName, oldTableName)).Error; err == nil {
|
||||
fmt.Printf("Renamed %s to %s.\n", tableName, oldTableName)
|
||||
|
||||
Reference in New Issue
Block a user