Skip to content

Global transaction does not work #74

Description

@jayschwa

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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