mirror of
https://github.com/launchbadge/sqlx
synced 2024-11-10 06:24:16 +00:00
Add reverting instructions to README (#1468)
Instructions on reverting migrations are missing from the README. Here are some that others may find helpful.
This commit is contained in:
parent
8561891474
commit
efde5c507f
1 changed files with 34 additions and 0 deletions
|
@ -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 <name>
|
||||
Creating migrations/20211001154420_<name>.up.sql
|
||||
Creating migrations/20211001154420_<name>.down.sql
|
||||
```
|
||||
|
||||
After that, you can run these as above:
|
||||
|
||||
```bash
|
||||
$ sqlx migrate run
|
||||
Applied migrations/20211001154420 <name> (32.517835ms)
|
||||
```
|
||||
|
||||
And reverts work as well:
|
||||
|
||||
```bash
|
||||
$ sqlx migrate revert
|
||||
Applied 20211001154420/revert <name>
|
||||
```
|
||||
|
||||
**Note**: attempting to mix "simple" migrations with reversible migrations with result in an error.
|
||||
|
||||
```bash
|
||||
$ sqlx migrate add <name1>
|
||||
Creating migrations/20211001154420_<name>.sql
|
||||
|
||||
$ sqlx migrate add -r <name2>
|
||||
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`.
|
||||
|
|
Loading…
Reference in a new issue