- I have some code that needs to be run in a
Tx
like here - I generated a go sql migration as mentioned here in the official docs for
go goose
my questions are:
- when are these transactions actually
committed
to the database? - I forced the migrations to be committed with
tx.Commit()
. Here's my migration file in go:
func Up00002(tx *sql.Tx) error {
_, err := tx.Exec("UPDATE users SET username='admin' WHERE username='root';")
if err != nil {
return err
}
if err = tx.Commit(); err != nil {
return fmt.Errorf("error during committing the transaction: %w", err)
}
return nil
}
I am unable to run the above migration after the down
part as I get the ErrTxDone
(source) when I run them. I still want to run the go migration Up00002
multiple times (for testing). How can I do this? What am I doing wrong here?