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

[Question] How to check if migration shoule be applied? #331

Closed
kkocel opened this issue Jan 26, 2020 · 2 comments
Closed

[Question] How to check if migration shoule be applied? #331

kkocel opened this issue Jan 26, 2020 · 2 comments
Labels
duplicate This issue or pull request already exists

Comments

@kkocel
Copy link

kkocel commented Jan 26, 2020

I want to use migrate in my tests setup.

I have following code:

	driver, err := postgres.WithInstance(db, &postgres.Config{})
	if err != nil {
		return err
	}
	sqltest.WaitForDB(db)
	m, err := migrate.NewWithDatabaseInstance(
		"file://"+path,
		dbName,
		driver)
	if err != nil  {
		return errors.Wrap(err, "cannot do migration")
	}

	err = m.Up()
	return err

The problem is when I apply m.Up() I get error -no change. How I can check if migration is feasible and then not apply migration?

@dhui dhui added the duplicate This issue or pull request already exists label Jan 26, 2020
@dhui
Copy link
Member

dhui commented Jan 26, 2020

You can check if the returned error is ErrNoChange.
For more info, see: #100 (comment)

It's hard to find the duplicate issue for this, but updating this PR should help prevent duplicates from being filed in the future.

@kkocel
Copy link
Author

kkocel commented Jan 27, 2020

Ok, thanks for info, I'll handle it in the same way.

@kkocel kkocel closed this as completed Jan 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants