Tx
like herego goose
my questions are:
committed
to the database?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?
So, just going through their documentations here shows that the commit already happens in an AddMigrations
call - this is with transactions ofc and is handled internally by go goose
- pretty nice :)
The same is true for sql as well, as we see it here
The pkg also provides --no-transaction
option which we can use to have full control of the db
object - awesome!