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

duplicate key value violates unique constraint "pg_type_typname_nsp_index" #55

Closed
dotchev opened this issue Jun 15, 2018 · 10 comments
Closed

Comments

@dotchev
Copy link
Contributor

dotchev commented Jun 15, 2018

We hit an error in our tests similar to #235

pq: duplicate key value violates unique constraint "pg_type_typname_nsp_index" in line 0: CREATE TABLE "schema_migrations" (version bigint not null primary key, dirty boolean not null)

What bothers me is that this is not ErrLocked. So it seems like the lock does not work as expected.
Or do I get it wrong?
We use Postgres and we call it like this

func updateSchema(db *sqlx.DB) error {
	driver, err := migratepg.WithInstance(db.DB, &migratepg.Config{})
	if err != nil {
		return err
	}
	m, err := migrate.NewWithDatabaseInstance("file://storage/postgres/migrations", "postgres", driver)
	if err != nil {
		return err
	}
	err = m.Up()
	if err == migrate.ErrNoChange {
		logrus.Debug("Database schema already up to date")
		err = nil
	}
	return err
}

We use migrate ver 3.2.0
We use pq driver

@dhui
Copy link
Member

dhui commented Jun 15, 2018

Are you able to reproduce the issue using the master branch?

There's an fix to the postgres db driver that'll be in the next release: #13

@dotchev
Copy link
Contributor Author

dotchev commented Jun 18, 2018

We still use the old code. We will try to reproduce with the latest master.

@dhui
Copy link
Member

dhui commented Jun 19, 2018

FYI, the postgres db driver fix I mentioned above is now in the latest release (v3.3.0)

@dhui
Copy link
Member

dhui commented Jul 11, 2018

@dotchev Is this still an issue w/ the latest release?

@nareshov
Copy link

nareshov commented Aug 1, 2018

@dhui i'm facing the same issue also when using the latest code (with go get -u -d github.com/golang-migrate/migrate/cli).

when invoked as follows:

% migrate -path /go/src/github.com/XYZ/abc/platform/tools/migrations/pgsql/platform/guardian -database 'postgres://u:p@localhost:5432/platform_test?sslmode=disable' down

@dhui
Copy link
Member

dhui commented Sep 20, 2018

Does anyone have steps to reproduce this?

Was there an old migrate process/connection that didn't support Postgres advisory locks?
Also, there's a bugfix in the latest release the correctly closes dangling DB connections in Postgres that might help.

tsenart pushed a commit to sourcegraph/sourcegraph that referenced this issue Jan 11, 2019
This commit introduces an isolated atomic migrations test command to
reliably reproduce these issues:

- golang-migrate/migrate#55
- #1491
@tsenart
Copy link
Contributor

tsenart commented Jan 11, 2019

Hello!

Here's a reproducible test command that runs into this. We're using v4.1.0.

@tsenart
Copy link
Contributor

tsenart commented Jan 11, 2019

The problem seems to be that func (*Postgres) ensureVersionTable() error isn't atomic.

tsenart pushed a commit to tsenart/migrate that referenced this issue Jan 11, 2019
This commit makes `ensureVersionTable` atomic.

Fixes golang-migrate#55
@tsenart
Copy link
Contributor

tsenart commented Jan 11, 2019

This commit doesn't seem to fix it unfortunately: tsenart@f6caf3e

Nor wrapping it all in a transaction.

tsenart pushed a commit to tsenart/migrate that referenced this issue Jan 11, 2019
tsenart pushed a commit to tsenart/migrate that referenced this issue Jan 13, 2019
tsenart pushed a commit to tsenart/migrate that referenced this issue Jan 15, 2019
@dhui dhui closed this as completed in #150 Jan 15, 2019
@dhui
Copy link
Member

dhui commented Jan 15, 2019

Fix is in master. I'll cut at new release with this fix in ~1 week.

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

4 participants