Skip to content

Refactor database seeding scripts and improve error handling#35

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

Refactor database seeding scripts and improve error handling#35
xukki241 merged 1 commit intomainfrom
shift

Conversation

@xukki241
Copy link
Copy Markdown
Collaborator

  • Updated gen_fix_seed.js to maintain original positional insert for payroll_calculations and align disposal_vouchers and disposal_voucher_items mappings with legacy export order.
  • Modified init-db-and-seed.sh to allow fallback to legacy seed file if the primary seed file is missing, and added checks to prevent seeding with legacy mock patch markers.
  • Enhanced reset-db-and-seed.sh to enforce strict error handling during seeding, ensuring that legacy mock patch markers are not present in seed files, and improved logging for better traceability.
  • Removed legacy fallback logic and streamlined seeding strategy to focus on either fix-only or data-only approaches, ensuring critical tables are populated correctly.

- Updated `gen_fix_seed.js` to maintain original positional insert for payroll_calculations and align disposal_vouchers and disposal_voucher_items mappings with legacy export order.
- Modified `init-db-and-seed.sh` to allow fallback to legacy seed file if the primary seed file is missing, and added checks to prevent seeding with legacy mock patch markers.
- Enhanced `reset-db-and-seed.sh` to enforce strict error handling during seeding, ensuring that legacy mock patch markers are not present in seed files, and improved logging for better traceability.
- Removed legacy fallback logic and streamlined seeding strategy to focus on either fix-only or data-only approaches, ensuring critical tables are populated correctly.
Copilot AI review requested due to automatic review settings March 28, 2026 20:42
@xukki241 xukki241 merged commit e1ceabd 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

Refactors the database seeding workflow to prefer deploy/fix_seed.sql, enforce stricter failure behavior during seeding, and add stronger “seed integrity” checks across local scripts and CD deployment.

Changes:

  • Switch seeding defaults to deploy/fix_seed.sql with legacy data.sql fallback in init/local scripts.
  • Make reset+seed fail fast on SQL errors and validate additional “critical” tables (orders/tickets/loyalty gifts).
  • Update gen_fix_seed.js column mappings (notably disposal vouchers/items) and strip BOM from data.sql input.

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
deploy/scripts/reset-db-and-seed.sh Strict seeding + expanded post-seed validation; simplified strategies/fallbacks.
deploy/scripts/init-db-and-seed.sh Prefer fix_seed.sql, fallback to legacy seed, and block legacy mock marker.
deploy/gen_fix_seed.js Adjust column mappings and remove BOM before generating fix_seed.sql.
deploy/fix_seed.sql Updated seed dataset and insert column alignment to match expected schema/order.
backend/run-seed.cmd Prefer fix_seed.sql, block legacy mock marker, and add post-seed verification queries.
README.md Document new default seed flow and regeneration instructions.
.github/workflows/cd.yml Expand post-deploy seed integrity checks and run reset+seed in fix-only mode.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

;;
*)
log "ERROR" "Invalid SEED_STRATEGY=$SEED_STRATEGY (allowed: fix-only|fix-first|data-only|data-first)"
log "ERROR" "Invalid SEED_STRATEGY=$SEED_STRATEGY (allowed: fix-only|data-only)"
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.

SEED_STRATEGY validation message is out of sync with what the case statement actually accepts. Here the script supports data-first (and earlier fix-first), but the error message advertises only fix-only|data-only. Please either (a) remove the unsupported strategy patterns from the case statement and the earlier require_file switch, or (b) update the error message (and any docs) to list all supported values consistently.

Suggested change
log "ERROR" "Invalid SEED_STRATEGY=$SEED_STRATEGY (allowed: fix-only|data-only)"
log "ERROR" "Invalid SEED_STRATEGY=$SEED_STRATEGY (allowed: fix-only|fix-first|data-only|data-first)"

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