Skip to content

Commit d383cad

Browse files
dont use tx for the drop and swap (#5)
1 parent 7d2af2d commit d383cad

File tree

1 file changed

+5
-16
lines changed

1 file changed

+5
-16
lines changed

main.go

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -437,15 +437,9 @@ func main() {
437437
os.Exit(0)
438438
}
439439

440-
tx, cancel, err := db.BeginTx()
441-
defer cancel()
442-
if err != nil {
443-
panic(err)
444-
}
445-
446440
// stop foreign key checks
447441
log.Println("disabling foreign key checks for our connection")
448-
err = tx.Exec("set foreign_key_checks=0")
442+
err = db.Exec("set foreign_key_checks=0")
449443
if err != nil {
450444
panic(err)
451445
}
@@ -471,7 +465,7 @@ func main() {
471465

472466
// drop the old table now that our temp table is done
473467
log.Println("dropping the original table")
474-
err = tx.Exec("drop table if exists`" + tableName + "`")
468+
err = db.Exec("drop table if exists`" + tableName + "`")
475469
if err != nil {
476470
panic(err)
477471
}
@@ -481,15 +475,15 @@ func main() {
481475
// comma and adding the word "add" at the beginning of each line
482476
if len(constraints) != 0 {
483477
log.Println("adding constraints")
484-
err = tx.Exec("alter table`" + tempTableName + "`" + strings.ReplaceAll(strings.TrimLeft(constraints, ","), "\n", "\nadd"))
478+
err = db.Exec("alter table`" + tempTableName + "`" + strings.ReplaceAll(strings.TrimLeft(constraints, ","), "\n", "\nadd"))
485479
if err != nil {
486480
panic(err)
487481
}
488482
}
489483

490484
for _, r := range triggers {
491485
log.Println("adding original triggers")
492-
err = tx.Exec(renameTriggerTable(r.CreateMySQL, tempTableName))
486+
err = db.Exec(renameTriggerTable(r.CreateMySQL, tempTableName))
493487
if err != nil {
494488
panic(err)
495489
}
@@ -503,12 +497,7 @@ func main() {
503497
// if you're doing this live, there *is* some down time, but other tools handle this the same
504498
// way, so I don't think it's unreasonable if we do the same
505499
log.Println("renaming temp table")
506-
err = tx.Exec("alter table`" + tempTableName + "`rename`" + tableName + "`")
507-
if err != nil {
508-
panic(err)
509-
}
510-
511-
err = tx.Commit()
500+
err = db.Exec("alter table`" + tempTableName + "`rename`" + tableName + "`")
512501
if err != nil {
513502
panic(err)
514503
}

0 commit comments

Comments
 (0)