hasura / hasura/graphql-engine

cli: check for inconsistent migrations before migrate apply

Open
#8,056 1 comment 0 reactions 0 assignees View on GitHub
c/cli c/migrations k/enhancement t/product-platform
Dominant language
TypeScript
Stars
32.1k
Forks
3k
PR merge metrics
PR metrics pending

Description

### Is your proposal related to a problem?

The CLI currently applies all unapplied migrations without ensuring the new migrations are consistent with already applied migrations. ie. it doesnt ensure if the migrations are incremental and all already applied migrations are also present in the list of migrations that are being applied.

This can cause issues when already applied migrations are squashed or if migrations of one project get applied on another project by mistake.

The motivation is to ensure the user is aware of any migration state inconsistency between the server and the local files system before updating any migrations state

### Describe the solution you'd like

The CLI should ensure that migrations are incremental, ie. all migrations that are already applied on a database exist in the list of migrations that are being applied before applying any new unapplied migrations or updating any migrations state

- The CLI by default can raise a warning/error (depending on the interactive mode) if it detects any migrations on the server that are not present in the migrations directory. In interactive mode the user can either choose to continue or abort the migrate apply.
- There can be a flag, `--skip-consistent-migrations-check`, to skip this check.
- Suggested warning/error should help explain the reason and how the user can get around it .e.g "Some migrations already applied on your database seem to be missing in the current migration list. Please check the migrations being applied or fix the migrations state of the database by deleting any irrelevant migrations using < command >". Or something on these lines that makes next steps clear
- The same logic should work for all commands migrate apply sub-commands like `--goto`, `--up`, `--down`, `--version` etc.

Contributor guide

Open the contributing guide

Research direction

Start at the CLI's migrate apply implementation and trace the --goto, --up, --down, and --version paths. Determine where applied server migrations are compared with local migrations before state changes; done means inconsistent migrations produce the specified warning or error, interactive mode can abort or continue, and --skip-consistent-migrations-check bypasses the check.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
cli, databases
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.