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

Global transaction does not work #74

Open
jayschwa opened this issue Jul 30, 2019 · 0 comments
Open

Global transaction does not work #74

jayschwa opened this issue Jul 30, 2019 · 0 comments

Comments

@jayschwa
Copy link

For running all migrations in a global transaction, the README suggests code like the following:

var oldVersion, newVersion int64
err = db.RunInTransaction(func(tx *pg.Tx) error {
	oldVersion, newVersion, err = migrations.Run(tx, flag.Args()...)
	return err
})
if err != nil {
	panic(err)
}

After upgrading from v6.2.0 to v6.7.3, the code now fails:

BEGIN
SELECT count(*) FROM "pg_tables" WHERE (schemaname = 'public') AND (tablename = 'gopg_migrations')
SET idle_in_transaction_session_timeout = 0
LOCK TABLE gopg_migrations

		SELECT version FROM gopg_migrations ORDER BY id DESC LIMIT 1
	
COMMIT
panic: pg: transaction has already been committed or rolled back

I don't see nested transactions in the output, but it does look like the code will attempt to create a transaction for each migration: https://github.com/go-pg/migrations/blob/master/collection.go#L454

gpmidi added a commit to gpmidi/TapeStats that referenced this issue Jan 19, 2021
geigi added a commit to geigi/radau that referenced this issue Jul 7, 2021
With the introduction of go modules we needed a newer version of go-pg.
This version introduced some changes in the schema definition as well as in the migration process.
Running the migration inside a global transaction is currently not possible and therefor split into transactions for each migration (go-pg/migrations#74).
strifel pushed a commit to FactoryCampus/radau that referenced this issue Feb 14, 2024
With the introduction of go modules we needed a newer version of go-pg.
This version introduced some changes in the schema definition as well as in the migration process.
Running the migration inside a global transaction is currently not possible and therefor split into transactions for each migration (go-pg/migrations#74).
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