From ee7178ec1bec4a6bc75766bb256f1a6af7d0875e Mon Sep 17 00:00:00 2001 From: Erik Date: Fri, 1 Oct 2021 08:57:47 -0700 Subject: [PATCH] Add reverting instructions to README Instructions on reverting migrations are missing from the README. Here are some that others may find helpful. --- sqlx-cli/README.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/sqlx-cli/README.md b/sqlx-cli/README.md index f098dad8ab..90045cd3af 100644 --- a/sqlx-cli/README.md +++ b/sqlx-cli/README.md @@ -49,6 +49,40 @@ $ sqlx migrate run Compares the migration history of the running database against the `migrations/` folder and runs any scripts that are still pending. +#### Reverting Migrations + +If you would like to create _reversible_ migrations with corresponding "up" and "down" scripts, you use the `-r` flag when creating new migrations: + +```bash +$ sqlx migrate add -r +Creating migrations/20211001154420_.up.sql +Creating migrations/20211001154420_.down.sql +``` + +After that, you can run these as above: + +```bash +$ sqlx migrate run +Applied migrations/20211001154420 (32.517835ms) +``` + +And reverts work as well: + +```bash +$ sqlx migrate revert +Applied 20211001154420/revert +``` + +**Note**: attempting to mix "simple" migrations with reversible migrations with result in an error. + +```bash +$ sqlx migrate add +Creating migrations/20211001154420_.sql + +$ sqlx migrate add -r +error: cannot mix reversible migrations with simple migrations. All migrations should be reversible or simple migrations +``` + #### Enable building in "offline mode" with `query!()` Note: must be run as `cargo sqlx`.