Skip to content

Seed database with initial data for patients, employees, and cases, u…#29

Merged
mattknatt merged 2 commits intomainfrom
feature/seedDatabase
Apr 2, 2026
Merged

Seed database with initial data for patients, employees, and cases, u…#29
mattknatt merged 2 commits intomainfrom
feature/seedDatabase

Conversation

@mattknatt
Copy link
Copy Markdown
Collaborator

@mattknatt mattknatt commented Apr 2, 2026

…pdate case creation template, and adjust database initialization properties

Summary by CodeRabbit

  • New Features

    • Case creation form now includes a patient selection field, allowing users to link a patient to new cases with inline validation.
  • Chores

    • Application now recreates the database schema for each run to ensure a fresh environment.
    • Added seeded sample data (patients, employees, cases) for development and test environments; test startup loads test-specific seed data.

…pdate case creation template, and adjust database initialization properties
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 2, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3b88d6a8-f52a-4db2-ba83-24756eb9e388

📥 Commits

Reviewing files that changed from the base of the PR and between d0b6950 and adb61a3.

📒 Files selected for processing (2)
  • src/test/resources/application.properties
  • src/test/resources/data-test.sql
✅ Files skipped from review due to trivial changes (1)
  • src/test/resources/data-test.sql

📝 Walkthrough

Walkthrough

Updated application initialization to recreate schema on startup and coordinate SQL script execution with JPA; added idempotent seed data for patients, employees, and cases (app + test); and extended the case creation template with a patient selection field and validation display.

Changes

Cohort / File(s) Summary
Configuration & Initialization
src/main/resources/application.properties, src/test/resources/application.properties
Changed spring.jpa.hibernate.ddl-auto to create-drop, enabled SQL script initialization (spring.sql.init.mode=always), and set spring.jpa.defer-datasource-initialization=true to adjust the initialization ordering for app and test environments.
Database Seeding (production)
src/main/resources/data.sql
Added idempotent INSERTs for three patients, three employees (roles: ADMIN, CASE_OWNER, HANDLER), and two cases, using fixed UUIDs and ON CONFLICT (id) DO NOTHING with CURRENT_TIMESTAMP for created_at.
Database Seeding (tests)
src/test/resources/data-test.sql
Added test-only seed script inserting patients, employees, and cases with fixed UUIDs and timestamps for test environment.
Case Creation UI
src/main/resources/templates/cases/new.html
Added a <select> for createCaseForm.patientId populated from patients and inline Thymeleaf field-level error display for patientId.

Sequence Diagram(s)

sequenceDiagram
  participant App as "Spring Boot App"
  participant JPA as "Hibernate / JPA"
  participant SQLInit as "Spring SQL Init"
  participant DB as "Database"

  Note over App,JPA: Application startup
  App->>JPA: Initialize JPA (ddl-auto=create-drop)
  JPA->>DB: Create schema (create-drop)
  Note over App,SQLInit: datasource init deferred to after JPA
  App->>SQLInit: Trigger SQL initialization (spring.sql.init.mode=always)
  SQLInit->>DB: Execute `data.sql` (INSERT ... ON CONFLICT DO NOTHING)
  DB-->>SQLInit: Acknowledge seed data
  DB-->>JPA: Schema and data available
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐇 In fields of SQL I plant my rows,
Three patients, helpers, cases grow.
A dropdown hops into the form,
Schema built, then scripts perform.
Hooray — the database softly glows! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main changes: database seeding for patients, employees, and cases; case template updates; and database initialization property adjustments. It is concise and specific.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/seedDatabase

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
Copy Markdown

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

🧹 Nitpick comments (1)
src/main/resources/templates/cases/new.html (1)

17-19: Make the placeholder non-selectable and require patient selection.

This prevents accidental empty submissions and aligns the UI with the intended required patient flow.

Suggested HTML tweak
-            <select class="input" th:field="*{patientId}">
-                <option value="">-- Select Patient --</option>
+            <select class="input" th:field="*{patientId}" required>
+                <option value="" disabled selected>-- Select Patient --</option>
                 <option th:each="p : ${patients}" th:value="${p.id}" th:text="${p.firstName + ' ' + p.lastName}"></option>
             </select>
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/resources/templates/cases/new.html` around lines 17 - 19, The
placeholder option in the patient select (th:field="*{patientId}" on the <select
class="input">) should be non-selectable and the control should be required;
change the placeholder option so it cannot be chosen (set it disabled and
hidden/selected as the initial value) and add the required attribute to the
<select> so a patient must be picked before submit. Ensure you keep th:each/
th:value/ th:text for the real options (the loop over ${patients}) unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/main/resources/templates/cases/new.html`:
- Around line 17-19: The placeholder option in the patient select
(th:field="*{patientId}" on the <select class="input">) should be non-selectable
and the control should be required; change the placeholder option so it cannot
be chosen (set it disabled and hidden/selected as the initial value) and add the
required attribute to the <select> so a patient must be picked before submit.
Ensure you keep th:each/ th:value/ th:text for the real options (the loop over
${patients}) unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d50bc199-2055-4ca8-8302-44f6469b0a26

📥 Commits

Reviewing files that changed from the base of the PR and between ba17d30 and d0b6950.

📒 Files selected for processing (3)
  • src/main/resources/application.properties
  • src/main/resources/data.sql
  • src/main/resources/templates/cases/new.html

@mattknatt mattknatt merged commit 5ec1c30 into main Apr 2, 2026
2 checks passed
@mattknatt mattknatt deleted the feature/seedDatabase branch April 2, 2026 08:14
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