A default goose go migration prepares a function providing an *sql.Tx
:
A transaction is provided, rather than the DB instance directly, since goose also needs to record the schema version within the same transaction. Each migration should run as a single transaction to ensure DB integrity, so it's good practice anyway.
I would like to write my migration using gorm migrations, but I’m not sure how to use the given transaction to that purpose. Here’s an example:
func Up_20151230135812(txn *sql.Tx) {
txn.CreateTable(&User{})
}
The build gives me txn.CreateTable undefined (type *sql.Tx has no field or method CreateTable)
as expected. How can I grab the transaction for use with gorm?