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

fix creating concurrent migration file #708

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

0legovich
Copy link

Closes #707

@@ -58,10 +58,15 @@ func CreateWithTemplate(db *sql.DB, dir string, tmpl *template.Template, name, m
}

path := filepath.Join(dir, filename)
if _, err := os.Stat(path); !os.IsNotExist(err) {
_, err := os.Stat(path)
if err != nil && !os.IsNotExist(err) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest replacing this with the code mentioned in the documentation to os.IsNotExist function
!errors.Is(err, fs.ErrNotExist)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also this code could be simplidfied in fort of fast failure:

_, err := os.Stat(path)
if err == nil {
	return fmt.Errorf("failed to create migration file: %w", os.ErrExist)
}

if !errors.Is(err, fs.ErrNotExist){
        return fmt.Errorf("failed to create migration file: %w", err)
}

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

Successfully merging this pull request may close these issues.

Creating two migrations at the same time
2 participants