hasura / hasura/graphql-engine
CLI: `hasura migrate apply --down` could validate the argument value and abort if it's absurdly big
- Dominant language
- TypeScript
- Stars
- 32.1k
- Forks
- 3k
- PR merge metrics
- PR metrics pending
Description
### Is your proposal related to a problem?
Recently I meant to run this command:
```
hasura migrate apply --type=down --version=1659058116550
```
But recalling the flags from memory, I accidentally ran this command instead:
```
hasura migrate apply --down=1659058116550
```
This was interpreted as wanting to go down N migrations where N = `1659058116550`. I think it's safe to assume that is _never_ what the operator intended.
Luckily, this was in a dev environment. That's actually why I didn't use `--dry-run` first. But it still caused a headache. Even though I killed the command after 5 or 10 seconds (when I realized what was going on), it had time to get the database into an invalid state. (And not just a state of bad migrations. It was a `pgaudit stack is not empty` error. But since it was just a dev database, I was able to roll back a day then just the correct migration commands and things were fine.)
Human errors are inevitable and these flags can be confused, so I think this is a good opportunity for some validation.
### Describe the solution you'd like
Perhaps `--down`[^1] could have a guard on this number, and if it's above some threshold it would require confirmation. The number could be, say, the seconds-since-the-epoch when the Hasura project was started.
[^1]: (... and perhaps `--up` but the impact would be smaller, since there won't be so many up-migrations that could be applied)
### Describe alternatives you've considered
(Easier for me to phrase as questions)
* Should it require _interactive_ confirmation in that event, or just an additional flag?
* Should it just refuse to proceed at all, since it's so unlikely that it could be intended?
### If the feature is approved, would you be willing to submit a PR?
Yes.
Contributor guide
Assessment
This issue has not been assessed yet.