mirror of
https://github.com/launchbadge/sqlx.git
synced 2026-03-23 18:40:24 +00:00
Add --source for migration subcommands (#1769)
This commit is contained in:
committed by
GitHub
parent
d3093d0b70
commit
c30a4a5d88
@@ -3,9 +3,9 @@
|
||||
SQLx's associated command-line utility for managing databases, migrations, and enabling "offline"
|
||||
mode with `sqlx::query!()` and friends.
|
||||
|
||||
### Install
|
||||
## Install
|
||||
|
||||
#### With Rust toolchain
|
||||
### With Rust toolchain
|
||||
|
||||
```bash
|
||||
# supports all databases supported by SQLx
|
||||
@@ -40,21 +40,36 @@ sqlx database create
|
||||
sqlx database drop
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
#### Create and run migrations
|
||||
|
||||
```bash
|
||||
$ sqlx migrate add <name>
|
||||
sqlx migrate add <name>
|
||||
```
|
||||
|
||||
Creates a new file in `migrations/<timestamp>-<name>.sql`. Add your database schema changes to
|
||||
this new file.
|
||||
|
||||
---
|
||||
|
||||
```bash
|
||||
$ sqlx migrate run
|
||||
sqlx migrate run
|
||||
```
|
||||
|
||||
Compares the migration history of the running database against the `migrations/` folder and runs
|
||||
any scripts that are still pending.
|
||||
|
||||
---
|
||||
|
||||
Users can provide the directory for the migration scripts to `sqlx migrate` subcommands with the `--source` flag.
|
||||
|
||||
```bash
|
||||
sqlx migrate info --source ../relative/migrations
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
#### 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:
|
||||
@@ -133,6 +148,7 @@ In order for sqlx to be able to find queries behind certain feature flags you ne
|
||||
on by passing arguments to rustc.
|
||||
|
||||
This is how you would turn all targets and features on.
|
||||
|
||||
```bash
|
||||
cargo sqlx prepare -- --all-targets --all-features
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user