Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UseTransaction should be true by default #221

Open
qustavo opened this issue May 30, 2024 · 0 comments
Open

UseTransaction should be true by default #221

qustavo opened this issue May 30, 2024 · 0 comments

Comments

@qustavo
Copy link

qustavo commented May 30, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant