mirror of
https://github.com/StarFleetCPTN/GoMFT.git
synced 2026-11-01 18:00:26 +01: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:
1 parent
c52267bbb6
commit
7a54a83c8d
1 file changed
+6
@@ -178,6 +178,12 @@ func AlterBooleanDefaults() *gormigrate.Migration {
|
|||||||
fmt.Printf("Recreating table %s...\n", tableName)
|
fmt.Printf("Recreating table %s...\n", tableName)
|
||||||
oldTableName := fmt.Sprintf("_%s_old", 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
|
// Rename old table
|
||||||
if err := tx.Exec(fmt.Sprintf("ALTER TABLE %s RENAME TO %s", tableName, oldTableName)).Error; err == nil {
|
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)
|
fmt.Printf("Renamed %s to %s.\n", tableName, oldTableName)
|
||||||
|
|||||||
Reference in new issue
Block a user