my-website-v2/database/README.md

44 lines
739 B
Markdown

# Database
You can set environment variables either through the command line, the Nix flake (if you are running nix/NixOS), _or_ the `.env` file
## Create migration database
Run:
```
sqlx database create
```
Only run this if the `DATABASE_URL` environment variable is set (with the `postgres://` protocol) and if the database migration has _not_ been set up yet.
## Create a new migration file
Run:
```
sqlx migrate add -r <name>
```
where `<name>` is the name of the database file name given.
This new migration will be placed in the `migrations/` directory.
## Run the migrations
Run:
```
sqlx migrate run
```
to run the _all_ migrations.
To revert migraitons:
```
sqlx migrate revert
```
to rollback (all?) migrations.