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

Creating two migrations at the same time #707

Open
0legovich opened this issue Feb 29, 2024 · 5 comments · May be fixed by #708
Open

Creating two migrations at the same time #707

0legovich opened this issue Feb 29, 2024 · 5 comments · May be fixed by #708
Labels

Comments

@0legovich
Copy link

When creating a migration file, goose adds a prefix in timestamp format with precision to the second. If you run the goose create command twice in a second, you will get unexpected behavior:

➜  goose create test
2024/02/29 16:39:34 Created new file: 20240229133934_test.go
➜  goose create test
2024/02/29 16:39:34 goose run: failed to create migration file: %!w(<nil>)

Error in the line https://github.com/pressly/goose/blob/master/create.go#L61

To be honest with the user, I think it is necessary to return an error indicating that such a file already exists.

@0legovich 0legovich linked a pull request Feb 29, 2024 that will close this issue
@mfridman
Copy link
Collaborator

mfridman commented Mar 1, 2024

To be honest with the user, I think it is necessary to return an error indicating that such a file already exists.

Good catch, we should certainly expose a better error like "file already exists".

@mfridman mfridman added the bug label Aug 24, 2024
@TomerShor
Copy link

@mfridman is there any option for a version prefix other than timestamp?
The docs recommend using sequential versions but is it supported OOB or should we manually change them?

@mfridman
Copy link
Collaborator

Yep, goose supports both timestamp (effectively very large numbers) and sequential numbers.

goose create some_file sql -s                    
2024/12/31 08:17:19 Created new file: 00001_some_file.sql

The -s flag instructs goose to create "sequential"-ly numbered migrations. The leading 0's are there for alignment, can be 01, 001, 0001, the default is 5 digits.

@TomerShor
Copy link

@mfridman thanks!
Is the 5-digit padding also configurable?

@mfridman
Copy link
Collaborator

mfridman commented Dec 31, 2024

It's not configurable via the goose CLI (at least not today, something we might consider if there's enough demand).

There is the goose.CreateWithTemplate if you're using it as a library.

In another project I worked on we just create a 00N.sql files with bash. Lots of options.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants