Skip to content

fix creating concurrent migration file#708

Open
0legovich wants to merge 1 commit intopressly:mainfrom
0legovich:fix-create-migration-file-concurrent
Open

fix creating concurrent migration file#708
0legovich wants to merge 1 commit intopressly:mainfrom
0legovich:fix-create-migration-file-concurrent

Conversation

@0legovich
Copy link

Closes #707

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