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

[cli] Feature: Add a baseline command to fake apply migrations up to a certain version #911

Open
mehcode opened this issue Dec 19, 2020 · 2 comments
Labels
enhancement New feature or request migrations Proposals or bugs involving migrations proposal

Comments

@mehcode
Copy link
Member

mehcode commented Dec 19, 2020

See #639 (comment)

@abonander
Copy link
Collaborator

abonander commented Dec 20, 2020

I don't know if we want it to be part of the baseline command or not but when developing a feature that modifies the database I realize I tend to do the following:

  • Write and run a migration for the schema changes I anticipate will be needed (new table, new columns in existing table, etc.)
  • Begin developing the feature
  • Realize I need to make more changes to the schema
  • Since the migration I just wrote hasn't been pushed to production, I prefer to modify it in-place and manually update the DB

But if the application uses sqlx::migrate!() it will die on startup because the migrations are out of sync with the database.

It's not that hard to just do openssl dgst -sha384 <migration file> and then update the hash in the _sqlx_migrations table but it would be nice to have a single command to do both.

I'm thinking we might want it to be separate from the baseline command because it's replacing the hash of a migration that's already run, but I'm not sure what I'd call it. sqlx migrate override?

@abonander
Copy link
Collaborator

abonander commented Feb 28, 2021

@mehcode

# mark <version> as applied if not already (error on hash mismatch)
sqlx migrate override --just=<version>

# mark <version> as applied, overwrite hash
sqlx migrate override -f --just=version

# mark all migrations up to and including <version> as applied (error on hash mismatch)
sqlx migrate override --up-to=<version>

# mark all migrations up to and including <version> as applied, overwrite mismatched hashes
sqlx migrate override -f --up-to=<version>

# mark all migrations as applied (error on hash mismatch)
sqlx migrate override --all

# mark all migrations as applied, overwrite mismatched hashes
sqlx migrate override -f --all

# starts a dialogue asking the user to select the target migration version (defaulting to latest), all/upto/just that version, and attempt to process the selected versions, asking to quit/skip/force on each that mismatches
sqlx migrate override

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request migrations Proposals or bugs involving migrations proposal
Projects
None yet
Development

No branches or pull requests

2 participants