Skip to content

UseTransaction should be true by default #221

@qustavo

Description

@qustavo

I have a mult-steps migration like:

return &gormigrate.Migration{
	Migrate: func(tx *gorm.DB) error {
		// This creates the table successfully
		if err := tx.Migrator().CreateTable("table1"); err != nil {
			return err
		}

		// Failure happens here
		return migrator.CreateTable("table2")
	},
}

Running this result in a partial failure; part of the migration is executed with no problem but it fails after.
The result is that I end up with a corrupt migration state. Since this can happen and can lead to potential bugs and or manual intervention to correct the db state, I believe that by default migrations should run inside a tx unless it is stated otherwise.
This will be simply fixed by making DefaultConfiguration return UseTransaction: true

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions