feat: Enhance database integrity checks and diagnostics in deployment scripts; update SQL seed data for variant attributes#33
Conversation
… scripts; update SQL seed data for variant attributes
There was a problem hiding this comment.
Pull request overview
This PR tightens production deployment/seed diagnostics by adding database integrity checks (products/variants/units/stock joinability) to scripts and the CD workflow, and makes the variant-attributes seed inserts more schema-resilient by explicitly naming columns.
Changes:
- Add “container-safe” DB_URL normalization + quick DB integrity diagnostics to the prod stack runner.
- Add scalar integrity queries + stricter post-seed validation (orphan refs, joinability, stock sanity) to the DB reset/seed script (and change default strategy to
data-only). - Update CD workflow to refuse deploying a missing image tag and to trigger reseeding when integrity metrics indicate broken product data.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
deploy/scripts/run-prod-stack.sh |
Normalizes DB_URL for compose network and prints quick integrity diagnostics after bringing up the stack. |
deploy/scripts/reset-db-and-seed.sh |
Adds scalar-query helpers + integrity verification and tightens failure conditions after seeding; changes default seed strategy. |
deploy/fix_seed.sql |
Updates variant_attributes insert to include an explicit column list. |
backend/src/main/resources/data.sql |
Same variant_attributes insert column-list update for the primary seed file. |
.github/workflows/cd.yml |
Removes fallback tag deployment and adds integrity-driven post-deploy checks to decide when to run destructive reseeding. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| SPRING_JPA_DDL_AUTO="$SPRING_JPA_DDL_AUTO" \ | ||
| docker compose -f "$COMPOSE_FILE" ps | ||
|
|
||
| echo "\nQuick DB integrity diagnostics:" |
There was a problem hiding this comment.
echo "\n..." is not portable (many shells don't interpret \n without -e), so this will likely print a literal \n. Prefer printf for the leading newline and message to keep output consistent with print_step().
| if [ "$STOCK_COUNT" != "0" ] && [ "$STOCKED_VARIANTS_COUNT" = "0" ]; then | ||
| log "ERROR" "Seed finished but inventory_stock has no positive quantities mapped to variants." | ||
| exit 1 | ||
| fi | ||
|
|
There was a problem hiding this comment.
The new check STOCK_COUNT != 0 && STOCKED_VARIANTS_COUNT == 0 treats “all quantities are 0” as an integrity failure. That’s a valid real-world state (e.g., everything sold out or just initialized), so this can cause the script to error even when FK relationships are correct. Consider replacing this with an actual referential-integrity check (e.g., inventory_stock rows whose variant_id/batch_id/location_id don’t join), or drop the positive-quantity requirement.
| if [ "$STOCK_COUNT" != "0" ] && [ "$STOCKED_VARIANTS_COUNT" = "0" ]; then | |
| log "ERROR" "Seed finished but inventory_stock has no positive quantities mapped to variants." | |
| exit 1 | |
| fi |
| if [ "${stock_count:-0}" != "0" ] && [ "${STOCKED_VARIANTS_COUNT:-0}" = "0" ]; then | ||
| return 0 | ||
| fi |
There was a problem hiding this comment.
is_integrity_bad() currently flags the deployment as bad when inventory_stock has rows but all quantity values are <= 0. That can be a normal business state (sold out), but in this workflow it triggers reset-db-and-seed.sh which drops and recreates the database—risking destructive data loss on a healthy production DB. Recommend removing the positive-quantity heuristic from the deploy gating logic, or replace it with a true integrity check (e.g., inventory_stock rows that don’t join to product_variants/product_batches/locations).
No description provided.