Skip to content

Commit efde5c5

Browse files
authored
Add reverting instructions to README (launchbadge#1468)
Instructions on reverting migrations are missing from the README. Here are some that others may find helpful.
1 parent 8561891 commit efde5c5

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

sqlx-cli/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,40 @@ $ sqlx migrate run
4949
Compares the migration history of the running database against the `migrations/` folder and runs
5050
any scripts that are still pending.
5151

52+
#### Reverting Migrations
53+
54+
If you would like to create _reversible_ migrations with corresponding "up" and "down" scripts, you use the `-r` flag when creating new migrations:
55+
56+
```bash
57+
$ sqlx migrate add -r <name>
58+
Creating migrations/20211001154420_<name>.up.sql
59+
Creating migrations/20211001154420_<name>.down.sql
60+
```
61+
62+
After that, you can run these as above:
63+
64+
```bash
65+
$ sqlx migrate run
66+
Applied migrations/20211001154420 <name> (32.517835ms)
67+
```
68+
69+
And reverts work as well:
70+
71+
```bash
72+
$ sqlx migrate revert
73+
Applied 20211001154420/revert <name>
74+
```
75+
76+
**Note**: attempting to mix "simple" migrations with reversible migrations with result in an error.
77+
78+
```bash
79+
$ sqlx migrate add <name1>
80+
Creating migrations/20211001154420_<name>.sql
81+
82+
$ sqlx migrate add -r <name2>
83+
error: cannot mix reversible migrations with simple migrations. All migrations should be reversible or simple migrations
84+
```
85+
5286
#### Enable building in "offline mode" with `query!()`
5387

5488
Note: must be run as `cargo sqlx`.

0 commit comments

Comments
 (0)