Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from migrant to sqlx-cli #29

Merged
merged 1 commit into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DATABASE_URL=sqlite:healthpi.db
5 changes: 2 additions & 3 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ jobs:
with:
components: clippy, rustfmt
- name: Install dependencies
run: sudo apt install libdbus-1-dev pkg-config && cargo install migrant --features sqlite
run: sudo apt install libdbus-1-dev pkg-config && cargo install sqlx-cli
- name: Run migration
working-directory: healthpi-db
run: migrant setup && migrant apply
run: sqlx database create && sqlx migrate run
- name: Check formatting
run: cargo fmt --check
- name: Cache cargo dependencies
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
/result

devices.csv
.env

*.db
*.db-wal
Expand Down
27 changes: 9 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,30 +45,21 @@ to be done one per device.

### Database setup

HealthPi uses [migrant](https://crates.io/crates/migrant) to manage database migrations.
At this point, you need to run the migrations manually. In order to do that,
you will have to install `migrant` cli with sqlite enabled. This also requires
`sqlite3` to be installed.
HealthPi uses [sqlx-cli](https://github.com/launchbadge/sqlx/blob/main/sqlx-cli/README.md)
to manage database migrations. At this point, you need to run the migrations manually.
sqlx-cli is included in the nix development shell, so you can set up the database by
running:

```
sudo apt install sqlite3 libsqlite3-dev
cargo install migrant --features sqlite
nix develop
sqlx database create
sqlx migrate run
```

After that you run the migration by simply executing:
If you do not want to use nix, you can install sqlx-cli with

```
cd healthpi-db; migrant setup; migrant apply; cd ..
```

You will also need to point healthpi-loader to the correct database by setting
an appropriate environment variable. The easiest way to do that is to create
a `.env` file with a `DATABASE_URL` variable set, pointing to an sqlite database
file. By default, `migrant` creates the database in the project root in a file
called `healthpi.db`. We suggest specifying an absolute path, like this:

```
echo DATABASE_URL=/home/pi/healthpi/healthpi.db > .env
cargo install sqlx-cli
```

Local development setup
Expand Down
12 changes: 0 additions & 12 deletions healthpi-db/Migrant.toml

This file was deleted.

2 changes: 1 addition & 1 deletion nix/shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ pkgs.mkShell {
inputsFrom = [ (pkgs.callPackage ./default.nix { inherit rust; }) ];

buildInputs = with pkgs; [
trunk
sqlx-cli
];
}
Loading