Beispiel #1
0
func (r *Runner) invokeMigration(isTest bool, m Migration, c *spiffy.DbConnection, optionalTx ...*sql.Tx) (err error) {
	defer func() {
		if r := recover(); r != nil {
			err = fmt.Errorf("%v", err)
		}
	}()

	if m.IsTransactionIsolated() {
		err = m.Apply(c, spiffy.OptionalTx(optionalTx...))
		return
	}

	var tx *sql.Tx
	tx, err = c.Begin()
	if err != nil {
		return err
	}
	defer func() {
		if err == nil {
			err = exception.Wrap(tx.Commit())
		} else {
			err = exception.WrapMany(err, exception.New(tx.Rollback()))
		}
	}()
	err = m.Apply(c, tx)
	return
}
Beispiel #2
0
// Test runs the data file reader and then rolls-back the txn.
func (dfr *DataFileReader) Test(c *spiffy.DbConnection, optionalTx ...*sql.Tx) (err error) {
	tx, err := c.Begin()
	if err != nil {
		return
	}
	defer func() {
		if r := recover(); r != nil {
			err = fmt.Errorf("%v", err)
		}
		if err == nil {
			dfr.logger.Applyf(dfr, "done!")
		} else {
			dfr.logger.Errorf(dfr, err)
		}
		tx.Rollback()
	}()
	err = dfr.invoke(c, tx)
	return
}