jackc / tern

The SQL Fan's Migrator
MIT License
925 stars 68 forks source link

Small bug with file suffixes (duplicate sql suffix) #33

Closed anton7r closed 2 years ago

anton7r commented 3 years ago

This probably is not considered a bug but it is a small inconvinience nevertheless and it is at the end the user's fault anyway.

when creating a new migration with the tern new command if you accidentally write the .sql suffix yourself then the file name will have the .sql suffix twice

Example

when running the following command:

tern new create_user.sql

the file it would create would be named: 001_create_user.sql.sql

pscheid92 commented 2 years ago

Yes, I fell for this, too. Frankly, I'm not sure if we should introduce some magic to prevent this 🤔 The implementation would be easy (naively thought). But should we do it?

https://github.com/jackc/tern/blob/master/main.go#L358

    name := args[0]
    if strings.HasSuffix(name, ".sql") {
        name = name[:len(name)-4]
    }

What do you think, @jackc?

jackc commented 2 years ago

🤷

It is a simple change. But the current behavior informs the user that they don't need to type the extra four characters. With the auto fix someone could use tern indefinitely and not realize they are typing too much. (I'm big on saving keystrokes.)

I don't feel strongly either way. Definitely a bike shed to debate it very much. If anyone feels strongly enough about it to make a PR I guess I'll merge it.

pscheid92 commented 2 years ago

On second thought, I think you're right 👍 😇