Skip to content

Commit 37ed012

Browse files
committed
feat(sqlx): update mise task and migration documentation
- Rename test:rust to test:sqlx for clarity - Implement hybrid migration approach in mise task - Document hybrid migration strategy in migrations README - Auto-copy built EQL to migrations on test run
1 parent 80f5996 commit 37ed012

File tree

2 files changed

+54
-12
lines changed

2 files changed

+54
-12
lines changed

tasks/rust.toml

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,31 @@
1-
["test:rust"]
2-
description = "Run Rust test framework"
3-
dir = "{{config_root}}/tests/sqlx"
1+
["test:sqlx"]
2+
description = "Run SQLx tests with hybrid migration approach"
3+
dir = "{{config_root}}"
4+
env = { DATABASE_URL = "postgresql://{{get_env(name='POSTGRES_USER', default='cipherstash')}}:{{get_env(name='POSTGRES_PASSWORD', default='password')}}@{{get_env(name='POSTGRES_HOST', default='localhost')}}:{{get_env(name='POSTGRES_PORT', default='7432')}}/{{get_env(name='POSTGRES_DB', default='cipherstash')}}" }
45
run = """
5-
# Ensure database is running
6+
# Build EQL SQL from source
7+
echo "Building EQL SQL..."
8+
mise run build --force
9+
10+
# Copy built SQL to SQLx migrations (EQL install is generated, not static)
11+
echo "Updating SQLx migrations with built EQL..."
12+
cp release/cipherstash-encrypt.sql tests/sqlx/migrations/001_install_eql.sql
13+
14+
# Ensure PostgreSQL is running
15+
echo "Starting PostgreSQL..."
616
mise run postgres:up --extra-args "--detach --wait"
717
8-
# Run tests
18+
# Run SQLx migrations and tests
19+
echo "Running SQLx migrations..."
20+
cd tests/sqlx
21+
sqlx migrate run
22+
23+
echo "Running Rust tests..."
924
cargo test
1025
"""
1126

12-
["test:rust:watch"]
13-
description = "Run Rust tests in watch mode"
27+
["test:sqlx:watch"]
28+
description = "Run SQLx tests in watch mode (rebuild EQL on changes)"
1429
dir = "{{config_root}}/tests/sqlx"
1530
run = """
1631
cargo watch -x test

tests/sqlx/migrations/README.md

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,42 @@
11
# SQLx Migrations
22

3-
These migrations install EQL and test helpers into the test database.
3+
These migrations install EQL and test helpers into the test database using a **hybrid approach**.
44

5-
**Important**: SQLx tracks migration state. When using `#[sqlx::test]`:
5+
## Hybrid Migration Approach
6+
7+
**Migration 001 is generated**, not static:
8+
- Built from `src/` using `mise run build`
9+
- Automatically copied to `migrations/001_install_eql.sql` by `mise run test:sqlx`
10+
- In `.gitignore` - never commit this file
11+
- Ensures tests always use current EQL version
12+
13+
**Migrations 002-004 are static fixtures**:
14+
- 002: Test helpers (`test_helpers.sql`)
15+
- 003: ORE test data (`ore.sql`)
16+
- 004: STE Vec test data (`ste_vec.sql`)
17+
18+
## How SQLx Uses These Migrations
19+
20+
When using `#[sqlx::test]`:
621
- Each test gets a fresh database
7-
- Migrations run automatically before each test
22+
- All migrations (001-004) run automatically before each test
23+
- Migration 001 contains the latest built EQL
824
- No need to manually reset database between tests
925

10-
To regenerate migrations:
26+
## When to Manually Regenerate
27+
28+
**You usually don't need to regenerate** - the `test:sqlx` task handles it automatically.
29+
30+
Only regenerate manually if debugging migration issues:
1131
```bash
1232
mise run build
1333
cp release/cipherstash-encrypt.sql tests/sqlx/migrations/001_install_eql.sql
14-
cp tests/test_helpers.sql tests/sqlx/migrations/002_install_test_helpers.sql
1534
```
35+
36+
## Adding New Test Fixtures
37+
38+
To add new test data or helpers:
39+
1. Create a new migration: `tests/sqlx/migrations/005_my_fixture.sql`
40+
2. Add your SQL fixtures
41+
3. Commit it (static migrations are version-controlled)
42+
4. SQLx will apply it automatically in test runs

0 commit comments

Comments
 (0)