Check prepare db in CI (vibe-kanban) (#1423)

* Done! Here's a summary of the changes:

1. **`scripts/prepare-db.js`** - Added `--check` flag support that runs `cargo sqlx prepare --check` instead of `cargo sqlx prepare`

2. **`package.json`** - Added new script:
   ```json
   "prepare-db:check": "node scripts/prepare-db.js --check"
   ```

3. **`.github/workflows/test.yml`** - Added `npm run prepare-db:check` to the Checks step

The check will verify that the `.sqlx/` cached query metadata is up-to-date with the actual SQL queries in the codebase. If a developer modifies a SQL query but forgets to run `npm run prepare-db`, the CI will fail.

* Fix image queries

* Done! Added check mode support to the remote script:

1. **`crates/remote/scripts/prepare-db.sh`** - Added `--check` flag support that runs `cargo sqlx prepare --check` when passed

2. **`package.json`** - Added:
   ```json
   "remote:prepare-db:check": "cd crates/remote && bash scripts/prepare-db.sh --check"
   ```

Note: I didn't add `remote:prepare-db:check` to CI since it requires PostgreSQL (`initdb`, `pg_ctl`) which may not be available on the CI runner. The local SQLite-based `prepare-db:check` is already in CI. Let me know if you'd like to add the remote check to CI as well (would require installing PostgreSQL in the workflow).

* Add remote db check to workflow

* Added a step to install `sqlx-cli` with both SQLite and PostgreSQL features. The Rust cache should help speed up subsequent runs since it caches installed crates.

* Done! All three files updated to use Rust `1.89.0`:

1. `rust-toolchain.toml` - `channel = "1.89.0"`
2. `.github/workflows/test.yml` - `toolchain: 1.89.0`
3. `.github/workflows/pre-release.yml` - `RUST_TOOLCHAIN: 1.89.0`

This should fix the `zerocopy` AVX512 compile error since 1.89.0 has `stdarch_x86_avx512` stabilized.

* Done. Added a step to install PostgreSQL before the Checks step so `npm run remote:prepare-db:check` can run.

* Updated to install `postgresql-16` and add `/usr/lib/postgresql/16/bin` to PATH so `initdb`, `pg_ctl`, and `createdb` are available.

* Added the official PostgreSQL apt repository so we can install PostgreSQL 16.

* Much cleaner. Using the `ikalnytskyi/action-setup-postgres@v7` action which handles the PostgreSQL 16 installation and PATH setup automatically.

* Done. Changes made:

1. **`crates/remote/scripts/prepare-db.sh`**: Now checks if `DATABASE_URL` is set. If so, uses the existing PostgreSQL server. Otherwise creates a temp cluster as before.

2. **`.github/workflows/test.yml`**:
   - Added `database: remote` to the PostgreSQL action to create the database
   - Added `DATABASE_URL: postgres://postgres@localhost:5432/remote` env var to the Checks step

* Done. Changes made:

1. **`.github/workflows/test.yml`**: Removed PostgreSQL setup step and `DATABASE_URL` env var
2. **`crates/remote/scripts/prepare-db.sh`**: Simplified - for `--check` mode, exits early with `SQLX_OFFLINE=true cargo sqlx prepare --check` (no database needed)
This commit is contained in:
Alex Netsch
2025-12-04 15:57:32 +00:00
committed by GitHub
parent a369cec373
commit 8a91dba6e3
11 changed files with 61 additions and 74 deletions

View File

@@ -26,7 +26,7 @@ permissions:
env:
NODE_VERSION: 22
PNPM_VERSION: 10.13.1
RUST_TOOLCHAIN: nightly-2025-05-18
RUST_TOOLCHAIN: 1.89.0
jobs:
bump-version:

View File

@@ -46,7 +46,7 @@ jobs:
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: nightly-2025-05-18
toolchain: 1.89.0
components: rustfmt, clippy
- name: Cache Rust dependencies
@@ -60,6 +60,9 @@ jobs:
shared-key: "shared"
cache-all-crates: true
- name: Install sqlx-cli
run: cargo install sqlx-cli --no-default-features --features sqlite,postgres
- name: Build frontend
run: cd frontend && npm run build
env:
@@ -69,5 +72,7 @@ jobs:
run: |
cargo fmt --all -- --check
npm run generate-types:check
npm run prepare-db:check
npm run remote:prepare-db:check
cargo test --workspace
cargo clippy --all --all-targets -- -D warnings

View File

@@ -0,0 +1,20 @@
{
"db_name": "SQLite",
"query": "SELECT EXISTS(\n SELECT 1\n FROM task_images\n WHERE task_id = $1 AND image_id = $2\n ) AS \"exists!: bool\"\n ",
"describe": {
"columns": [
{
"name": "exists!: bool",
"ordinal": 0,
"type_info": "Integer"
}
],
"parameters": {
"Right": 2
},
"nullable": [
false
]
},
"hash": "6f2bfe9a7e8e578676dedea7f62cd826e1158ef6892ab1cb9cc4f8ad0236c3da"
}

View File

@@ -1,20 +0,0 @@
{
"db_name": "SQLite",
"query": "SELECT 1 as \"exists\" FROM task_images WHERE task_id = $1 AND image_id = $2",
"describe": {
"columns": [
{
"name": "exists",
"ordinal": 0,
"type_info": "Integer"
}
],
"parameters": {
"Right": 2
},
"nullable": [
false
]
},
"hash": "99f759d5f5dfdf7770de7fb31915b1885402b5f936df49016e572104a5547355"
}

View File

@@ -1,38 +0,0 @@
{
"db_name": "SQLite",
"query": "INSERT INTO task_images (id, task_id, image_id)\n VALUES ($1, $2, $3)\n RETURNING id as \"id!: Uuid\",\n task_id as \"task_id!: Uuid\",\n image_id as \"image_id!: Uuid\", \n created_at as \"created_at!: DateTime<Utc>\"",
"describe": {
"columns": [
{
"name": "id!: Uuid",
"ordinal": 0,
"type_info": "Blob"
},
{
"name": "task_id!: Uuid",
"ordinal": 1,
"type_info": "Blob"
},
{
"name": "image_id!: Uuid",
"ordinal": 2,
"type_info": "Blob"
},
{
"name": "created_at!: DateTime<Utc>",
"ordinal": 3,
"type_info": "Text"
}
],
"parameters": {
"Right": 3
},
"nullable": [
true,
false,
false,
false
]
},
"hash": "b68712f3bcf28184ed0497e4d024b914bb01b545bfa627e5f9ba14e1048f4dfd"
}

View File

@@ -59,4 +59,4 @@
]
},
"hash": "f4dfe229b47380175daba08daa93a9b832e5ba96da7f68374b05d09ec93087e1"
}
}

View File

@@ -215,12 +215,17 @@ impl TaskImage {
image_id: Uuid,
) -> Result<bool, sqlx::Error> {
let result = sqlx::query_scalar!(
r#"SELECT 1 as "exists" FROM task_images WHERE task_id = $1 AND image_id = $2"#,
r#"SELECT EXISTS(
SELECT 1
FROM task_images
WHERE task_id = $1 AND image_id = $2
) AS "exists!: bool"
"#,
task_id,
image_id
)
.fetch_optional(pool)
.fetch_one(pool)
.await?;
Ok(result.is_some())
Ok(result)
}
}

View File

@@ -1,7 +1,17 @@
#!/usr/bin/env bash
set -euo pipefail
# Create a temporary data directory
CHECK_MODE="${1:-}"
# For --check mode, run offline without database (just verify .sqlx cache)
if [ "$CHECK_MODE" = "--check" ]; then
echo "➤ Checking SQLx data (offline mode)..."
SQLX_OFFLINE=true cargo sqlx prepare --check
echo "✅ sqlx check complete"
exit 0
fi
# For prepare mode, need a running PostgreSQL instance
DATA_DIR="$(mktemp -d /tmp/sqlxpg.XXXXXX)"
PORT=54329
@@ -34,9 +44,9 @@ pg_ctl -D "$DATA_DIR" -m fast -w stop > /dev/null
echo "➤ Cleaning up..."
rm -rf "$DATA_DIR"
echo "✅ sqlx prepare complete using a temporary Postgres instance"
echo "Killing existing Postgres instance on port $PORT"
pids=$(lsof -t -i :"$PORT" 2>/dev/null || true)
[ -n "$pids" ] && kill $pids 2>/dev/null || true
sleep 1
sleep 1
echo "✅ sqlx prepare complete"

View File

@@ -25,10 +25,12 @@
"generate-types": "cargo run --bin generate_types",
"generate-types:check": "cargo run --bin generate_types -- --check",
"prepare-db": "node scripts/prepare-db.js",
"prepare-db:check": "node scripts/prepare-db.js --check",
"build:npx": "bash ./local-build.sh",
"prepack": "npm run build:npx",
"remote:dev": "cd crates/remote && docker compose --env-file .env.remote up --build ; docker compose down -v",
"remote:prepare-db": "cd crates/remote && bash scripts/prepare-db.sh"
"remote:prepare-db": "cd crates/remote && bash scripts/prepare-db.sh",
"remote:prepare-db:check": "cd crates/remote && bash scripts/prepare-db.sh --check"
},
"devDependencies": {
"concurrently": "^8.2.2",

View File

@@ -1,5 +1,5 @@
[toolchain]
channel = "nightly-2025-05-18"
channel = "1.89.0"
components = [
"rustfmt",
"rustc",

View File

@@ -4,7 +4,9 @@ const { execSync } = require('child_process');
const fs = require('fs');
const path = require('path');
console.log('Preparing database for SQLx...');
const checkMode = process.argv.includes('--check');
console.log(checkMode ? 'Checking SQLx prepared queries...' : 'Preparing database for SQLx...');
// Change to backend directory
const backendDir = path.join(__dirname, '..', 'crates/db');
@@ -29,13 +31,14 @@ try {
});
// Prepare queries
console.log('Preparing queries...');
execSync('cargo sqlx prepare', {
const sqlxCommand = checkMode ? 'cargo sqlx prepare --check' : 'cargo sqlx prepare';
console.log(checkMode ? 'Checking prepared queries...' : 'Preparing queries...');
execSync(sqlxCommand, {
stdio: 'inherit',
env: { ...process.env, DATABASE_URL: databaseUrl }
});
console.log('Database preparation complete!');
console.log(checkMode ? 'SQLx check complete!' : 'Database preparation complete!');
} finally {
// Clean up temporary file