Skip to content

feat: Enhance database integrity checks and diagnostics in deployment scripts; update SQL seed data for variant attributes#33

Merged
xukki241 merged 1 commit intomainfrom
shift
Mar 28, 2026
Merged

feat: Enhance database integrity checks and diagnostics in deployment scripts; update SQL seed data for variant attributes#33
xukki241 merged 1 commit intomainfrom
shift

Conversation

@xukki241
Copy link
Copy Markdown
Collaborator

No description provided.

… scripts; update SQL seed data for variant attributes
Copilot AI review requested due to automatic review settings March 28, 2026 19:39
@xukki241 xukki241 merged commit 67314ae into main Mar 28, 2026
6 checks passed
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:"
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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().

Copilot uses AI. Check for mistakes.
Comment on lines +311 to +315
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

Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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

Copilot uses AI. Check for mistakes.
Comment on lines +329 to +331
if [ "${stock_count:-0}" != "0" ] && [ "${STOCKED_VARIANTS_COUNT:-0}" = "0" ]; then
return 0
fi
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants