Skip to content

Commit e6312f8

Browse files
authored
Merge pull request #31 from CurtisTechSolutions/feat/postgres-match-store
feat: add atomic PostgreSQL match storage
2 parents 948804c + df31112 commit e6312f8

24 files changed

Lines changed: 1795 additions & 703 deletions
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"""Verify checked-in SQLx PostgreSQL metadata against the migrated CI database."""
2+
import json
3+
import os
4+
from pathlib import Path
5+
6+
7+
def metadata(directory):
8+
values = {}
9+
for path in directory.glob("query-*.json"):
10+
value = json.loads(path.read_text())
11+
if value["db_name"] == "PostgreSQL":
12+
values[path.name] = value
13+
return values
14+
15+
16+
generated = metadata(Path(os.environ["SQLX_OFFLINE_DIR"]))
17+
if not generated or generated != metadata(Path(".sqlx")):
18+
raise SystemExit("PostgreSQL SQLx metadata is missing or stale.")

‎.github/scripts/sqlite-query-check.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@
1919
connection.executescript(migration.read_text())
2020
elif sys.argv[1] == "verify":
2121
def metadata(directory):
22-
return {path.name: json.loads(path.read_text()) for path in directory.glob("query-*.json")}
22+
return {
23+
path.name: json.loads(path.read_text())
24+
for path in directory.glob("query-*.json")
25+
if json.loads(path.read_text())["db_name"] == "SQLite"
26+
}
2327

2428
generated = metadata(queries)
2529
if not generated or generated != metadata(Path(".sqlx")):

‎.github/workflows/ci.yml‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,17 @@ jobs:
1919
run: python3 .github/scripts/sqlite-query-check.py prepare
2020
env:
2121
GFA_SQLX_WORK_DIR: ${{ runner.temp }}/gfa-sqlx
22-
- run: cargo test --workspace --all-features --locked
22+
- run: cargo check -p gfa-store --no-default-features --features sqlite --locked
2323
env:
2424
DATABASE_URL: sqlite:${{ runner.temp }}/gfa-sqlx/schema.sqlite
2525
SQLX_OFFLINE_DIR: ${{ runner.temp }}/gfa-sqlx/queries
2626
- name: Verify offline query metadata
2727
run: python3 .github/scripts/sqlite-query-check.py verify
2828
env:
2929
GFA_SQLX_WORK_DIR: ${{ runner.temp }}/gfa-sqlx
30+
- run: cargo test --workspace --all-features --locked
31+
env:
32+
SQLX_OFFLINE: "true"
3033
- run: cargo build -p gfa-cli --locked
3134
- run: python3 .github/scripts/local-server-smoke.py
3235
- name: Export generated OpenAPI

‎.github/workflows/postgres.yml‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: PostgreSQL CI
2+
on:
3+
pull_request:
4+
push:
5+
branches: [main]
6+
permissions:
7+
contents: read
8+
concurrency:
9+
group: postgres-ci-${{ github.ref }}
10+
cancel-in-progress: true
11+
jobs:
12+
postgres:
13+
runs-on: ubuntu-latest
14+
services:
15+
postgres:
16+
image: postgres:16-alpine
17+
env:
18+
POSTGRES_USER: gfa_test
19+
POSTGRES_PASSWORD: gfa-test
20+
POSTGRES_DB: gfa_test
21+
ports:
22+
- 5432:5432
23+
options: >-
24+
--health-cmd "pg_isready -U gfa_test -d gfa_test"
25+
--health-interval 5s --health-timeout 5s --health-retries 10
26+
env:
27+
DATABASE_URL: postgres://gfa_test:gfa-test@localhost:5432/gfa_query
28+
GFA_TEST_POSTGRES_URL: postgres://gfa_test:gfa-test@localhost:5432/gfa_test
29+
SQLX_OFFLINE_DIR: ${{ github.workspace }}/target/pg-queries
30+
steps:
31+
- uses: actions/checkout@v4
32+
- uses: dtolnay/rust-toolchain@stable
33+
- uses: Swatinem/rust-cache@v2
34+
- name: Prepare migration-derived query schema
35+
run: |
36+
psql "$GFA_TEST_POSTGRES_URL" -v ON_ERROR_STOP=1 -c 'CREATE DATABASE gfa_query'
37+
for migration in crates/adapters/gfa-store/migrations/postgres/*.sql; do
38+
psql "$DATABASE_URL" -v ON_ERROR_STOP=1 -f "$migration"
39+
done
40+
mkdir -p "$SQLX_OFFLINE_DIR"
41+
- name: Check queries and exercise PostgreSQL
42+
run: cargo test -p gfa-store --no-default-features --features postgres --locked -- --ignored
43+
- name: Verify PostgreSQL query metadata
44+
run: python3 .github/scripts/postgres-query-check.py

‎.sqlx/query-1e21b2c1fd62078ae5d29e3397c71bda8f71ab7b93bcc5644cb9a7abb4b87f26.json‎

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.sqlx/query-1e4184d66b974d25764dd449b4914599aff345ec804025b31bee147bc9f26ff7.json‎

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.sqlx/query-247574d35e4219d9d848bcfedcfe158e54ca813792fd2971c3969e296e07230b.json‎

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.sqlx/query-4de08d4df474832dd8431c211ff5d553ec30732f3343b68d373e20bd6e3b8382.json‎

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.sqlx/query-53ee1aeedfd92fff3dae8a533114711a9862c75565287cb45830a82e602efd44.json‎

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.sqlx/query-566148e25e12c16c178ebd392595e35ccde1b37d1fc9d03f21ad4036bb8a6531.json‎

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)