8000 Default create extension to sql by smw1218 · Pull Request #53 · golang-migrate/migrate · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Default create extension to sql #53

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

Closed
wants to merge 1 commit into from

Conversation

smw1218
Copy link
@smw1218 smw1218 commented Jun 13, 2018

The default extension is left blank even though the parameter is optional. This produces a file that has no extension at all which then doesn't match the regexp in source/parse.go (a broken migration file name). Defaulting to .sql fixes this and matches your documentation.

@coveralls
Copy link
coveralls commented Jun 13, 2018

Pull Request Test Coverage Report for Build 89

  • 0 of 1 (0.0%) changed or added relevant line in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 46.58%

Changes Missing Coverage Covered Lines Changed/Added Lines %
cli/main.go 0 1 0.0%
Totals Coverage Status
Change from base Build 88: 0.0%
Covered Lines: 681
Relevant Lines: 1462

💛 - Coveralls

@dhui
Copy link
Member
dhui commented Jun 14, 2018

Thanks for opening a PR but using a default extension isn't the appropriate fix as there are other DBs migrate supports that aren't SQL.

A better approach is to present better error messages.

@smw1218
Copy link
Author
smw1218 commented Jun 14, 2018

My reasoning is that a "default" value is the one that works for most people. The empty string is clearly not a good default because it doesn't work for anyone and is just a bug.

I chose .sql because I'm guessing it is the most common option for your users of your project. This seems reasonable since all the documentation uses the .sql extension in examples. Obviously, if .sql worked for everyone, changing extension wouldn't be a CLI flag at all and the -ext flag should just be removed.

Your approach would make the -ext mandatory for the create call. IMHO, that would reduce the usability of the tool.

Feel free to close if you disagree or have a different solution, it's your party.

@dhui
Copy link
Member
8000 dhui commented Jun 15, 2018

It looks like we have the following solutions for this problem:

  1. Update docs and error messages to make this less confusing
  2. Make -ext a required parameter for the create command
  3. Make .sql the default extension
  4. Change source URL parsing to not require an extension

As suggested by @smw1218, I like the 2nd solution the most since it works the best with existing commands and docs and most migrations should have an extension anyways.

@smw1218 do you mind updating this PR to make the -ext flag required for the create command?

@dhui
Copy link
Member
dhui commented Jun 18, 2018

Flags in Go cannot be made mandatory, so I'll leave the default as the empty string and error if the extension is not specified.

@smw1218
Copy link
Author
smw1218 commented Jun 18, 2018

I still think it's a mistake to make a parameter mandatory when most users just want .sql
It makes the most common use cases + documentation more difficult. The only currently supported DB that doesn't use .sql is cassandra; and .sql works fine for cql files as well (you get decent syntax highlighting because cql is so similar to sql).

@dhui
Copy link
Member
dhui commented Jun 18, 2018

I disagree. It's not clear that most users are using SQL. Although most DBs supported by migrate use SQL, it's hard to say what the distribution of users using those DBs are as I don't have any data about the usage of migrate.

Making the -ext flag required for the create command is a formality since an extension is currently required by every command that reads migration files. Maintaining backwards compatibility is a goal of most releases, although it's less important for the create command since it's less likely to be scripted.

Evaluation of potential solutions

N Solution Backwards compatible? Improves usability? Notes
1 Update docs and error messages to make this less confusing 👍 😑 Reduce confusion but mistakes are likely to be made if docs aren't read e.g. would probably still have to rename/recreate migrations
2 Make -ext a required parameter for the create command 😑 👍 This is essentially the status quo. Technically it's not backwards compatible, but for all intents and purposes, it is.
3 Make .sql the default extension 😑 😑 Only makes life easier for SQL users
4 Change source URL parsing to not require an extension 👍 👍

Of the potential solutions listed above, the only one that best maintains backwards compatibility and improves usability is 4. However, I've currently implemented 2 instead of 4 since it keeps constraints instead of relaxing them, but I could go with either solution for the next release.

@smw1218 smw1218 closed this Jun 18, 2018
@dhui
Copy link
Member
dhui commented Jun 19, 2018

Solution 2 was implemented in v3.3.0

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.

3 participants
0