Skip to content

fix: improve error handling in database initialization and seeding#856

Merged
nevil-mathew merged 2 commits intodevelopfrom
fix-package-issue
Oct 27, 2025
Merged

fix: improve error handling in database initialization and seeding#856
nevil-mathew merged 2 commits intodevelopfrom
fix-package-issue

Conversation

@nevil-mathew
Copy link
Collaborator

@nevil-mathew nevil-mathew commented Oct 27, 2025

Summary by CodeRabbit

  • Chores
    • Improved database init and seeding scripts: initialization continues to migration even if creation reports an issue, and seeding now shows a clear message and returns a non-zero exit on failure to surface problems.

@coderabbitai
Copy link

coderabbitai bot commented Oct 27, 2025

Walkthrough

Updated two npm scripts in src/package.json: db:init now falls back to an echo message if db:create fails and still runs migrations; db:seed:all now echoes on failure and returns a non-zero exit status.

Changes

Cohort / File(s) Summary
Database npm scripts
src/package.json
db:init: changed from sequelize-cli db:create && sequelize-cli db:migrate to `sequelize-cli db:create

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Dev as Developer/CI
  participant Shell as Shell
  participant DB as Database
  rect rgb(230, 248, 255)
    Dev->>Shell: run `npm run db:init`
    Shell->>DB: sequelize-cli db:create
    alt create succeeds
      DB-->>Shell: created
      Shell->>DB: sequelize-cli db:migrate
      DB-->>Shell: migrated
    else create fails
      DB-->>Shell: error
      Shell-->>Dev: echo "Database already exists or some issue..."
      Shell->>DB: sequelize-cli db:migrate
      DB-->>Shell: migrated (or error)
    end
  end

  rect rgb(255, 243, 230)
    Dev->>Shell: run `npm run db:seed:all`
    Shell->>DB: sequelize-cli db:seed:all
    alt seed succeeds
      DB-->>Shell: seeded
      Shell-->>Dev: exit 0
    else seed fails
      DB-->>Shell: error
      Shell-->>Dev: echo "Seeded data already exists or some issue..." 
      Shell-->>Dev: exit non-zero
    end
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Check shell quoting and escaping in src/package.json to ensure scripts run in target shells/CI.
  • Verify intended behavior: migrations should run even if create failed; seed script exits non-zero on failure.
  • Test scripts on CI environment used by the project (e.g., sh vs bash differences).

Poem

🐇 I nudged the scripts with a careful tap,
If creation trips, migrations still lap.
Seeds that balk now shout, not hide,
So devs can fix with gentle pride.
Hop on—these changes keep the garden spry! 🌿

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The PR title "fix: improve error handling in database initialization and seeding" accurately reflects the core changes in the pull request. The changeset updates two npm scripts (db:init and db:seed:all) to include error handling fallbacks with informative error messages, which directly aligns with the title's description of improving error handling. The title is concise, specific, and uses clear, descriptive terms without vague language or noise, making it easy for teammates reviewing the history to understand the primary change at a glance.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-package-issue

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4d1b2c9 and 865d7ff.

📒 Files selected for processing (1)
  • src/package.json (1 hunks)
🔇 Additional comments (2)
src/package.json (2)

19-19: ✅ Critical issue resolved: db:init migration logic.

The semicolon separator now ensures sequelize-cli db:migrate runs regardless of whether db:create succeeds or fails. This fixes the operator precedence bug where migrations were previously skipped on successful creation.


20-20: ✅ Critical issue resolved: db:seed:all exit code preservation.

The subshell (echo '...' && false) now correctly preserves the non-zero exit code on seeding failure while still delivering the error message. This restores proper failure signaling to CI/CD pipelines and deployment systems.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a6cd6da and 4d1b2c9.

📒 Files selected for processing (1)
  • src/package.json (1 hunks)

@nevil-mathew nevil-mathew merged commit 04aee75 into develop Oct 27, 2025
1 of 2 checks passed
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.

1 participant