Skip to content
This repository was archived by the owner on Jan 2, 2026. It is now read-only.

Commit a042560

Browse files
committed
feat: provide database access for pre-commit
1 parent 383fd92 commit a042560

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

.github/workflows/pre-commit.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,23 @@ jobs:
1515
runs-on: ubuntu-latest
1616
steps:
1717
- uses: actions/checkout@v4
18+
- uses: Swatinem/rust-cache@9d47c6ad4b02e050fd481d890b2ea34778fd09d6
19+
with:
20+
cache-all-crates: "true"
21+
- name: Setup PostgreSQL for Linux/macOS/Windows
22+
uses: ikalnytskyi/action-setup-postgres@v7
23+
id: postgres
24+
with:
25+
postgres-version: 17
26+
- name: "Install dependencies, prepare database"
27+
env:
28+
DATABASE_URL: ${{ steps.postgres.outputs.connection-uri }}
29+
run: |
30+
cargo install -f -q sqlx-cli
31+
cargo sqlx migrate run
1832
- uses: actions/setup-python@v5
1933
with:
2034
python-version: "3.13"
2135
- uses: pre-commit/action@576ff52938d158a24ac7e009dfa94b1455e7df99
36+
env:
37+
DATABASE_URL: ${{ steps.postgres.outputs.connection-uri }}

src/main.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use std::str::FromStr;
1515

1616
use clap::Parser;
1717
use log::{LevelFilter, debug, error, info, trace};
18+
use polyproto::key;
1819
use sqlx::query_scalar;
1920

2021
/// Module housing the HTTP API routes and functionality
@@ -105,16 +106,16 @@ async fn main() -> StdResult<()> {
105106
};
106107
let keys_in_table =
107108
query_scalar!("SELECT COUNT(*) FROM api_keys").fetch_one(&database.pool).await?;
108-
if let Some(number) = keys_in_table
109-
&& number >= 1
110-
{
111-
} else {
112-
let api_key =
113-
api_keys::add_api_key_to_database(&ApiKey::new_random(&mut rand::rng()), &database)
114-
.await?;
115-
info!("Added an API key to the database, since none were available: {api_key}");
116-
info!("Save this API key, as it will not be shown again on future starts.");
117-
}
109+
match keys_in_table {
110+
Some(0) | None => {
111+
let api_key =
112+
api_keys::add_api_key_to_database(&ApiKey::new_random(&mut rand::rng()), &database)
113+
.await?;
114+
info!("Added an API key to the database, since none were available: {api_key}");
115+
info!("Save this API key, as it will not be shown again on future starts.");
116+
}
117+
_ => (),
118+
};
118119

119120
Ok(())
120121
}

0 commit comments

Comments
 (0)